【问题标题】:How to set zapier cli authentication?如何设置zapier cli身份验证?
【发布时间】:2022-01-23 20:24:56
【问题描述】:

我正在尝试使用 zapier cli 构建应用程序。 我在授权请求时遇到问题。 我正在使用 api 密钥和客户端 ID。 当我尝试在 UI 中使用相同的凭据时 它工作完美,但是在 cli 中它给出了错误代码 403。

我已经列出了下面的代码。可能是什么问题?

//test 
"use strict";

const should = require("should");

const zapier = require("zapier-platform-core");

const App = require("../index");
const appTester = zapier.createAppTester(App);

describe("custom authentication authentication", () => {
  // Put your test TEST_USERNAME and TEST_PASSWORD in a .env file.
  // The inject method will load them and make them available to use in your
  // tests.
  zapier.tools.env.inject();

  it("should authenticate", (done) => {
    const bundle = {
      authData: {
        api_key: process.env.API_KEY,
        client_id: process.env.CLIENT_ID,
      },
    };

    appTester(App.authentication, bundle)
      .then((response) => {
        should.exist(response);
        done();
      })
      .catch(done);
  });
});


//authentication.js

"use strict";

const currentDate = new Date();
const year = currentDate.getFullYear();
const month = currentDate.getMonth() + 1;
const day = currentDate.getDate();

const authentication = (z, bundle) => {
  const options = {
    url: "url",
    method: "GET",
    headers: {
      ContentType: "application/json",
      Accept: "application/json",
      "x-api-key": bundle.authData["api_key"],
      client_id: bundle.authData["client_id"],
    },
    params: {
      year: year,
      month: month,
      day: day,
      page_size: "1000",
    },
  };

  return z.request(options).then((response) => {
    response.throwForStatus();
  });
};

module.exports = authentication;

【问题讨论】:

    标签: node.js zapier


    【解决方案1】:

    您在应用程序根目录的.env 文件中有值吗?您还可以仔细检查 console.log(process.env.API_KEY) 在测试运行时是否打印了一个值。


    顺便说一句,您可以使用zapier convert CLI 命令将您的集成从 UI 复制到 CLI,而无需重新编写它。如果它可以在 UI 中运行,那么它也可以在 CLI 中运行。

    【讨论】:

      猜你喜欢
      • 2017-09-07
      • 2018-09-06
      • 1970-01-01
      • 1970-01-01
      • 2020-05-29
      • 2016-12-27
      • 1970-01-01
      • 1970-01-01
      • 2016-12-03
      相关资源
      最近更新 更多