Zapier自定义响应对象

时间:2019-04-01 19:45:27

标签: javascript json zapier zapier-cli

使用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这是一个可接受的响应对象?

1 个答案:

答案 0 :(得分:1)

Zapier Platform团队的David在这里。

如果您的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;它应该是对操作最有意义的任何类型。如果是搜索(如假网址所示),则搜索可能是一种方法。