是否可以在 Zapier 代码中启动服务器

Is it possible to start a server in Zapier Code

我们需要发送一个 HTTP CODE = 200 和正文 'OK' 来回复通过 Zapier 的通知。

是否可以在Zapier中使用以下代码:

var http = require('http');
  const server = http.createServer((req,res) => {
  res.statusCode = 200;
  res.end('OK');
}).listen(80);

它returns一个错误:

Error: You did not define `output`! Try `output = {id: 1, hello: "world"};`

回复无效。

来自 Zapier 平台团队的大卫。

切入正题 - 虽然可以启动一个 http 服务器(据我所知,没有理由不这样做),但它不会像你看起来那样做希望做。也就是说,您无法向传入的 webhook 发送自定义响应。来自 docs:

There is no way to customize the response to the request you send to the Catch Hook URL, as the response is sent before the Zap triggers and runs on the webhook request.

如果您需要这样的行为,我建议 运行 网络服务器。

您看到的特定代码步骤错误与未定义函数输出有关。有些东西进去,有些东西必须出来。您可以根据输入自定义输出并使用该输出,但函数必须返回一些内容(即使只是 {})。