2

致力于使用 zapier CLI 创建自定义 zapier 集成。我的 API 端点在技术上不是 create,但它使用 POST 方法,所以我在 zapier 中的 create 定义下创建它。我将输出字段设置为空,但它在我的空响应对象上中断。

outputFields: []

错误信息:

We had trouble sending your test through.
Unexpected end of JSON input
Hide details
Troubleshooting Errors | Contact Support
What happened (You are seeing this because you are an admin):
  Starting POST request to https://api.fake.com/v2/demo-finance/live/csh-search
  Received 202 code from https://api.fake.com/v2/demo-finance/live/csh-search after 596ms
  Received content ""
  Unexpected end of JSON input

一切都按预期工作,请求通过它只是对空字符串响应不是有效的 JSON 不满意。有没有办法告诉 zapier 这是一个可接受的响应对象?

4

1 回答 1

1

大卫在这里,来自 Zapier 平台团队。

如果您的 API 以这种方式工作,那很好,但您仍然需要从您的函数返回一些可序列化的 json。尝试这样的事情:

const performCreate = async (z, bundle) => {
  const response = await z.request('https://api.fake.com/v2/demo-finance/live/csh-search')
  if (response.statusCode === 202) {
    return {}
  }
  // handle errors, other cases, whatever
  // just make sure to return an object
}

作为旁注,仅仅因为请求使用 POST 请求并不意味着它必须是Create; 它应该是对操作最有意义的任何类型。如果是搜索(就像假网址所暗示的那样),搜索可能是要走的路。

于 2019-04-02T03:14:49.877 回答