【问题标题】:What does this response object mean? ( Zapier JS code )这个响应对象是什么意思? (扎皮尔 JS 代码)
【发布时间】:2018-02-06 15:48:37
【问题描述】:

我在 Zapier Code 中有以下代码:

var settings = {
  "url": "https://<HOST>/api/v1/siteinfo",
  "method": "GET",
  "crossDomain": true,
  "headers": {
    "authorization": "Basic <TOKEN>",
    "cache-control": "no-cache"
  }
}

fetch(settings.url, settings)
  .then(function(res) {
    return res.text();
  })
  .then(function(body) {
    var output = {id: 1234};
    callback(null, output);
  })
  .catch(function(error) {
  callback(error.text());
};

我基本上是从Zapier documentation复制过来的。

运行此请求后,我得到以下响应:

为什么会有大量数据、一些缓冲区内容等,而不仅仅是简单的{id: 1234}

【问题讨论】:

    标签: javascript integration fetch-api zapier


    【解决方案1】:

    这个问题有两个方面:

    1.为什么代码不起作用?

    目前 Zapier 没有直接的方法来告诉您的代码更新不会生效,除非您告诉 Re-test Code by Zapier 让另一个运行 javascript 可以在 Zap 步骤的 Test this step 项中找到。

    另一种方法是添加一些输入参数。这也让 Zapier 重新评估代码。

    2。我得到的对象是什么?

    这是由Fetch API 定义的原始Response Object。在将其设为 regular 格式之前,需要使用诸如 Zapier 示例中所述的.text().json() 之类的特定方法对其进行解析。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-16
      • 2011-06-02
      • 2011-08-26
      • 2011-05-28
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多