Describe the problem/error/question
I have a pagination loop built using HTTP Request → Code Node → IF Node → loop back to HTTP Request. The loop is working correctly — it fetches all pages using a pagination[last_id] cursor and loops back until there are no more pages.
The problem: When the loop finishes and exits via the FALSE branch of the IF node, only the last iteration’s data is passed to the next node. I need ALL the data from EVERY iteration combined into a single output.
I tried:
-
Accumulating data inside the Code node using
$('NodeName').all()— does not return previous loop iterations -
Using an Aggregate node after the IF node’s FALSE branch — only receives 1 item (the last loop output)
-
Storing accumulated data in a Set node and reading it back — the Set node value does not persist/update across loop iterations
-
Passing the full accumulated array through each loop iteration via the output JSON — the FALSE branch still only outputs the last iteration’s single item
The core issue: N8N’s IF node FALSE branch only outputs ONE item when a loop exits. There is no way to collect or aggregate data across multiple loop iterations into a single combined output.
Question: How do I properly accumulate and combine data from multiple iterations of a loop (HTTP → Code → IF → loop back) so that when the loop exits, I have ALL the data combined in one output?
What is the error message (if any)?
No error. The workflow runs successfully, but the FALSE branch of the IF node only passes through the data from the very last loop iteration, discarding all previously fetched pages.
Please share your workflow
Share the output returned by the last node
Output from “Accumulate Data” on each loop iteration (console logs):
Page 1: Retrieved 100 POs. Total: 100
➡️ Next cursor: 1109
---
Page 2: Retrieved 100 POs. Total: 100
➡️ Next cursor: 1209
---
Page 3: Retrieved 100 POs. Total: 100
➡️ Next cursor: 1309
...
Page 11: Retrieved 9 POs. Total: 9
🏁 No more pages
Output received on the FALSE branch (after loop exits):
{
"last_id": null,
"all_purchase_orders": [/* only 9 items - last page only */],
"page_count": 11,
"has_more": false
}
Expected output on the FALSE branch:
{
"last_id": null,
"all_purchase_orders": [/* ALL 1109 items combined from all 11 pages */],
"page_count": 11,
"has_more": false
}
Information on your n8n setup
-
n8n version: latest (cloud)
-
Database (default: SQLite): Cloud managed
-
n8n EXECUTIONS_PROCESS setting (default: own, main): default
-
Running n8n via: n8n cloud
-
Operating system: N/A (cloud)