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.
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.
eat 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 comm
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.
@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?
@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!
The duration to wait before the block times out. Default is
for the above, is it per iteration or the entire loop execution?
@Wildan_S_Nahar! The timeout should be for the whole block rather than individual loops