發送 kintone REST API 請求

information

本頁面使用機器翻譯而成。
機器翻譯免責聲明 (External link)

目錄

發送 kintone REST API 請求

執行 kintone REST API 和 User API。

函數

PC/行動裝置

kintone.api(pathOrUrl, method, params, successCallback, failureCallback)

參數

參數名稱 類型 必須 說明
pathOrUrl 字串 必須 kintone API 路徑或 URL
例如,API 的 URL 為“https://sample.cybozu.com/k/v1/records.json“時,指定為“/k/v1/records.json”。
結尾省略".json"時,生成的 URL 會自動添加".json"。
也可以指定用獲取 API URL 的 API( 無查詢字串/ 帶查詢字串)來獲取的值。
method 字串 必須 HTTP 方法
指定以下值之一:
  • GET
  • POST
  • PUT
  • DELETE
params 物件 必須 要執行的 API 的請求參數
successCallback 函數 可省略 API 呼叫成功時執行的回調函數
傳遞給回調函數的參數的類型是物件。
如果省略,返回 kintone.Promise 物件 並用傳遞給 successCallback 的參數做解析。
failureCallback 函數 可省略 API 呼叫失敗時執行的回調函數
回調函數的參數以 JSON 格式傳遞錯誤內容。
如果錯誤的內容無法解析為 JSON,則傳遞未解析的字串。
如果省略,返回 kintone.Promise 物件, 並用傳遞給 failureCallback 的參數來廢棄。

返回值

如果指定 successCallback ,則沒有返回值。
如果省略參數 successCallback ,返回 kintone.Promise 物件

可使用的畫面

PC/行動裝置

它可在所有畫面上使用。

示例代碼

如何使用回調進行編寫
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
const body = {
  app: kintone.app.getId(),
  id: 1
};

kintone.api(kintone.api.url('/k/v1/record.json', true), 'GET', body, (resp) => {
  // success
  console.log(resp);
}, (error) => {
  // error
  console.log(error);
});
如何使用 kintone.Promise 物件編寫
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
(async () => {
  const body = {
    app: kintone.app.getId(),
    id: 1
  };

  try {
    const resp = await kintone.api(kintone.api.url('/k/v1/record.json', true), 'GET', body);
    // success
    console.log(resp);
  } catch (error) {
    // error
    console.log(error);
  }
})();

限制