basic http auth in zappier code

孤者浪人 提交于 2019-12-12 04:57:52

问题


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

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:

What is wrong with my code?


回答1:


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);


来源:https://stackoverflow.com/questions/45934030/basic-http-auth-in-zappier-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!