I’m working with Zapier’s Code by Zapier using JavaScript to make API calls. The problem is that my script keeps failing with a timeout error after exactly 1 second. The error message I get looks like this: “We had trouble sending your test through. Please try again. Error: Task timed out after 1.00 seconds”. It works sometimes but fails most of the time.
Here’s the code I’m using to call the API:
var requestPromises = [];
var apiResponse;
requestPromises.push(fetch(apiUrl));
Promise.all(requestPromises).then(function(response){
var textPromises = [];
for (var j = response.length - 1; j >= 0; j--) {
textPromises.push(response[j].text());
}
return Promise.all(textPromises);
}).then(function(responseBody){
apiResponse = JSON.parse(responseBody);
var apiTitles = [apiResponse.length];
var timeLength = [apiResponse.length];
var itemIds = [apiResponse.length];
for(var j=0; j<apiResponse.length; j++){
apiTitles[j] = apiResponse[j].title;
timeLength[j] = convertMillisecondsToTime(apiResponse[j].files[0].fileInfo.duration);
itemIds[j] = apiResponse[j].id;
}
var result = {apiTitles, timeLength, itemIds};
callback(null, result);
}).catch(callback);
I think free accounts only get 1 second for API calls. Is there a way to work around this limitation without upgrading my account?
Had this exact problem last year. You’re right about the nested promises, but the real killer is all that synchronous work after the API call. That convertMillisecondsToTime function is probably blocking everything while your timer’s still ticking. I fixed it by doing minimal processing in Zapier and moving the heavy stuff to a webhook on a cheap VPS. Can’t do that? At least cache those convertMillisecondsToTime results or pre-compute them. Also check if your API has pagination or lets you select specific fields - smaller payloads help a ton. Remember, that 1 second limit covers everything from request start to callback finish, not just network time. Got mine running consistently under 900ms by killing all synchronous loops and moving string operations outside the promise chain.
Yeah, the 1-second timeout on Zapier’s free tier is a hard limit, but your code’s definitely causing delays you can fix. Your nested Promise.all() chains are adding overhead you don’t need. Plus you’re parsing JSON and doing array operations right inside the promise chain, which slows things down. Flatten those promises and move JSON parsing outside the main promise. If you can hit the API with specific parameters to shrink response size, do it - smaller responses = faster processing. I’ve noticed pre-allocating arrays with set sizes works better than using array.length in Zapier’s environment. Test locally first and aim for under 800ms. That gives you breathing room since Zapier’s timeout includes both network and processing time. Every millisecond matters here.
your code’s processng too much inside the promise chain - thats killing performnce. move the JSON parsing and array ops outside, or switch to async/await for cleaner, faster code. that convertMillisecondsToTime function could be a bottleneck if its doing heavy work. cache API responses and strip out any data u dont actually need.