zmii
zmii

Reputation: 4277

basic http auth in zappier code

I'm trying to send HTTP request with Zapier Code to hit my API to do some GET and POST requests.

enter image description here

API requires API_KEY in form of authorization header to understand my requests. Here is code I'm running

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

fetch(settings.url, settings)
.then(function (r) {
  callback({data: r});
}).catch(callback);

But get this error:

enter image description here

What is wrong with my code?

Upvotes: 0

Views: 379

Answers (1)

zmii
zmii

Reputation: 4277

It turns out that the first argument of callback function is always error, thus if we have the some result to pass from asynchronous action we should pass null as the first argument to callback, e.g. in my case I should have this:

fetch(settings.url, settings)
.then(function (r) {
  callback(null, {data: r});
}).catch(callback);

Upvotes: 1

Related Questions