AWS Lambda(node.js)からkintone REST API(updateRecords)を実行する方法

AWS Lambda(node.js)からkintone REST API(updateRecords)を実行する方法

updateRecordsメソッドでkintoneアプリに登録されている複数レコードを更新します。

@kintone/rest-api-clientモジュールを使用して実現します。

npm init -y
npm i @kintone/rest-api-client
touch index.js

index.js

LambdaはESMで記述しています。kintoneが提供しているREST APIのレコードの更新APIを使用して顧客リストアプリの2レコードに対してアップデートを行います。

import { KintoneRestAPIClient } from '@kintone/rest-api-client'
export async function handler(event, context) {
  const client = new KintoneRestAPIClient({
    baseUrl: 'https://xxxxxxxxxx.cybozu.com',
    auth: {
      username: 'ログインID',
      password: 'パスワード'
    }
  })
  const results = await client.record.updateRecords(
    {
      app: '4',
      records:[
        {
          id:23,
          record:{'person':{'value':'坂本'},'address':{'value':'大阪府大阪市'}}
        },
        {
          id:24,
          record:{'person':{'value':'山田'},'address':{'value':'大阪府大阪市'}}
        }
      ]
    }
  )
  console.log(results)
  return {
    statusCode: 200,
    body: `Hello`
  }
}

zip圧縮

簡単に試すために7zでzip圧縮し、Lambdaデプロイします。

AWS Lambda(node.js)からkintone REST API(updateRecords)を実行する方法

「Test」を押します。

AWS Lambda(node.js)からkintone REST API(updateRecords)を実行する方法

顧客アプリのレコードが2件更新されていることが確認できます。

参考サイト

https://github.com/kintone/js-sdk/blob/master/packages/rest-api-client/docs/record.md#updateRecords
Update Records
Updates details of multiple records in an App, by specifying their record numbers, or their unique keys.

コメント

株式会社CONFRAGE ITソリューション事業部をもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む

タイトルとURLをコピーしました