Skip to content
Visual explainer 3h to learn 5 steps

Loops, batches and pagination in n8n workflows

Process many items in batches with pagination and bounded waits, and prove every expected item was handled.

By Invicly Tech, , in n8n, AI Automation and Voice Agents. About 10 minutes to read.

Topic 5 of 43

In short

Most n8n nodes already loop for you, running once per item. When you need to take items in small groups, for example to be gentle on an API, you use Loop Over Items. To read an API that returns many pages, use the pagination option on the HTTP Request node, and add a wait if the service limits how fast you may call it.

Explained simply

Most n8n nodes already work through every item for you. If 20 requests arrive and you add an HTTP Request node, it makes 20 calls. You do not need to build a loop for that. Extra loops are only for special cases.

One special case is a batch: a small group of items. Services often limit how many calls you can make per second or per minute. The Loop Over Items node splits your list into batches of a size you choose, so you can handle a few at a time and pause between them.

Another case is pagination. Some APIs return a long list one page at a time and tell you where the next page is. The HTTP Request node can follow these links for you. Always set a limit so a mistake cannot loop forever.

The most important step is checking the result. After the run, count what came in, what succeeded, what failed and what was skipped. If these numbers add up, you can trust the run. If they do not, something was lost.

Press Play on a diagram to walk through it one step at a time.

CycleOne Loop Over Items cycle
  1. 1
    Take a batch

    For example 10 items

  2. 2
    Process the batch

    Call the API or transform

  3. 3
    Wait

    Pause to respect the rate limit

  4. 4
    Return to the loop

    Ask for the next batch

  5. Back to step 1
CompareWhich tool for which job
Built-in per-item run
  • Default for most nodes
  • No extra node needed
  • Good for light work
Loop Over Items
  • Fixed batch size
  • Has loop and done outputs
  • Lets you pause between batches
HTTP Pagination
  • Follows next pages of one API
  • Stops on a condition
  • Limits the page count
FlowPagination with a safety limit
  1. Step 1
    Request page 1

    Fixture returns 5 records

  2. Step 2
    Read next link

    Or increase the page number

  3. Step 3
    Check stop rule

    Empty page or page limit reached

  4. Step 4
    Collect all records

    Output is one item per record

In depth

When n8n already loops for you

n8n nodes run once for each item they receive. A Filter, Edit Fields, If or HTTP Request node all handle the whole list without any loop. Adding Loop Over Items around such nodes just makes the workflow harder to read.

Reach for a loop when you must control the pace or the group size, when each step depends on the one before, or when an API takes only a limited number of records per call. If none of that applies, leave it out.

  • Normal nodes handle every item
  • Loop Over Items is for pace and group size
  • Do not add loops by habit

Loop Over Items in practice

Set a batch size, for example 10. The node has two outputs. The loop output sends one batch at a time into the nodes you connect. When those nodes finish, you connect the last one back to the input of Loop Over Items so the next batch starts. When there are no batches left, the done output runs once with the combined results.

The most common mistake is forgetting to connect the end of the chain back to the loop node. Then only the first batch is processed and the done output never fires.

SequenceThree batches over 25 items
Loop Over Items
HTTP Request
Wait
  1. 1Batch 1: items 1 to 10
    Loop Over Items to HTTP Request: Batch 1: items 1 to 10
  2. 2Calls done
    HTTP Request to Wait: Calls done
  3. 3Pause ends, ask for next
    Wait to Loop Over Items: Pause ends, ask for next
  4. 4Batch 2: items 11 to 20
    Loop Over Items to HTTP Request: Batch 2: items 11 to 20
  5. 5Calls done
    HTTP Request to Wait: Calls done
  6. 6Pause ends, ask for next
    Wait to Loop Over Items: Pause ends, ask for next
  7. 7Batch 3: items 21 to 25
    Loop Over Items to HTTP Request: Batch 3: items 21 to 25

Paginating an HTTP API

Open the HTTP Request node options and add Pagination. You choose how the next request is built. Often the response contains a next URL, or you increase a page number. You also set a condition for when to stop, such as the response being empty, and a maximum number of requests.

Test pagination against a fixture with a known number of pages, for example 3 pages of 5 records, and confirm the output has 15 items. Then break it on purpose, for example by returning the same page forever, and check that your maximum stops the loop.

  • Next URL or page number
  • A stop condition
  • A maximum number of requests
  • Test with a fixture of known size

Rate limits and bounded waits

