简体   繁体   中英

What does this response object mean? ( Zapier JS code )

I have the following code in 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());
};

which I've basically copied from Zapier documentation .

After running this request I get this response:

在此处输入图片说明

Why there is lot's of data, some buffer contents etc. and not just simple {id: 1234} ?

There are two sides of this question:

1. Why didn't the code work?

Currently Zapier doesn't have straightforward way of telling that your code updates will not be in effect unless you will tell Re-test Code by Zapier to get another run javascript which can be found on Test this step item of Zap step.

在此处输入图片说明

Another way is to add some input parameter. This also make Zapier to reevaluate the code.

2. What is the object I was getting?

This is raw Response Object defined by Fetch API . One need to parse it with some specific method like .text() or .json() as described in examples of Zapier prior to have it in regular format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM