The FREE API Pagination Loop Blueprint Generator
1. API Configuration
2. Generated Node.js Loop
If you are building B2B automations, standard webhooks will only get you so far. When you query a CRM like HubSpot or a database like Notion, the API will only return a subset of your data (usually 50 to 100 records) to save server bandwidth.
To get the rest of your data, you must build a Pagination Loop. Use the generator above to select your API’s pagination type and instantly generate the bulletproof Do/While JavaScript logic needed to extract every single record without crashing your workflow.
The 3 Types of API Pagination (Which one are you using?)
Before you paste this code into your n8n Code Node or Make.com custom app, you must check your target API’s documentation to see how they structure their data.
1. Cursor-Based Pagination (The Modern Standard)
Used by Slack, Stripe, Notion, and most modern APIs. When you make a request, the API returns your records alongside a next_cursor (a random string of characters). To get the next page, you make the exact same request, but append ?cursor=[YOUR_STRING] to the URL.
- Why it’s best: It prevents data duplication if new records are added to the database while your loop is running.
2. Offset & Limit Pagination (The Legacy Standard)
Used by HubSpot, WordPress, and many SQL-backed APIs. You tell the API how many records to skip (offset) and how many to return (limit). If you want records 100 through 200, your URL parameters will be ?limit=100&offset=100.
- The danger: If a record is deleted while your loop is running, the offset shifts, and your automation will accidentally skip a record.
3. Page Number Pagination
The simplest, but least scalable format. You simply append ?page=1, then ?page=2. The loop terminates when the API returns an empty array.
Why Zapier’s Default Webhook Node Fails at Pagination
If you are using Zapier’s “Webhooks by Zapier” integration to GET data from an API, you have likely noticed a massive flaw: It cannot paginate.
Zapier will fire your request, grab the first 50 records, and stop. Zapier does not have a native “Loop until condition is met” feature. To bypass this, RevOps engineers must either:
- Write a custom “Code by Zapier” step (using the JavaScript generated above).
- Migrate the workflow to Make.com or n8n, which natively support iterative API polling.
Preventing Infinite Loops (And API Credit Drains)
When writing Do/While loops in automation platforms, a single typo can result in an infinite loop. If your logic never triggers the hasMore = false condition, your script will poll the API thousands of times a minute.
This results in two disasters:
- Massive Bills: You will burn through your monthly task allotment (and budget) in minutes.
- IP Bans: The target API will instantly permanently ban your server’s IP address for a DDoS attack.
Note: The code generated by our tool above includes explicit exit conditions based on array lengths and null cursors to guarantee the loop breaks properly.
Handling Rate Limits Inside a Pagination Loop
If you are extracting 10,000 records, you will likely hit an HTTP 429 Too Many Requests error halfway through your loop.
To prevent this, you must introduce a delay between your requests. In the Node.js snippet generated above, we include this critical line of code at the end of the loop:
await new Promise(r => setTimeout(r, 200));
This forces the script to pause for 200 milliseconds before asking for the next page, keeping your workflow safely under the standard 5-requests-per-second API limits enforced by most SaaS companies.
Struggling to sync massive datasets between your tools? Don’t let pagination errors ruin your data integrity. Download our library of pre-built, fail-proof data extraction blueprints for Make.com and n8n.