api - 如何通过 Apps 脚本在 API 请求中传递会话 ID?
问题描述
我正在尝试通过 Google Sheets / Apps Script访问我们的 CRM文档的 API。通过 Postman 访问 API 时,我没有任何问题,并使用以下设置获得所需的结果:
发布:https://api.sharpspring.com/pubapi/v1.2/?accountID={{accountID}}&secretKey={{secretKey}}
身体:
{
"id":"12345678912345678999",
"method": "getOpportunities",
"params": {
"where": {},
"limit":"500",
"offset": "0"
}
}
现在,当我尝试在 Apps 脚本中复制相同内容时,我得到以下结果:
{结果:空,错误:{代码:102,消息:'标头缺少请求ID',数据:[]},id:空}
我正在运行的功能如下:
function myFunction() {
var URL = "https://api.sharpspring.com/pubapi/v1.2/?accountID={{accountID}}&secretKey={{secretKey}}"
var body = {
"method": "POST",
"body": raw,
"headers": {"Content-Type": "application/json"},
"redirect": "follow"
}
var raw = {
"method": "getOpportunities",
"id": "12345678912345678999",
"params": {
"where": {},
"limit":"500",
"offset": "0"
}
}
var results = UrlFetchApp.fetch(URL, body).getContentText();
var data = JSON.parse(results);
console.log(data);
}
在两者中,我都传递了一个随机会话 ID“12345678912345678999”。我尝试在 cookie 中查找会话 ID,但没有奏效,我认为我在那里走错了路。直接在标头中传递 id 也不起作用。
有任何想法吗?提前非常感谢!
解决方案
推荐阅读
- c - 编写嵌入式驱动程序的序列
- java - 如何让我的 HashMap 正确打印到文件
- javascript - Chrome:所选元素未收到“复制”事件
- docker - Gitlab CI with docker+machine - 使用多个容器测试应用程序
- java - Drools 嵌套聚合
- ios - 未调用具有自定义 isSelected 设置器的 MKAnnotationView 子类
- amazon-web-services - AWS Athena 查询分区
- angular - 如何使用 gridOptions 为 ag-grid/angular 中的行着色?
- linux - 无法从 git clone go.googlesource.com 克隆 Git 存储库
- python - openpyxl没有将数据框写入excel表