我已经使用Postman设置了一个有效的api调用,该调用返回了我想返回的信息。我需要使用Google Apps脚本设置相同的API调用,但由于某些原因搜索参数无法加载。 api响应的结果与Postman响应的结果相同,而没有加载任何搜索参数。
到目前为止,我的代码如下所示。我曾尝试以各种顺序删除和添加不同的设置,但没有找到能找到与我使用的搜索字词相关的卡片的任何内容。
function cardSearch(part) {
var settings = {
"method": "POST",
"contentType": "application/json",
"headers": {
"async": true,
"crossDomain": true,
"Authorization": "Basic *********",
"User-Agent": "PostmanRuntime/7.15.0",
"Accept": "*/*",
"Cache-Control": "no-cache",
"Postman-Token": "************",
"accept-encoding": "gzip, deflate",
"contentLength": "60",
"Connection": "keep-alive",
"cache-control": "no-cache"
},
"payload": JSON.stringify({"searchOptions": { "SearchTerm": part, "Page": 1 } })
// part is loaded into this function as a variable
}
var url = "https://**********.leankit.com/kanban/api/board/********/searchcards";
var response = UrlFetchApp.fetch(url,settings);
Logger.log(response);
var result = JSON.parse(response.getContentText());
var results = result.ReplyData[0].Results;
Logger.log(results);
}
预期结果: JSON描述了1张或多张带有标题或标题的卡片,其中包含我选择的搜索词(如果有)。
实际结果: JSON表示上传到我参考的leankit板上的前20张卡。
{TypeName=Test, ClassOfServiceId=0, Size=1, BlockReason=null, IsOlderThanXDays=true, SystemType=Card, Index=139, ActualStartDate=9/12/2018 4:11:09 PM, DrillThroughStatistics=null, CreateDate=9/10/2018, PriorityText=High, StartDate=9/12/2018, CurrentTaskBoardId=*****, ExternalCardIdPrefix=null, LastComment=null, AssignedUserIds=[******], CardTypeIconColor=212121, Version=84, LaneTitle=Finished As Planned, DrillThroughBoardId=null, Tags=Testing, SmallGravatarLink=********, ClassOfServiceCustomIconName=null, TypeId=*******, ClassOfServiceIconPath=null, DrillThroughProgressSizeComplete=null, ParentBoardId=0, Priority=2, Color=#0084FF, CurrentContext=Tasks, ExternalCardID=Material Testing, AssignedUsers=[{AssignedUserId=*********, AssignedUserName=*********, FullName=******** *****, Id=********, EmailAddress=******@*****.com, GravatarLink=*********, SmallGravatarLink=**********}], GravatarLink=********, DrillThroughProgressComplete=null, HasDrillThroughBoard=false, Active=false, ExternalSystemName=null, ExternalSystemUrl=null, Icon=, Id=********, DrillThroughCompletionPercent=null, CountOfOldCards=0, Description=<p>***********</p>, AssignedUserId=*******, ClassOfServiceTitle=null, LastAttachment=null, BoardId=**********, TypeColorHex=#0084FF, ActualFinishDate=9/15/2018 8:28:55 PM, HasMultipleDrillThroughBoards=false, CardDrillThroughBoardIds=[], TypeIconPath=null, ClassOfServiceColorHex=null, BoardTitle=********, TaskBoardTotalCards=3, DueDate=09/19/2018, DrillThroughProgressSizeTotal=null, IsBlocked=false, ParentCardId=null, ParentCardIds=[], AssignedUserName=******, TaskBoardCompletedCardSize=11, Title=Test Card, ClassOfServiceCustomIconColor=null, ParentBoardIds=[], CardTypeIconName=blank_icon, LastActivity=09/18/2018 03:28:55 PM, AttachmentsCount=0, DrillThroughProgressTotal=null, TaskBoardCompletionPercent=100, TaskBoardTotalSize=11, Type={Id=********}, CommentsCount=0, DateArchived=01/15/2018, LaneId=********, ParentTaskboardId=null, LastMove=09/16/2018 04:18:34 PM, TaskBoardCompletedCardCount=3, BlockStateChangeDate=null}
答案 0 :(得分:1)
'method':'post'
options
来说,不是UrlFetchApp.fetch()
的有效参数的所有内容都会进入headers
或payload
中-取决于您要调用的API的语法。特别是:async
和crossDomain
属于headers
,而data
中的所有内容都应分配给payload
这些问题可能对您有所帮助: