Timed Request Loops in JS in Integrations

Alejandro Posted by: Alejandro Hernandez Date Posted: February 27, 2025
Back to Case Studies

Issue

In an integration, we are able to connect to an API using custom JS but bulk requests are not available and we don’t want to use up a lot of tasks.

Solution

The solution uses the code action almost as far as its timeout limit will allow, resulting in great optimization while allowing for variability in API response times. This solution will generally need to be used along with while loops and variables.

Achievement

Process large numbers of requests sequentially, staying under the time limits of the Workato JS action (30 seconds).

Snippet/Screenshot/Link

Timer function snippet – runs 28 seconds, allowing 2 seconds to bail:
var executionStart = Date.now()
var keepExecuting = () => {
return (Date.now() – executionStart) < 28000
}

Link to example recipe using it.