如何通过 Apps 脚本在 API 请求中传递会话 ID?

问题描述

我正在尝试通过 Google 表格/Apps 脚本访问我们的 CRM Documentation 的 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","offset": "0"
      }
    }

  var results =  UrlFetchApp.fetch(URL,body).getContentText();
  var data = JSON.parse(results);
  console.log(data);

}

在两者中,我都传递了一个随机会话 ID“12345678912345678999”。我尝试在 cookie 中找到一个会话 ID,但这没有用,我认为我在那里走错了路。直接在标头中传递 id 也不起作用。

有什么想法吗?非常感谢提前!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)