1
我對Google Apps Script
很新。我正在嘗試創建一個腳本來從公共API中提取數據。我需要傳遞參數,但無法弄清楚如何做到這一點的Apps Script
Apps腳本將參數傳遞給cUrl
的API documenation指示信息可以這樣訪問:
curl -H "Content-Type: application/json" -X GET
--header "X-PW-AccessToken:<TOKEN>" \
--header "X-PW-Application:developer_api" \
--header "X-PW-UserEmail:<USER_EMAIL_ADDRESS>" \
-d '{"name":"My Lead","email":{"email":"[email protected]","category":"work"}}'
我有這個功能設置在Apps Script
:
function myFunction() {
var url = "https://api.prosperworks.com/developer_api/v1/leads/search";
var fetchParameters = {};
fetchParameters.method = "post";
fetchParameters.contentType = "application/json";
fetchParameters.headers = {
"X-PW-AccessToken": <TOKEN>,
"X-PW-Application": "developer_api",
"X-PW-UserEmail": <USER_EMAIL_ADDRESS>
};
fetchParameters.muteHttpExceptions = true;
fetchParameters.payload = {"name":"My Lead","email":{"email":"[email protected]","category":"work"}};
var response = UrlFetchApp.fetch(url, fetchParameters);
var dataAll = JSON.parse(response.getContentText());
}
我加fetchParameters.payload
,因爲這似乎是如何傳遞的價值觀,但我在解析JSON
得到這個錯誤:
Execution failed: SyntaxError: Unexpected token: <
如果我註釋掉fetchParameters.payload
它可以成功運行,但不會影響任何參數(顯然)。
我嘗試過:fetchParameters.d
,fetchParameters.data
,和其他許多,但似乎沒有任何工作。