npm version CircleCI Coverage Status

Javascript SDK for Kii Thing Interaction Framework.


Build SDK

Install NPM packages

$ npm install

Build SDK

thing-if SDK is built as UMD(Universal Module Definition) library. So your code can load it either with CommonJS style, AMD style or script tag.

Normal build

Built with gulp command

$ npm run build-src

If succeeded, library file named thing-if.js is available under ./dist/ folder.

Use thing-if in browser app

Note: thing-if SDK uses global Promise, so if the browser doesn't support Promise( like Mircrosoft IE11), it needs to polyfill promise to the browser app.

Basic operations of thing-if SDK are tested and passed on the following browsers: Mozilla Firefox 49.0.1, Safari 9.1.3, Chrome 53.0, and Microsoft Edge 38.

  1. Clone this repository
$ git clone
  1. Bundle library using browserify.

browserify bundles all the dependencies into a single file.

$ cd thing-if-JSSDK
$ npm install
$ npm install browserify -g
$ browserify . -s ThingIF > thing-if.js
  1. Include the bundle file in your browser app
<!-- if the browser does not support promise, need to download polyfill promise library(i.e. and import like the following script -->
<script src="path/to/promise.js"></script>

<script src="path/to/thing-if.js"></script>


Configure TestApp

You need to configure TestApp as env variable for testing, the format is [app-id]:[app-key]:[JP|CN3|US|EU|SG]:[client-id]:[client-secret]

$ export TestApp=[app-id]:[app-key]:[JP|CN3|US|EU|SG]:[client-id]:[client-secret]

Run npm test

$ npm test

Use cases in nodejs

Integrate with kii-cloud-sdk

You usally need to get user id and token from kii-cloud-sdk, you can simply integrate it with thing-if SDK.

mkdir MyApp
cd MyApp
npm install kii-cloud-sdk

Copy thing-if.js in MyApp direcotry and create file named Onboarding.js in MyApp directory.

"use strict"
var kiicloud = require("kii-cloud-sdk").create();

var thingIF = require('./thing-if.js');

var appid = "****",
    appkey = "****",
    site = kiicloud.KiiSite.JP;

kiicloud.Kii.initializeWithSite(appid, appkey, site);

// an already registered kii user
var username = "user-name";
var pass = "pass";

kiicloud.KiiUser.authenticate(username, pass).then(function (authedUser) {
    var token = authedUser.getAccessToken();
    var ownerId = authedUser.getID();

    var apiAuthor = new thingIF.APIAuthor(
        new thingIF.App(

    var onboardRequest = new thingIF.OnboardWithVendorThingIDRequest(
        new thingIF.TypedID(thingIF.Types.User, ownerId));

return apiAuthor.onboardWithVendorThingID(onboardRequest);
}).then(function (res) {
}).catch(function (err) {

Execute with node.

node Onboarding.js

onboard and send command to a thing

Create file named Command.js in YourApp directory.

var thingIF = require('./thing-if.js');

// <Replace those values>
var appID = "appID";
var appKey = "appKey";
var appSite = thingIF.Site.JP;

var ownerToken = "owner-token";
var ownerID = "owner-id";
var vendorThingID = "th.myTest";
var thingPassword = "password";
// <Replace those values/>

var app = new thingIF.App(appID, appKey, appSite);
var apiAuthor = new thingIF.APIAuthor(ownerToken ,app);
var onboardRequest = new thingIF.OnboardWithVendorThingIDRequest(
    new thingIF.TypedID(thingIF.Types.User, ownerID));

// using promise
    var thingID = res.thingID;
    var actions = [
        new thingIF.AliasAction('alias', [
            new thingIF.Action('power', true)
    var commandOptions = new thingIF.PostCommandRequest(
        new thingIF.TypedID(thingIF.Types.User, ownerId)
    return apiAuthor.postNewCommand(new thingIF.TypedID(thingIF.Types.Thing, thingID), commandOptions);
    console.log("command created:"+command.commandID);

Execute with node.

node Command.js

Use in Typescript Project

  • install thing-if SDK with npm
npm install thing-if --save
  • add reference to your code
/// <reference path="./typings/modules/thing-if/index.d.ts" />
import * as ThingIFSDK from 'thing-if'


thing-if-JSSDK is released under the Apache 2.0 license. See LICENSE for details.