Skip to main content

Hi All,

I’m currently developing a Zapier integration and would appreciate some input on best practices for long running API calls.

We currently return a 201 accepted response if the API call exceeds x seconds, with a ‘location’ header specifying the URL to get the status of the call and a ‘retry-after’ header specifying how frequently to retry.

I’ve drawn a bit of a blank when searching for how to configure our Zapier action to support this. I assume I would need some custom JavaScript code that checks for a 201 response and performs some retry logic. If my assumption is correct, could anyone point me in the direction of some sample code to help with this?

The documentation I have found for long running API calls seems to recommend creating a webhook and posting the results on completion, would we be better of implementing this?

 

Thanks!

Hey @SMB 👋

You could write code to make follow-up “retry” requests based on the response status code and headers that the API is returning. I’d recommend researching JavaScript Promises to learn more about how to do that. This community post has some pointers and additional information that might be useful to you: 

As per the community post I’ve linked to above, it’s important to note that actions have a timeout limit of 30 seconds. This means all requests sent by the action (including any “retries”) would need to be completed in 30 seconds to avoid hitting a “timeout” error: https://platform.zapier.com/docs/constraints#timeouts-actions

Will the API you’re using take longer than 30 seconds to complete processing? If so and you are able to make the API post data to a specific URL on completion, I’d recommend using the z.generateCallbackUrl() method via a CLI app as it has been designed specifically to solve this use case: https://platform.zapier.com/cli_docs/docs#zgeneratecallbackurl