How to Use Loop Over Items Node in n8n | Batching, Conditional Logic

Learn How to Use Loop Over Items Node in n8n | Batching, Conditional Logic in this comprehensive n8n tutorial. Step-by-step guide with video, code examples, and expert tips from the n8n Zero to Hero course.

Table of Contents

Overview

This lesson is part of the n8n AI Automation - Zero to Hero course, Section: 3. Deep Dive Concepts.

Watch the video above for the full tutorial, or read the written guide below.

What is the Loop Over Items node in n8n, and when do you need it?

The Loop Over Items node splits a dataset into batches and iterates over each batch, repeating a sequence of steps until all items are processed. Use it when you need controlled batch processing of large datasets, when an API enforces rate limits (such as 100 emails per second), or when a step-by-step process requires a Wait node between iterations. Without it, n8n fires every request simultaneously and gives you no throttle control.

How to use the Loop Over Items node in a real workflow

The Loop Over Items node exposes two output branches: a loop branch and a done branch. Every node you want to repeat connects into the loop branch, starting with a placeholder called Replace Me. After the last step in the loop, you wire that node's output back into the Loop Over Items node itself, closing the cycle. When all items are exhausted, execution exits through the done branch, where you can trigger downstream steps or attach a Do Nothing node to signal a clean end.

In the transcript workflow, a Gmail Trigger downloads email attachments with the Download Attachments option enabled and Simplify turned off. A Filter node checks that $json.binary exists, dropping emails with no attachments. A Split Out node on $binary then explodes the single email item into five separate binary items, one per attachment. These five items feed into Loop Over Items, which processes them one at a time.

Inside the loop branch, an HTTP node posts each binary file to a temporary hosting service (tempfiles.org) and returns a public URL. A Notion node then creates a database page in the sales task board, setting the email subject as the page title, a status property of To Do, and an image block populated with that temporary URL. A Wait node set to two seconds follows, preventing rate-limit errors on the Notion API before the output loops back into Loop Over Items. A critical fix covered in the transcript: instead of hardcoding the binary field name as attachment_0 (which breaks on iteration two), use the expression Object.keys($binary).first() to dynamically resolve whichever key is present on each iteration.

Key Takeaways

  • The Loop Over Items node has two output branches: the loop branch (where repeated steps live) and the done branch (what runs after all items are processed).
  • Even a batch size of 1 warrants Loop Over Items when you need a Wait node between requests; n8n's default per-item execution gives you no throttle control and will hit rate limits.
  • The Split Out node on $binary is what converts a single multi-attachment email item into individual binary items that the loop can iterate over.
  • Dynamic binary field names require the expression Object.keys($binary).first() rather than hardcoded keys like attachment_0, which break on the second iteration.
  • Notion's API accepts images only by public URL, making a temporary upload step (via HTTP node to a hosting service) a required prerequisite before the Notion create-page call.

Next Steps

Continue your n8n journey with the full n8n AI Automation - Zero to Hero course.

Frequently Asked Questions

The Loop Over Items node is needed whenever you want to insert a Wait node between individual item executions to respect API rate limits. n8n's default per-item execution fires all requests simultaneously with no delay, which breaks workflows that hit limits like 100 emails per second. Loop Over Items gives you explicit control over pacing, even when your batch size is 1.

The loop branch contains every node you want to repeat for each batch. After the last loop-branch node, you wire its output back into Loop Over Items to continue iteration. The done branch only executes once, after all items are exhausted. You can attach downstream steps there or use a Do Nothing node to mark a clean workflow end.

Hardcoding the field name as `attachment_0` fails on the second iteration because n8n names subsequent binary files `attachment_1`, `attachment_2`, and so on. Fix it by switching the input data field name to an expression and using `Object.keys($binary).first()`, which dynamically resolves the correct key name on every iteration regardless of its index.

The Notion API's image block only accepts a publicly accessible URL, not a raw binary file. n8n does not expose a public URL for attachments it downloads locally. The workflow solves this by posting each binary file to tempfiles.org via an HTTP node first, receiving a public URL in the response, and then passing that URL to the Notion create-database-page call.

Dheeraj Sharma

Dheeraj Sharma

AI Systems Builder
Creator of the n8n Zero to Hero course (42 lessons, 31+ hours). I help solopreneurs build AI systems that grow revenue without growing workload.

Get the n8n Mastery Bundle

All workflows, cheat sheets, and premium resources from the entire course in one package.

Get Premium Resources