Pagination and change feed
Page through lists with cursors, and keep another system in step with the change feed.
Paging through lists
List operations return one page at a time. Most take limit and an opaque cursor, and return nextCursor: send it back as cursor for the next page, and stop when it is null. Treat cursors as opaque strings; their format can change. Some lists page by offset or return everything at once: Conventions → List responses names the style of every list. The example pages through List leads.
BASE="https://lms.iotindia.ai/v1/tenants/your-workspace"# First pagecurl -G "$BASE/lms/leads" \ --data-urlencode "limit=50" \ -H "Authorization: Bearer $LMS_API_KEY"# Next page: the same filters, plus the previous nextCursorcurl -G "$BASE/lms/leads" \ --data-urlencode "limit=50" \ --data-urlencode "cursor=eyJpZCI6IjBiNmM3YTUyIiwidCI6MTc5NjgxODQwMH0" \ -H "Authorization: Bearer $LMS_API_KEY"{ "nextCursor": "eyJpZCI6IjBiNmM3YTUyIiwidCI6MTc5NjgxODQwMH0", "totalCount": 128, "items": [ { "id": "0b6c7a52-4f0e-4c1a-9d43-3f2a7c1e9b10", "fullName": "Asha Verma", "city": "Pune", "stageCategory": "QUALIFIED", "…": "other lead fields" } ]}Keep the same filters while you page. Sorting is stable, so records do not repeat or go missing between pages of one pass, but records created during the pass may appear on a later page.
The change feed
GET /v1/integrations/events returns the same events webhooks deliver, in the order they were committed. Use it when you cannot receive inbound HTTPS, to catch up after downtime, or to reconcile alongside webhooks. It needs the events.read scope.
{ "nextCursor": "eyJzIjo0MjEsInQiOjE3OTY4MTg0MDAwMDB9", "hasMore": false, "data": [ { "id": "0f7e6d5c-4b3a-4291-8f7e-000000000003", "type": "lead.stage_changed", "version": 1, "timestamp": "2026-12-01T10:00:00.000Z", "workspace": "your-workspace", "data": { "previousStage": { "id": "8c7b6a59-4d3e-4f2a-9b1c-0d9e8f7a6b5c", "name": "New", "category": "new" }, "stage": { "id": "5d1f2e3a-9b8c-4d7e-a6f5-1c2b3a4d5e6f", "name": "Qualified", "category": "qualified" }, "changedAt": "2026-12-01T10:00:00.000Z", "lead": { "id": "0b6c7a52-4f0e-4c1a-9d43-3f2a7c1e9b10", "…": "full lead snapshot" } } } ]}Without a cursor the feed starts at the oldest retained event, or at since (an ISO time). Filter with types (comma-separated) and set limit up to 500.
After you process a page, save its nextCursor and send it on the next call. Every page returns one, even an empty page, and it always holds your place. hasMore: false means you have caught up: wait a little, then call again with the cursor you just saved.
Polling loop
A complete loop, as a template: the comment at the top lists the four functions you provide.
// Template: replace the four helpers with your own code.// loadCursor() the saved cursor, or undefined the first time// saveCursor(c) persist it, only after its page is processed// handleOnce(e) process an event, skipping ids you have seen// reconcile() re-read what you mirror with the list operationsimport { setTimeout as sleep } from "node:timers/promises";const headers = { Authorization: `Bearer ${process.env.LMS_API_KEY}` };const FEED = `${process.env.LMS_API}/v1/integrations/events`;let cursor = await loadCursor();let since; // set only while recovering from a 410while (true) { const url = new URL(FEED); if (cursor) url.searchParams.set("cursor", cursor); else if (since) url.searchParams.set("since", since); url.searchParams.set("limit", "200"); url.searchParams.set("types", "lead.created,lead.stage_changed"); const response = await fetch(url, { headers }); if (response.status === 410) { // Recovery, steps 1-2: note the time first, then re-read. since = new Date().toISOString(); cursor = undefined; await reconcile(); continue; // step 3: the next request reads from since } if (response.status === 429) { const wait = Number(response.headers.get("Retry-After") ?? 1); await sleep(wait * 1000); continue; } if (!response.ok) throw new Error(`Feed returned ${response.status}`); const page = await response.json(); // Events the re-read already applied arrive again: skip by id. for (const event of page.data) await handleOnce(event); cursor = page.nextCursor; // on every page, even an empty one await saveCursor(cursor); // step 4: the first safe checkpoint since = undefined; if (!page.hasMore) await sleep(10_000); // caught up: poll later}Retention and recovery
Events are kept for 30 days. A cursor older than that returns 410 CURSOR_EXPIRED rather than silently skipping events. The events in the gap are gone, so a copy you keep in step needs a re-read. The polling loop above follows these steps:
- Note the current time as
since, before you re-read anything, so a change made during the re-read is not missed. - Re-read the records you mirror with the list operations (for example List leads) and update your copy. Do not save a cursor yet.
- Call the feed with
sinceand process that first page like any other. Events the re-read already applied arrive again; de-duplication onidskips them. - Save that page's
nextCursor: it is the first safe checkpoint. Then keep polling with it as usual.