LoginSignup
9
6

More than 3 years have passed since last update.

kintone-rest-api-client を使ってみた。レコード編その①

Posted at

新しくkintone-rest-api-clientが公開されたみたいなので、
まずはシンプルなレコード操作を試して使い方などをまとめてみました。

インストール

npm install @kintone/rest-api-client

セットアップ

const { KintoneRestAPIClient } = require('@kintone/rest-api-client');

const client = new KintoneRestAPIClient({
  host: 'https://example.cybozu.com',

  // パスワード認証の場合
  auth: { username: 'username', password: 'password' }

  // APIトークン認証の場合
  // auth: { apiToken: "API_TOKEN" }

  // セッション認証の場合
  // auth: {}
});

レコードの取得(1 件)

client.record
  .getRecord({
    app: '100',
    id: '1'
  })
  .then(resp => {
    console.log(resp.record);
  })
  .catch(err => {
    console.log(err);
  });

パラメータ 必須
app 数値または文字列 必須
id 数値または文字列 必須

レコードの登録(1 件)

client.record
  .addRecord({
    app: '100',
    record: {
      文字列1行: {
        value: 'test'
      }
    }
  })
  .then(resp => {
    console.log(resp);
  })
  .catch(err => {
    console.log(err);
  });
パラメータ 必須
app 数値または文字列 必須
record レコードオブジェクト 省略可

レコードの更新(1 件)

client.record
  .updateRecord({
    app: '100',
    id: '1',
    record: {
      文字列1行: {
        value: 'test'
      }
    }
  })
  .then(resp => {
    console.log(resp);
  })
  .catch(err => {
    console.log(err);
  });

パラメータ 必須
app 数値または文字列 必須
id 数値または文字列 必須
record レコードオブジェクト 省略可
revision 数値または文字列 省略可

または

client.record
  .updateRecord({
    app: '100',
    updateKey: {
      field: '文字列1行',
      value: 'test'
    },
    record: {
      数値: {
        value: '100'
      }
    }
  })
  .then(resp => {
    console.log(resp);
  })
  .catch(err => {
    console.log(err);
  });
パラメータ 必須
app 数値または文字列 必須
updateKey 重複禁止フィールドコードと値のオブジェクト 必須
record レコードオブジェクト 省略可
revision 数値または文字列 省略可

レコードの削除(複数)

client.record
  .deleteRecords({
    app: '100',
    ids: [1, 2]
  })
  .then(resp => {
    console.log(resp);
  })
  .catch(err => {
    console.log(err);
  });

パラメータ 必須
app 数値または文字列 必須
ids レコード ID の数値配列 必須
revisions revision 番号の数値配列 省略可

つづく

9
6
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
9
6