zappier代码中的基本HTTP身份验证 [英] basic http auth in zappier code

查看:87
本文介绍了zappier代码中的基本HTTP身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Zapier代码发送HTTP请求以击中我的API来执行一些GET和POST请求.

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

API需要 authorization 标头形式的 API_KEY 才能理解我的请求.这是我正在运行的代码

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

但是出现此错误:

我的代码有什么问题?

推荐答案

事实证明,回调函数的第一个参数始终是错误的,因此,如果我们从异步操作中获得某些结果,我们应该将null作为第一个参数传递给callback,例如就我而言,我应该有这个:

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

这篇关于zappier代码中的基本HTTP身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