Best practice to handle 50+ invokeurl calls in a loop without hitting the 30-second timeout?

Best practice to handle 50+ invokeurl calls in a loop without hitting the 30-second timeout?

Hi everyone,

I am working on a custom Deluge function where I have a Map containing around 50+ key-value pairs. I need to iterate through this Map using a for each loop and make a GET API call (invokeurl) for each item.

The Problem: Because of the 50+ consecutive API calls, the script inevitably throws the following error before it can finish: "Function cannot be executed as it has exceeded the 30 seconds timeout limit."

Here is a simplified structure of my code:

Code snippet
my_map = Map();
// Map contains 52 items
my_map.put("Item1", "ID_1");
// ...

for each key in my_map.keys()
{
item_id = my_map.get(key);
dynamic_url = "https://api.example.com/data?id=" + item_id;

response = invokeurl
[
url : dynamic_url
type : GET
];

// Processing response...
}

My Question: What is the recommended architecture or workaround to handle this volume of API calls in Deluge?

Any guidance on best practices would be highly appreciated!

Thanks in advance.