获取 POST 到 Tsheets API returns "code": 417, "message": "Expectation Failed: data field missing"

Fetch POST to Tsheets API returns "code": 417, "message": "Expectation Failed: data field missing"

我正在尝试创建一个 Zapier Zap 以通过 Tsheets API 拉取和推送数据 from/to Tsheets。我已经成功地使用 Fetch 方法从 Tsheets 获取数据。我现在正在尝试 POST 数据,经过一天的谷歌搜索和搜索这个网站后,我仍然没有想出解决方案,所以我希望你们能给我一些线索。

这是我的 POST 代码:

var payload = '{data:[{name:"aServiceItem1", customfield_id:"118530", short_code:"c1" }, {name:"aServiceItem2", customfield_id:"118530", short_code:"c1"}]}';
var endpoint = "https://rest.tsheets.com/api/v1/customfielditems";

fetch(endpoint, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer <my_token>"
  },
  data: JSON.stringify(payload)
})
  .then(function(response) {
    return response.text();
  })
  .then(function(responsebody) {
    var output = {
      response: responsebody
    };
    callback(null, output);
  })
  .catch(function(error) {
    callback(error);
  });

在 Zapier zap 开发控制台中,测试此步骤它编译无误并与 Tsheets 通信 API 然而我得到的响应是

response { "error": { "code": 417, "message": "Expectation Failed: data field missing" } }

据我所知,根据 Tsheets API 文档 here,唯一的必填项目是 "name" 和 "customfield_id" 并且据我所知在我的代码中告诉我正在提供这些。该文档中有一个响应项 _status_extra,它可能会为我提供更多信息,但我没有在响应中看到该值。我可以修改我的代码以提供该值吗?

有人知道为什么我的代码无法 POST 我的数据吗?

免责声明:POST 代码不是我自己的,我是在这个网站上找到的。

TIA。

好的,记录一下,这就是最终的效果。

var payload =  { "data": [{"name": "From Zapier2", "customfield_id": "118530", "short_code": "FZ2"}]};

var endpoint = "https://rest.tsheets.com/api/v1/customfielditems";

fetch(endpoint, {
    method: "POST",
    headers: {"Content-Type": "application/json", "Authorization": "Bearer <MyToken>"},
    body: JSON.stringify(payload)
    })
      .then(function(response) {
        return response.text();
      })
      .then(function(responsebody) {
        var output = {response: responsebody};
        callback(null, output);
      })
    .catch(function(error) {
        callback(null, error);
    });