Waiting until a loop is finished before sending data to the Aggregate

Describe the problem/error/question

I’m fetching data from an API inside a loop in n8n. After each request, I’m merging the results using the Merge node. My goal is to wait until the entire loop finishes, then send the combined data to the Aggregate node.
However, right now, as soon as any data reaches the Merge node, it immediately continues to the Aggregate node — before the loop is fully complete.
How can I make sure the Aggregate node only receives data after all iterations of the loop are done?

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

The reason the Merge immediately goes to Aggregate is because the Aggregate follows the Merge node.
The Aggregate should follow the IF false output (that puts it outside the loop) and I think you want the Merge inside the loop (it’s currently outside the loop).

:thinking:

when i put aggregate to false output, it takes the last item of loop. but i wanna merge all items in one item. bc i send it to chatgpt next step.

Are you trying to accumulate input for chat over multiple loops?

If so, you’ll need to use an external place to store the data (like Google Sheets or Docs) for each loop then get it back once you are done gathering data. There is no global variable you can add to.

Please show your workflow. It will help anyone looking at this understand exactly what you are trying to do.

  • Select your entire workflow and copy it.
  • Click on </> at the top of the Reply Edit window.
  • Paste the workflow within the delimiters.

:slightly_smiling_face:

Why not to use pagination?

I faced same problem, temp table or google sheet may take care of it, can n8n have another way?

Use the loop node for this.

NIce, there always multiple way to achieve the same thing, good to know :slight_smile: