सामग्री पर जाएँ

लेसन 12 · APIs and Integrations

Pagination and Rate Limits

Fetch every page of an API with n8n pagination modes, pace requests with batching and waits, respect rate limits and design safe backoff for temporary failures.

APIs rarely hand you everything at once. A list of 5,000 customers may arrive in pages of 100. Services also limit how often you may call them. If you ignore either fact, your workflow silently processes only part of the data, or fails halfway through.

Common pagination styles

Style You send The reply tells you
Page number page=2 How many pages, or when empty
Offset and limit offset=200&limit=100 Total count, or short page
Cursor cursor=abc The next cursor
Next link Follow a URL The full next URL

Cursor pagination is usually more reliable than offsets when data changes while you read, because new records do not shift your position.

Pagination in the HTTP Request node

The HTTP Request node has a pagination option with modes:

  • Off: one request.
  • Update a Parameter in Each Request: for example, increase the page number or send the next cursor.
  • Response Contains Next URL: follow the address in the reply.

You can use $response (the last reply) and $pageCount (pages fetched so far) in expressions. An illustrative setup for a page-number API:

TEXT
Pagination mode : Update a Parameter in Each Request
Parameter       : query "page" = {{ $pageCount + 1 }}
Stop when       : {{ $response.body.items.length === 0 }}

Check which variables and stop rules your version offers, because options evolve. Always set a maximum number of requests so a bug cannot loop forever.

Python Stand-in: follow a cursor until it ends

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Rate limits

A provider may allow only so many requests per second or per day. Going over usually produces status 429, often with a header such as Retry-After that says how long to wait. According to the documentation, the HTTP Request node does not automatically honor Retry-After, so you plan for it yourself.

Ways to stay within limits:

  1. Batching in the HTTP Request node: process a number of items per batch and wait between batches.
  2. Loop Over Items plus Wait: handle a small batch, pause, repeat. See merge and loops.
  3. Ask for more per page where allowed, so you need fewer calls.
  4. Cache results that rarely change.
  5. Request only new data with a "changed since" filter if the API has one.

Retry with backoff

For temporary failures, wait longer after each attempt: 1 second, 2, 4, 8. This is exponential backoff. Adding a little randomness ("jitter") stops many clients from retrying at the same moment. n8n's built-in Retry On Fail node setting repeats a node a few times with a short fixed wait (the docs list at most five tries and 5,000 milliseconds between them). For long waits, design your own loop with the Wait node.

JS Stand-in: plan waits for a retry policy

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Only retry safe requests

Reading (GET) is normally safe to repeat. Creating (POST) is not: the first call might have succeeded even though you never got the reply. Many APIs support an idempotency key, a unique ID you send so that repeats do not create duplicates. Use it where available, or check whether the record exists before creating it.

Check completeness

After fetching, verify: compare the total with what the API reports, and log how many pages you read. A silently truncated list is one of the most common automation bugs.

Do not remove the maximum-requests limit "just to get everything". A bad stop rule could call an API thousands of times, exceeding your quota or running up charges.

Estimate before you run

Work out the cost of a job first. Suppose you need 12,000 records at 100 per page: that is 120 requests. If a provider allowed 60 requests per minute, the job would need at least two minutes even without errors. If your workflow also called a second API once per record, that would be 12,000 more calls, which is a very different problem. Look for a bulk endpoint before you loop. These numbers are examples; read your provider's real limits.

Plan for a failure in the middle of a long job. If page 80 fails, can you continue from there, or must you start again? Saving a cursor or the last processed ID lets you resume. Make the writes idempotent, so a repeated page does no harm.

Practice

Imagine an API that returns 25 records per page with a cursor, allows 30 requests per minute and has about 2,000 records. Work out the number of requests, which is 80, and the shortest time the limit allows, about 2 minutes 40 seconds. Decide on a batch size or pause that stays comfortably below the limit. Then write what should happen if request 50 returns 429, and what should happen if it returns 500 three times in a row. These are invented numbers for practice, but the same reasoning applies to a real provider.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Which pagination mode fits an API that returns the next page address?

    That mode follows the address in each reply.
  2. 2. Why set a maximum number of requests?

    A safety cap limits damage from a bad stop rule.
  3. 3. Why is retrying a POST risky?

    Use idempotency keys or check for the record first.

Summary

  • Know your API's pagination style and fetch every page safely.
  • Set a maximum number of requests and verify the totals.
  • Pace calls with batching, loops and waits.
  • Use backoff, and retry non-idempotent requests only with protection.

Next: If, Switch and Filter

आपकी प्रगति इसी ब्राउज़र में सेव होती है। खाते की ज़रूरत नहीं है।