Implementing Things with JavaScript SDK

You can use the JavaScript SDK to let a thing manipulates itself (i.e., leverage the thing features with the thing's access token).

In this page, we will present how you can implement things with the JavaScript SDK. We assume that you are using the JavaScript SDK with Node.js. Please read the page with the assumption that the SDK package installation and SDK module initialization are already made by following the instructions covered in Running the SDK on Node.js.

First, get the ThingContext as shown in the following sample code. In this sample code, we assume that the target thing is already registered with the vendorThing ID "rBnvSPOXBDF9r29GJeGS" and the password "123ABC".

var vendorThingID = "rBnvSPOXBDF9r29GJeGS";
var password = "123ABC";

// Get the thing context.
kii.Kii.authenticateAsThing(vendorThingID, password).then(
  function(thingContext) {
    // The thing has been successfully loaded.
    // You can manipulate the thing as the thing itself
    // using the thing context.
  function(error) {
    // Handle the error.

Please use the following methods provided by the ThingContext to leverage the features by the thing itself.

  • getAuthenticatedThing()

    Get the KiiThing instance of the thing. If needed, please execute the refresh method to get the latest thing information from Kii Cloud.

  • bucketWithName()

    Refer to the application scope bucket with the specified name. If the bucket with the specified name does not exist, the method will create a new bucket with the given name.

  • objectWithURI()

    Refer to the object with the specified object URL. You can refer any object in any scope as long as the thing has the correct access control over the thing.

  • topicWithName()

    Refer to the application scope topic with the specified name. If the topic with the specified name does not exist, the method will create a new topic with the given name.

  • listTopics()

    Get a list of all application scope topics.

  • pushInstallation()

    Install the thing to make it prepared for receiving push notifications.

Please read the JSDoc for the detailed explanation of these methods.

Please make sure to execute the methods via the ThingContext. If you do not execute them via the ThingContext, the features will be executed by the currently logged-in user (i.e., executed with the user's access token).

Refer to the Programming Guide of the Kii Cloud SDK to learn how to use each feature such as the data management and push notification. For the details on the thing registration and management, refer to the Function Guide and Programming Guide of the Kii Cloud SDK for Thing.