In Workflow repeat a rest api query until all pages have been fetched

Hi,

I'm writing a workflow to fetch a number of pages from a REST api. I'm struggling to work out how I can repeat a query in a workflow incrementing the page number each time it repeats until all pages have been fetched. I don't seem to be able to create a loop back to repeat a query multiple times.

I'm sure there must be a simple solution to this as I'm sure it's a common use case. I would appreciate any pointers you might have on achieving this in workflows.

Kind Regards

Hey Simon,

Here is the document for loop in workflows.

Let me know if it helps!

I did look at loops but it only seemed to be for looping over results of a query, rather than repeating a query a number of times. I will take another look as I may have missed some feature of it.

If it helps, you could perhaps create JavaScript Code Block with the number of pages and loop through them to get all the information you need and proceed from that point onwards.

Unfortunately I don't know how many pages there are, I just need to keep triggering the REST query until it returns an empty result set.

So you could accomplish this with 1-2 workflows depending on the use case.

1st workflow would on cadence trigger the second workflow (if you want it to be happening automatically).

2nd workflow would be triggered by webhook and if results are found, actions would be performed and then it would trigger itself or wait the first workflow to trigger it.

So in my example test_table had 3 records, workflow went and each run dropped 1 record, when there are no records the loop behavior breaks.

Does this work for your case?

Hi, I have similar use case for this but quite confused with your last reply. Could you elaborate for please?

In my case, I need to perform multiple rest api i.e. GET base-url/:service-name where service-name is an array of strings from my previous block.

Hi @Wildan_S_Nahar Your use case sounds like it would work well with the loop block. Is it the same base url every time & then a dynamic service name?

hi hi @Tess, thanks for the swift response!

I guess I figured it out how to do it. I previously missed to configure the next action when iterate the loop.

Using the example and combine with the pre-configured resource to call rest api, it's now working. this loop is indeed super helpful!

question though:
The duration to wait before the block times out. Default is 10000 .

for the above, is it per iteration or the entire loop execution?

Hi @Wildan_S_Nahar! The timeout should be for the whole block rather than individual loops