3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Node.jsからSesame API v3 を使う

3
Last updated at Posted at 2019-02-11

実行環境

MacBookAir Mid2012 Sierra。

$ node -v
v10.15.0

requestのインストール


$npm install request

tokenの取得

https://docs.candyhouse.co/#obtain-your-api-key の手順をにしたがってtokenを取得。

  1. https://my.candyhouse.co/ からCandy House Dash Boardにログイン。
  2. サイドバーの"API Settings"を選択。アクセスにはVerification codeが必要なので、"SEND CODE"を押して、登録されたemailで受け取ります。受け取ったVerification codeを入力して、"CONFIRM"をクリックします。
  3. Verifiation Codeを入力するとAPI settingにアクセスできます。"ADD"をクリックして、新しいAPI Keyを取得します。
  4. このAPI Keyをコピーしておきます。このAPI Keyはrefreshやlogoutすると全体がみえたくなります。そのためどこかにコピーしておくのを忘れないでください。
    20190211_ScreenShot_CandyHouse.png

device idの取得

以下のコードで一番目にあるdevice idを取得します。
[[your_token]]には上で取得したtokenを入力してください。

testSesame.js
var request = require('request');

const token_sesame = '[[your_token]]';

var options_device = {
  uri: 'https://api.candyhouse.co/public/sesames',
  method: 'GET',
  headers: {
    'Authorization': token_sesame,
  },
  json: true
};

let device_id = "";

request.get(options_device, function(error, response, body){
  if ( response ){
    if (response.statusCode == 200) {
      device_id = body[0].device_id;
      console.log(device_id);
    }
  }
});

実行結果です。

$ node testSesame.js
cxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?