@kintone/rest-api-client(以下簡稱「本用戶端」)是整合了在JavaScript中操作kintone REST API時所需處理的函式庫。
它支援Web瀏覽器和Node.js環境。
詳情請參閱以下頁面。

// CommonJS
const {KintoneRestAPIClient} = require('@kintone/rest-api-client');
// ES modules
import {KintoneRestAPIClient} from '@kintone/rest-api-client';

在您創建的記錄的URL中,找到記錄ID。
如過紀錄URL為 https://sample.cybozu.com/k/123/show#record=1 時, record= 後的數字為記錄ID。
在上述例子中,紀錄ID為「1」。

Step2:建立範例程式

將以下內容貼上到文字編輯器中:

* kintone JavaScript Client sample program (for kintone environment) * Licensed under the MIT License * https://opensource.org/license/mit/ (() => { 'use strict' ; kintone.events.on( 'app.record.index.show' , async (event) => { try { // 創建用戶端 const client = new KintoneRestAPIClient(); // 設置請求參數 const APP_ID = kintone.app.getId(); const RECORD_ID = 1 ; const params = { app: APP_ID, id: RECORD_ID // 獲取記錄 const resp = await client.record.getRecord(params); console.log(resp.record); } catch (err) { console.log(err); })();

在「PC用的JavaScript/CSS檔案」中依以下順序指定URL和檔案:

  • https://js.cybozu.com/kintone-rest-api-client/5.6.0/KintoneRestAPIClient.min.js
  • 範例代碼(kintone-rest-api-sample.js)
  • 在「應用程式設置」畫面中,點擊【更新應用程式】。

    Step4:執行確認

    開啟套用自訂的kintone應用程式列表畫面。

    打開瀏覽器的開發者工具。

    確認主控台中輸出了取得的紀錄內容。

    在您創建的記錄的URL中,找到記錄ID。
    如過紀錄URL為 https://sample.cybozu.com/k/123/show#record=1 時, record= 後的數字為記錄ID。
    在上述例子中,紀錄ID為「1」。

    Step2:安裝所需的套件

    為專案創建目錄。
    建立專案目錄,例如「sample」。
    開啟終端並鍵入以下命令,然後按「Enter」:

    const resp = await client.record.getRecord(params); console.log(resp.record); } catch (err) { console.log(err); })();
    "value": {"code": "yamada" , "name": "山田太郎" } "$revision": { "type": "REVISION" , "value": "2" }, "更新時間": { "type": "UPDATED_TIME" , "value": "2020-05-13T04:24:00Z" }, "建立時間": { "type": "CREATED_TIME" , "value": "2020-02-28T04:13:00Z" }, "$id": { "type": "ID" , "value": "1" }

    此用戶端支援密碼驗證、API權杖驗證、使用OAuth用戶端的驗證和Session驗證。

    驗證資訊在kintoneRESTAPIClient的參數物件的auth屬性中設置。

    以下範例假設在Node.js環境中使用(不包含Session認證), 並從環境變數中讀取認證資訊。
    若從瀏覽器環境使用,請不要將認證資訊硬編碼(hardcode)在JavaScript檔案中。
    有關說明,請參閱以下頁面。

    const client = new KintoneRestAPIClient({
      auth: {
        oAuthToken: process.env.KINTONE_OAUTH_TOKEN
      // ...大約...
      basicAuth: { // Basic身分驗證設定
        username: process.env.KINTONE_BASIC_USERNAME,
        password: process.env.KINTONE_BASIC_PASSWORD
      // ...省略...
      
    在設置了SecureAccess的環境中

    如果已在kintone環境中設置了SecureAccess,請在kintoneRestAPIClient參數物件中添加clientCertAuth屬性來指定用戶端憑證的檔案。

    指定憑證的方法有兩種:「使用pfx屬性直接指定二進位資料」和「使用pfxFilePath屬性指定檔案路徑」。

    以二進位資料方式指定

    clientCertAuth: { pfxFilePath: './cert.pfx', password: process.env.KINTONE_CLIENT_CERTIFICATE_PASSWORD // ...省略...