nucjag
April 8, 2025, 8:08pm
1
Hello! I need help with looping
Input: paginated data, each page has some JSON
Algorithm:
load next page (if has_more)
split
loop over all items on the page (Loop2, blue sticker)
increment offset
get next page (step 1)
I have setup flow, but issue is that:
it loops over Loop2 only once (see console logs)
Question: how to fix and why Loop2 runs only once
n8n 1.85.4 community edition
barn4k
April 9, 2025, 1:47pm
2
hello @nucjag
HTTP Requests node has build-in pagination option, which you can use to receive the whole data
The issue is that the Loop node depends on the $runIndex
property of the workflow, which is changed after the last Code node returns payload to the IF node.
The first outer iteration should go as intended, but the second one will break the Loop node, forcing it going directly to the done branch
nucjag
April 9, 2025, 4:27pm
3
barn4k:
pagination option
I have tried pagination, but with it enabled i have a result that ALL data from API comes in (way too much), than it is being splitted and processed…
But because of data size it does not work for me. So, i am trying to ‘paginate’ manually, processing each page after it loads.
barn4k:
$runIndex
is there a way to “reset” this $runIndex ? adding “set” node befor loop did not help…
Algorithm is pretty simpe:
if we have more data items, step2, else finish
load next 20 data items
split loaded item
process each item
continue to step 1
barn4k
April 11, 2025, 9:27pm
4
You can split the workflow into two parts.
Main WF:
Sub WF
Also, your sub WF will remove the execution data once the execution is finished, so it’s better to use the parent-sub workflows instead of the loop node.
1 Like
system
Closed
April 24, 2025, 5:48am
6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.