Constructor
new APIAuthor(token, app)
Parameters:
Name | Type | Description |
---|---|---|
token |
string
|
A token can access Thing-IF APIs, which can be admin token or token of a registered kii user. |
app |
App
|
App instance of existing Kii App. You must create a app in Kii developer portal |
Members
app
App instance about Kii App.
token
Access token of APIAuthor.
Methods
aggregate(target, request, onCompletionopt) → {Promise}
Aggregate history states of specified target.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
request |
AggregateGroupedHistoryStatesRequest
|
request object. | |
onCompletion |
function
|
<optional> |
Callback function when completed. |
Returns:
- Type:
-
Promise
promise object.
deleteTrigger(target, triggerID, functionopt) → {Promise}
Delete a specified trigger.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
triggerID |
string
|
ID of trigger. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
author.deleteTrigger(targetID, "Trigger ID").then(function(deletedTriggerID) {
// Do something
}).catch(function(err){
// Error handling
});
enableTrigger(target, triggerID, enable, functionopt) → {Promise}
Enable/Disable a specified trigger.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
triggerID |
string
|
ID of trigger. | |
enable |
boolean
|
True to enable, otherwise, disable the trigger. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
author.enableTrigger(targetID, "Trigger ID", true).then(function(trigger) {
// Do something
}).catch(function(err){
// Error handling
});
getCommand(target, commandID, functionopt) → {Promise}
Retrieve command with specified ID.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
commandID |
string
|
Command ID to retrieve. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
author.getCommand(targetID, "CommandID").then(function(command) {
// Do something
}).catch(function(err){
// Error handling
});
getFirmwareVersion(thingID, onCompletionopt) → {Promise}
Get firmware version of specified target thing. If firmware versoin is not set, then null is resolved.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
thingID |
string
|
ID of thing. | |
onCompletion |
function
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object.
getState(target, aliasopt, functionopt) → {Promise}
Get State of specified target.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
alias |
string
|
<optional> |
Trait alias of state to query. If provided, only states of the specified alias returned. |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
author.getState(targetID).then(function(state) {
// Do something
}).catch(function(err){
// Error handling
});
getThingType(thingID, onCompletionopt) → {Promise}
Get thingType to use trait for specified target thing.
If thing type is not set, then null is resolved.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
thingID |
string
|
ID of thing. | |
onCompletion |
function
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object.
getTrigger(target, triggerID, functionopt) → {Promise}
Retrieve trigger.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
triggerID |
string
|
ID of trigger. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
author.getTrigger(targetID, "TriggerID").then(function(trigger) {
// Do something
}).catch(function(err){
// Error handling
});
getVendorThingID(thingID, functionopt) → {Promise}
Get vendorThingID of specified target
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
thingID |
string
|
ID of thing. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
author.getVendorThingID("Thing ID for target").then(function(vendorThingID) {
// Do something
}).catch(function(err){
// Error handling
});
groupedQuery(target, request, onCompletionopt) → {Promise}
Query grouped history states of specified target based on data grouping intervals.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
request |
QueryGroupedHistoryStatesRequest
|
request object. | |
onCompletion |
fuction
|
<optional> |
Callback function when completed. |
Returns:
- Type:
-
Promise
promise object.
installFCM(installationRegistrationID, development, functionopt) → {Promise}
Install Firebase Cloud Message(FCM) notification to receive notification from IoT Cloud.
IoT Cloud will send notification when the Target replies to the Command. Application can
receive the notification and check the result of Command fired by Application or registered Trigger.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
installationRegistrationID |
string
|
The ID of registration that identifies the installation externally. | |
development |
boolean
|
Indicates if the installation is for development or production environment. | |
function |
onCompletion
|
<optional> |
Callback function when completed. |
Returns:
- Type:
-
Promise
promise object.
Example
author.installFCM("Registration ID", false).then(function(installationID) {
// Do something
}).catch(function(err){
// Error handling
});
listCommands(target, listOptions, functionopt) → {Promise}
Retrieve commands.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
listOptions |
Object
|
Options to retrieve commands. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
author.listCommands(targetID).then(function(queryResult) {
if (queryResult.hasNext) {
// Handle more results
}
// Do something
var commands = queryResult.results;
}).catch(function(err){
// Error handling
});
listServerCodeExecutionResults(target, triggerID, listOptions, functionopt) → {Promise}
Retrieve execution results of server code trigger.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
triggerID |
string
|
ID of trigger. | |
listOptions |
Object
|
Options to retrieve. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
author.listServerCodeExecutionResults(targetID, "Trigger ID").then(function(queryResult) {
if (queryResult.hasNext) {
// Handle more results
}
// Do something
var executionResults = queryResult.results;
}).catch(function(err){
// Error handling
});
listTriggers(target, functionopt) → {Promise}
Retrive triggers.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
author.listTriggers(targetID).then(function(queryResult) {
if (queryResult.hasNext) {
// Handle more results
}
// Do something
var triggers = queryResult.results;
}).catch(function(err){
// Error handling
});
onboardWithThingID(onboardRequest, functionopt) → {Promise}
Onboard Thing by thingID for the things already registered on Kii Cloud.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
onboardRequest |
Object
|
Necessary fields when request onboarding | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
onboardWithVendorThingID(onboardRequest, functionopt) → {Promise}
Onboard Thing by vendorThingID
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
onboardRequest |
Object
|
request body when request onboarding | |
function |
onCompletion
|
<optional> |
callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
// Assume user is already exist and you have User ID and Access token.
var app = new ThingIF.App("Your AppID", "Your AppKey", ThingIF.Site.US);
var author = new ThingIF.APIAuthor("Your user's acess token", app);
var vendorThingID = "Your thing's vendor thing ID";
var password = "Your thing's password";
var owner = new ThingIF.TypedID(ThingIF.Types.User, "Your UserID");
var request = new ThingIF.OnboardWithVendorThingIDRequest(vendorThingID, password, owner);
author.onboardWithVendorThingID(request).then(function(result){
// Do something
}).catch(function(err){
// Error handling
});
patchCommandTrigger(target, triggerID, requestObject, functionopt) → {Promise}
Update a command trigger.
When condition described by predicate is met, a registered command sends to thing related to target.
`target` property and commandTarget in requestObject must belong to same owner.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
triggerID |
string
|
ID of trigger. | |
requestObject |
Object
|
The fields of trigger to be updated. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
// if commandTargetID can be different with targetID
var commandTargetID = new ThingIF.TypedID(ThingIF.Types.Thing, "another thing to receive command");
var issuerID = new ThingIF.TypedID(ThingIF.Types.User, "Your UserID");
var condition = new ThingIF.Condition(new ThingIF.Equals("power", "false"));
var statePredicate = new ThingIF.StatePredicate(condition, ThingIF.TriggersWhen.CONDITION_CHANGED);
var triggerCommandObject = new ThingIF.TriggerCommandObject("led2", 2, [{setBrightness: {brightness:50}}], commandTargetID, issuerID);
var request = new ThingIF.PatchCommandTriggerRequest(triggerCommandObject, statePredicate);
author.patchCommandTrigger(targetID, "Trigger ID", request).then(function(trigger) {
// Do something
}).catch(function(err){
// Error handling
});
patchServerCodeTrigger(target, triggerID, requestObject, functionopt) → {Promise}
Update a servercode trigger.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
triggerID |
string
|
ID of trigger. | |
requestObject |
PatchServerCodeTriggerRequest
|
The fields of trigger to be updated. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
var serverCode = new ThingIF.ServerCode("function_name", null, null, {param1: "hoge"});
var condition = new ThingIF.Condition(new ThingIF.Equals("power", "false"));
var statePredicate = new ThingIF.StatePredicate(condition, ThingIF.TriggersWhen.CONDITION_CHANGED);
var request = new ThingIF.PatchServerCodeTriggerRequest(serverCode, statePredicate);
author.patchServerCodeTrigger(targetID, "Trigger ID", request).then(function(trigger) {
// Do something
}).catch(function(err){
// Error handling
});
postCommandTrigger(target, requestObject, functionopt) → {Promise}
Post a new command trigger.
When condition described by predicate is met, a registered command sends to thing related to target.
`target` property and commandTarget in requestObject must belong to same owner.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
requestObject |
Object
|
Necessary fields for new command trigger. IssuerID is required in requestObject. If requestObject.command.targetID is not provide or null, `target` parameter will be used. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
// commandTargetID can be different with targetID.
var commandTargetID = new ThingIF.TypedID(ThingIF.Types.Thing, "another thing to receive command");
var issuerID = new ThingIF.TypedID(ThingIF.Types.User, "Your UserID");
var condition = new ThingIF.Condition(new ThingIF.Equals("power", "false"));
var statePredicate = new ThingIF.StatePredicate(condition, ThingIF.TriggersWhen.CONDITION_CHANGED);
var triggerCommandObject = new ThingIF.TriggerCommandObject("Schema name", 1, [{turnPower: {power:true}}], commandTargetID, issuerID);
var request = new ThingIF.PostCommandTriggerRequest(triggerCommandObject, statePredicate);
author.postCommandTrigger(targetID, request).then(function(trigger) {
// Do something
}).catch(function(err){
// Error handling
});
postNewCommand(target, command, functionopt) → {Promise}
Post a new command.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
command |
Object
|
Necessary fields for new command | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
var issuerID = new ThingIF.TypedID(ThingIF.Types.User, "Your UserID");
var request = new ThingIF.PostCommandRequest("led", 1, [{turnPower: {power:true}}], issuerID);
author.postNewCommand(targetID, request).then(function(command) {
// Do something
}).catch(function(err){
// Error handling
});
postServerCodeTrigger(target, requestObject, functionopt) → {Promise}
Post a new servercode trigger.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
requestObject |
PostServerCodeTriggerRequest
|
Necessary fields for new servercode trigger. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
var targetID = new ThingIF.TypedID(ThingIF.Types.Thing, "Thing ID for target");
var serverCode = new ThingIF.ServerCode("function_name", null, null, {param1: "hoge"});
var condition = new ThingIF.Condition(new ThingIF.Equals("power", "false"));
var statePredicate = new ThingIF.StatePredicate(condition, ThingIF.TriggersWhen.CONDITION_CHANGED);
var request = new ThingIF.ServerCodeTriggerRequest(serverCode, statePredicate);
author.postServerCodeTrigger(targetID, request).then(function(trigger) {
// Do something
}).catch(function(err){
// Error handling
});
query(target, request, onCompletionopt) → {Promise}
Query history states of specified target.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
TypedID
|
TypedID of target, only Types.THING is supported now. | |
request |
QueryHistoryStatesRequest
|
parameters to do query. | |
onCompletion |
function
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object.
uninstallPush(installationID, functionopt) → {Promise}
Unregister the push settings by the id(issued by KiiCloud) that is used for installation.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
installationID |
string
|
The ID of the installation issued by KiiCloud. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object.
Example
author.uninstallPush("Installation ID").then(function() {
// Do something
}).catch(function(err){
// Error handling
});
updateFirmwareVersion(thingID, firmwareVersion, functionopt) → {Promise}
Update firmware version of specified target thing.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
thingID |
string
|
ID of thing. | |
firmwareVersion |
string
|
New firmware version. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object.
updateThingType(thingID, thingType, onCompletionopt) → {Promise}
Update thingType to use trait for a specified target thing.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
thingID |
string
|
ID of thing. | |
thingType |
string
|
Name of ThingType, which should be already defined. | |
onCompletion |
function
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object.
updateVendorThingID(thingID, newVendorThingID, newPassword, functionopt) → {Promise}
Update vendorThingID of specified target
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
thingID |
string
|
ID of thing. | |
newVendorThingID |
string
|
New vendorThingID of target to be updated. | |
newPassword |
string
|
New password of target to be updated. | |
function |
onCompletion
|
<optional> |
Callback function when completed |
Returns:
- Type:
-
Promise
promise object
Example
author.updateVendorThingID("Thing ID for target", "New vendor thing ID", "New Password").then(function() {
// Do something
}).catch(function(err){
// Error handling
});