Hi, I’m building up an array of 50 records to POST, and then I want to move to the next 50 and so on until there are no more records. Can I use the Repeat block somehow?
Here’s what I’ve got so far .. just not sure how to fit in the Repeat
Hi @shazzaball
Are you trying to paginate an API to get the first 50, process them then move to the next 50?
Using a repeat may be possible or alternatively recursively calling the workflow once each 50 has finished, is it possible to see more of what’s happening in the flow so I can give you more specific advice?
Sure, here’s the flow in two parts, I think you helped me previously

I’m generating fake data and pushing into another API. Before I pushed in one invoice at a time, however to be more efficient, I now want to batch the invoices in batches of 50. So I changed the logic slightly to generate the JSON array, I’m just not quite sure of the best way to iterate thru 50 at a time. The Start parameters are contact qty and invoice qty, so someone can choose to create 100 contacts each with 5 invoices. Thank you !
Hi @shazzaball
There’s a couple ways to do it but the easiest way (assuming the number of customers x invoices is always divisible by 50) is using a repeat something like this:
so if 500 is the number of invoices x customer in my example , the first evaluate block divides by 50 to get 10 so it invokes the repeat 10 times that generates the set of 50 records (this is what your faker API + eval block are doing today) then the for<>collect logic are inside the module. The last collect in my flow is also not necessary since you’re making your API call right after your inner collect in the module.
I put the for<>collect + 50 record Xero API call inside the module so that the collect will run after each 50, otherwise it will collect your repeat blocks values and accumulate the whole 500.
Let me know if there’s anything I can help clarify.
Thanks @flows-daniel really helpful .. that did work really well
However .. the number may not always be divisible by 50, and may also be less than 50. In my head I want to loop a counter in an outer kind of loop .. pushing/posting the data when it gets to 50 records or until it reaches the end .. .
Hi @shazzaball
The easiest way to do that is have one branch that uses
Math.floor((invoices * customers) / 50))
that will give you the number of batches of 50 (which may be 0)
and then:
(invoices * customers) % 50
that should give you the remainder
Let me know if that works for you.