I’m working with a Code by Zapier action that runs on node.js. I want to make HTTP requests to integrate with an external API but I’m getting an error about needing callbacks for async operations.
My current code works fine when I test it locally, but fails in Zapier:
Zapier throws an error saying I need to use callbacks for async operations with fetch. How do I modify this code to work properly in the Zapier environment? What’s the correct way to handle asynchronous requests in their Code action?
Zapier needs you to explicitly call the callback function for async operations - that’s what’s causing your timeout. Your fetch chain isn’t telling Zapier when it’s done. Add callback(null, your_output_data) in your final .then() block and callback(error_message) in your .catch() block. Without these callbacks, Zapier thinks your code’s still running and kills it. I hit the same issue moving local scripts to Zapier - you’ve got to signal when async stuff finishes. Also make sure you’re assigning your output inside the promise chain before calling the callback, not after the fetch like you’re doing now.
zapier’s strict on async, so you gotta use their callback setup. try wrapping fetch like this: fetch(…).then(res => …).then(data => callback(null, output)). now zapier knows when your code’s done!
This happens because Zapier needs explicit completion signals for async operations. You’re setting the output variable before the fetch finishes, so Zapier returns the output while your API call’s still running in the background. You need to restructure everything to happen within the promise chain. Move your output assignment inside the final then block and add the callback there: