Search code examples
javascriptnode.jszapier

Is it possible to start a server in Zapier Code


We need to send an HTTP CODE = 200 with a body 'OK' in reply to a notification through Zapier.

Is it possible to use the following code in Zapier:

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

It returns an error:

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

And the reply doesn't work.


Solution

  • David here, from the Zapier Platform team.

    To cut to the chase - though it might be possible to start an http server (there's no reason it wouldn't be, as far as I know), it's not going to do what it seems like you're hoping to do. Namely, you can't send a custom response to an incoming webhook. From the 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.

    If you need behavior like that, I'd suggest running a webserver.

    The specific Code step error you're seeing has to do with not defining output to the function. Something goes in and something must come out. You can customize the output based on the input and use that output, but something has to be returned from the function (even if it's just {}).