API Data Changes During a Long n8n Workflow

Hey guys I have an n8n workflow that pulls thousands of records from an external API using pagination.
The problem is that the dataset can change while the workflow is running. New records may be inserted, and existing records can be updated or deleted between page requests.
For example:
GET /customers?page=1
GET /customers?page=2
GET /customers?page=3
…
With offset-based pagination, I’m worried that records could be skipped or processed twice when the dataset changes between requests.
Would you use cursor-based pagination instead?
How would you handle APIs that only support page + limit and don’t provide a cursor or snapshot token?

Describe the problem/error/question

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:

Hey @Catherine, while you wait for a response, here are some things that might help:

Suggested resources

Automatically matched to your question.

Docs:

Forum:

@achamm, @sbruner, @om-Juri - you’ve helped with similar issues before, can you take a look?

Automatically suggested by n8n’s community bot. It’s a pilot - please share feedback here.

Hello @Catherine I would prefer cursor-based pagination whenever the API supports it. Offset pagination can become unreliable when records are being inserted or deleted while you’re moving through the pages.

A cursor gives you a stable position:Request Page
Process Records
Get next_cursor
Request next page
Repeat

For example:

return [{
json: {
cursor: $json.next_cursor,
hasMore: Boolean($json.next_cursor)
}
}];

If the API only supports page and limit, I’d try to make the dataset deterministic by sorting on an immutable field such as id:GET /customers?limit=500&sort=id&order=asc

Even better, if the API supports filtering by ID, use keyset-style pagination:GET /customers?after_id=5000&limit=500

Also store the last processed ID/cursor in PostgreSQL so the workflow can resume without starting from page 1 after a failure.

Hi @Catherine sorting by ID won’t fix offset pagination when records are deleted. If page 1 returns IDs 1 and 2, then ID 1 gets deleted, page 2 can start at ID 4 and skip 3.

I’d prefer cursor/keyset pagination, but a cursor doesn’t automatically give you a snapshot of the data.

With only page + limit, you can’t guarantee a complete, consistent read while the source keeps changing. Fetch into a staging table before doing the slow processing, deduplicate using record ID and source version where available, then run reconciliation passes. That reduces the impact, but deduplication cannot recover records you never received. Don’t treat an absent record as proof it was deleted.

Which API is this? For strict consistency, we’d need to check whether it offers a snapshot/export or a change feed that includes deletions.

@Anshul_Namdev is correct: sorting by id on offset pagination does not prevent records from being skipped when intermediate rows are deleted.

Community Answer Critique

Emmas: Rightly advocates for cursor pagination, but is incorrect that sorting by id eliminates offset pagination drift during deletions.

Anshul_Namdev: Correctly notes that deletions shift offsets regardless of sorting, and properly recommends staging tables, deduplication, or bulk snapshots.

Native n8n Setup
Implement pagination natively inside the n8n HTTP Request node under Add Option > Pagination to avoid canvas loops:

Cursor-Based (Recommended):
Set Pagination Mode to Update a Parameter in Each Request (or Response Contains Next URL).

Pass $response.body.next_cursor as the query parameter, referencing HTTP Node Built-in Variables.

Stop when {{ !$response.body.next_cursor }}.
Offset-Based (page + limit):

Following the n8n Pagination Cookbook set Pagination Mode to Update a Parameter in Each Request.

Set parameter page to expression {{ $pageCount + 1 }}.

Complete when {{ $response.body.length < limit }}.

Stream rows to a database staging table using Upsert to neutralize offset duplicates.

If you want to configure this directly for Catherine’s API, please share:

The API documentation link or endpoint schema

The response JSON structure for the pagination fields

Whether you would like a ready-to-import n8n workflow JSON snippet

Hey @Catherine , short answer to both: yes, use a cursor if the API has one, and with only page + limit, go with the staging and reconciliation approach Anshul described.

One thing I’d add: pulling thousands of records like this is a long-running workflow, and at that point pagination is only half the problem. The other half is workflow state: keeping track of which batches have actually been saved and where a failed run can safely resume.

The order you save things in matters here. If the workflow updates the “last processed” checkpoint before the batch is saved and then crashes, that batch is lost and the next run skips it. If you save the batch first, the worst case is processing it twice, which is fine as long as your writes are upserts like Daniel mentioned. So save the batch first, then move the checkpoint.

If you end up running this on a schedule, also make sure a slow run can’t overlap with the next one, or both can write to the same checkpoint.