獲取執行外部 API 所需的資訊

information

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

目錄

獲取執行外部 API 所需的資訊

使用 從外掛程式執行外部 API 的API,以獲取在執行外部 API 時添加到請求標頭和資料中的資訊。
添加到請求中的資訊是在 將執行外部 API 所需的資訊儲存在外掛程式 的 API中指定的資訊。

函數

PC

kintone.plugin.app.getProxyConfig(url, method)

參數

參數 類型 必須 說明
url 字串 必須 要執行的 API 的 URL
method 字串 必須 HTTP 方法
指定以下值之一:
  • GET
  • POST
  • PUT
  • DELETE

返回值

執行外部 API 所需的資訊以“key:value”配对的物件形式返回。

參數名稱 類型 說明
headers 物件 從外掛程式執行外部 API 這個 API的 headers 中指定的請求標頭
data 物件 將執行外部 API 所需的資訊儲存在外掛程式 這個 API 的 data 中指定的请求正文
Null 條件

可使用的畫面

  • 每個外掛程式的設定畫面

示例代碼

這是獲取用 將執行外部 API 所需的資訊儲存在外掛程式 這個 API 存儲的資訊的範例。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
const headers = {
  Authorization: 'Bearer TEST_TOKEN',
};
const data = {
  key1: '1',
  key2: true
};
kintone.plugin.app.setProxyConfig('https://api.example.com', 'POST', headers, data);
const config = kintone.plugin.app.getProxyConfig('https://api.example.com', 'POST');
console.log(config);

注意事項

  • 如果使用該 API 獲取 將執行外部 API 所需的資訊儲存在外掛程式 這個 API header 中指定的值時,返回的值必是字串。
    例如, 將執行外部 API 所需的資訊儲存在外掛程式headers 中指定數值或布爾值布林值。

    1
    2
    3
    4
    5
    
    const headers = {
      key1: 1, // 數值
      key2: true, // 布森值
    };
    kintone.plugin.app.setProxyConfig('https://api.example.com', 'POST', headers, {}, () => console.log('Saved!'));

    在這種情況下,執行 獲取執行外部 API 所需的資訊 這個 API 時,數值和布爾值將作為字串類型返回。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    
    const config = kintone.plugin.app.getProxyConfig('https://api.example.com', 'POST');
    console.log(config);
    /**
    * 1 和 true 的類型為字串
    * {
    *    headers: {
    *      "key1": "", // 字串
    *      "key2": "true",  // 字串
    *    },
    *    data: {},
    *  }
    **/