How to Send Data to Webhooks Using Zapier JavaScript Code Step

I’m stuck trying to send data to a webhook through Zapier’s JavaScript code action. I need to use the code step because I want to pass dynamic data to the same webhook endpoint.

Here’s what I’m trying to do:

fetch('https://hooks.zapier.com/hooks/catch/123456/abc123/', {
  method: 'POST',
  body: 'name=john, status: active'
})
.then(response => {
  return response.json();
})
.then(data => {
  console.log(data);
})
.then(() => {
  callback();
})
.catch(callback);

But I keep getting this error message: “Error: You must return a single object or array of objects.”

I think I’m missing something basic here but can’t figure out what. Any ideas on how to fix this?

That callback() approach is outdated for Zapier code steps. Modern Zapier JavaScript actions just need you to return output directly - no callbacks needed. Try this:

const response = await fetch('https://hooks.zapier.com/hooks/catch/123456/abc123/', {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({name: 'john', status: 'active'})
});

return {webhook_response: response.status, sent_data: {name: 'john', status: 'active'}};

Hit this same issue last month. Just ditch the callback completely and make sure you’re returning an object with useful data. Your body syntax was also broken - use proper JSON format with JSON.stringify().

Your fetch request runs but doesn’t return anything - that’s the problem. Zapier code steps need you to return data, not just execute callbacks. Here’s how to fix it: const response = await fetch(‘https://hooks.zapier.com/hooks/catch/123456/abc123/’, { method: ‘POST’, headers: {‘Content-Type’: ‘application/json’}, body: JSON.stringify({name: ‘john’, status: ‘active’}) }); const data = await response.json(); return data; Also, your body format’s wrong - you’re mixing object and string syntax. Use JSON.stringify to format it properly. That return statement’s crucial because Zapier expects output data for the next step.

the main prob is ur not awaiting the fetch & missing the return. zapier code steps need data returned properly or theyll fail. also, that body format is wrong - it should be actual json, not a stringified version. switch to async/await instead of .then chains. its much cleaner.