使用Google脚本和Trello API,我无法发送放置请求以在预定义的trello自定义字段上设置选项。
这是trello API对javascript的建议,但是由于我使用的是Google脚本,因此我不得不使用Google的“ UrlFetchApp”类,我该怎么做?
var url = "https://api.trello.com/1/cards/{idCard}/customField/{idCustomField}/item?token={yourToken}&key={yourKey}";
var data = {value: { number: "42" }};
fetch(url, { body: JSON.stringify(data), method: 'PUT', headers: {'content-type': 'application/json'}})
.then((resp) => resp.json()) //Error would occur here
.then((data) => console.log(JSON.stringify(data, null, 2)))
.catch((err) => console.log(JSON.stringify(err, null, 2)))
https://developers.trello.com/reference#customfielditemsid
如果我尝试在Google脚本中运行该示例,则会收到错误消息:
Syntax error. (line 135, file "Code")
因此,我尝试使用URLFetchApp:
var url = "https://api.trello.com/1/cards/" + cardId + "/customField/{customFieldIDHere}/item?token={TokenHere}&key={KeyHere}";
var data = {value: { "text": "42" }};
var payload = {"customField" : data};
var options = {"method" : "put",
"payload" : payload};
UrlFetchApp.fetch(url,options); //Error would occur here
https://developers.google.com/apps-script/reference/url-fetch
但是我得到这个错误:
"Request failed for https://api.trello.com returned code 400. Truncated server response: Invalid value for custom field type"
我也尝试做var
mData = JSON.stringify(data);
并在选项中使用mData,但不幸的是仍然遇到相同的错误 最佳答案
问题是,我不需要var = {customField" : data}
相反,我需要做的是:
var options = {
"method" : "put",
"payload" : JSON.stringify(data),
"contentType": "application/json"
};
关于javascript - 如何使用Google脚本在Trello的自定义字段中添加值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58686670/