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

167 views Asked by At

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:

enter image description here

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

1

There are 1 answers

0
zmii On

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.

enter image description here

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.