A rate limit is a rule such as 60 requests per minute. If you go over, the service replies with an error, often status 429 Too Many Requests. Stay under it by processing small batches and waiting between them. The Wait node pauses for a time you set. The HTTP Request node also has a batching option with batch size and batch interval, which does the same job inside one node.

Bounded means the wait has a fixed, known length. Calculate it: 10 calls per batch and a limit of 60 per minute means at most 6 batches a minute, so wait at least 10 seconds.

Prove every item was handled

Add a counting step after the loop. Record how many items entered, how many succeeded, how many failed and how many were skipped on purpose. The four numbers should add up. When they do not, an item has been lost somewhere.

Also keep a list of the identifiers of the failed items, so you can retry exactly those and nothing else.

Learn it in 5 short steps

About 35m each. Track them with a timer in your plan.

  1. 1
    Know when n8n loops for you~35m
  2. 2
    Use Loop Over Items for batches~35m
  3. 3
    Paginate an HTTP API~35m
  4. 4
    Add waits to respect rate limits~35m
  5. 5
    Count input and output items~35m

Key points

  • Do not add a loop when a node can already handle every item itself.
  • Loop Over Items has a loop output that feeds the batch back and a done output that fires when all batches are finished.
  • HTTP Request pagination can follow a next URL or a page number. Always set a maximum number of pages.
  • A Wait node or the HTTP Request batching options (batch size and interval) keep you under a rate limit.
  • Prove completeness: the number of items in should equal handled plus failed plus skipped.

Key terms

Tap a card to flip it. 0/5 known

Examples

text
Loop Over Items
  Batch size: 10        -> 5 batches (10,10,10,10,5)
  loop output  -> HTTP Request -> Wait 2 seconds -> back to loop
  done output  -> Code: compare counts

Count check
  items in:   45
  succeeded:  43
  failed:      2
  total 45 = 45  ->  every item accounted for

A bounded batch run over 45 synthetic requests.

Send 45 requests in batches of 10

A limit allows 60 calls a minute. With batches of 10 and a 12 second wait, you make at most 50 calls a minute. Expect five batches: 10, 10, 10, 10 and 5. After the done output, a Code node compares counts and flags any gap.

javascript
// Code node on the done output (Run Once for All Items)
const total = $('Requests').all().length;
const done = $input.all().length;
return [{ json: { total, done, missing: total - done } }];

Paginate a fixture with three pages

The fixture returns 5 records per page with a next link, and the last page has none. Set pagination to use the next link and stop when it is empty, with a maximum of 10 requests. Expect 15 output items. Change the fixture to loop forever and confirm the run stops at 10 requests.

text
HTTP Request > Options > Pagination
  Mode: Response Contains Next URL
  Next URL: {{ $response.body.next }}
  Complete when: {{ $response.body.next }} is empty
  Max Requests: 10

Quick reference

  • Most nodes already run once per item. Do not add a loop by habit.
  • Loop Over Items: loop output feeds the batch, done output fires at the end.
  • Connect the end of the chain back to Loop Over Items.
  • HTTP Request pagination needs a stop rule and a max request count.
  • 429 means too many requests: slow down and retry later.
  • Wait time = batch size divided by allowed rate.
  • Always check in = succeeded + failed + skipped.

Common mistakes

  • Pagination with no stop condition or page limit, which can run forever on a buggy API.
  • Forgetting to connect the loop back to Loop Over Items, so only the first batch runs.
  • Treating a green run as proof. A run can succeed while skipping items.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

120 items reach an HTTP Request node with no loop. How many calls does it make?

Question 2

2Only the first batch of a Loop Over Items run is processed. What is the usual mistake?

Question 3

3A service allows 60 calls a minute. Which plan stays safely inside it?

Question 4

4What guards against a paginated API that never ends?

Question 5

5After a run, input 45, succeeded 43, failed 1, skipped 0. What does this tell you?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Create 25 synthetic items and split them into batches of 10 with Loop Over Items. How many batches run?

  2. Exercise 2medium

    Add a 5 second Wait inside the loop and compute the total waiting time for 25 items.

  3. Exercise 3hard

    Paginate a fixture with 3 pages of 5 records, add a maximum of 10 requests, and add a count check that fails the run if the total is not 15.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Is Loop Over Items the same as Split in Batches?
Yes. It was formerly called Split in Batches, and older docs and exports may still use that name.
What does a 429 status mean?
The service says you sent too many requests. Slow down, wait and try again.
Do I need a loop to process every item?
No. Most nodes already run once per item. Use a loop only to control batch size or pace.
How do I retry only the failed items?
Keep their identifiers in the count step and feed just those back in on a second run.

Go deeper

ShareXLinkedInWhatsApp