问题描述
我正在尝试发送带有Zapier代码的HTTP请求以达到我的API来执行一些获取和发布请求.
api需要 api_key 以授权的形式标题以了解我的请求.这是我正在运行的代码
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);
但是获取此错误:
我的代码有什么问题?
推荐答案
事实证明,回调函数的第一个参数始终是错误的,因此,如果我们有一些结果可以从异步操作传递,我们应该将null作为第一个参数传递给callback,例如就我而言,我应该有:
fetch(settings.url, settings) .then(function (r) { callback(null, {data: r}); }).catch(callback);
问题描述
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?
推荐答案
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);
相关标签/搜索