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デプロイします。
「Test」を押します。
顧客アプリのレコードが2件更新されていることが確認できます。
参考サイト
js-sdk/packages/rest-api-client/docs/record.md at main ?? kintone/js-sdk
A monorepo for Kintone development tools :wrench:. Contribute to kintone/js-sdk development by creating an account on Gi...

Update Records
Updates details of multiple records in an App, by specifying their record numbers, or their unique keys.

KHI入社して退社。今はCONFRAGEで正社員です。関西で140-170/80~120万から受け付けております^^
得意技はJS(ES20xx),Java,AWSの大体のリソースです
コメントはやさしくお願いいたします^^
座右の銘は、「狭き門より入れ」「願わくは、我に七難八苦を与えたまえ」です^^




コメント