I’m stuck with a JavaScript code step in Zapier that makes HTTP POST requests to webhook endpoints. The code runs but throws an error saying I need to return a single object or array of objects.
Here’s my current approach:
fetch('https://webhook.site/12345678-abcd-efgh-ijkl-mnopqrstuvwx', {
method: 'POST',
body: 'name=john, status: active'
})
.then(response => {
return response.json();
})
.then(data => {
console.log(data);
})
.then(() => {
callback();
})
.catch(callback);
The webhook call works fine but Zapier complains about the return format. What am I missing here? I need to send dynamic data to the same endpoint which is why I’m using a code step instead of the regular webhook action.
yeah, return the data in the right format. replace callback() with return {status: 'success', data: data}; so zapier recognizes it. it’s tricky but watch those return values!
Had the same issue when I started using code steps more. Zapier needs your code block to return something it can use in the next step. Right now you’re just calling the webhook without giving Zapier any output. Wrap your fetch in an async function and return the response: const webhookResponse = await fetch(...); const responseData = await webhookResponse.json(); return responseData; Now Zapier gets the actual webhook response and can pass it to the next steps. Also, you might need to JSON.stringify your body depending on what your webhook expects - I’ve hit content-type issues with plain text bodies before.
The issue you’re encountering is due to not returning the data in the correct format. In Zapier’s JavaScript code steps, you need to return an object or an array explicitly; otherwise, the subsequent steps won’t receive any data at all. Instead of using callback(), you should structure your return like this:
const response = await fetch('https://webhook.site/12345678-abcd-efgh-ijkl-mnopqrstuvwx', {
method: 'POST',
body: 'name=john, status: active'
});
const result = await response.json();
return {
webhook_response: result,
success: true
};
By utilizing async/await and returning an object directly, you provide Zapier with the data it needs, thereby resolving the callback error.