Pagination
Endpoints that return lists (for example, the customers of your business) return them in pages. Lynked uses cursor pagination: instead of asking for "page 3", you ask for "the page after this point". The point is called a cursor.
Request#
Every list endpoint accepts two query parameters:
| Parameter | Type | Description |
|---|---|---|
limit | integer, 1–100, default 20 | How many items one page holds at most. |
cursor | string | Where the page starts. Omit it for the first page; for every next page, send the next_cursor of the previous response. |
Response#
Every list endpoint returns an object with the same two fields:
| Field | Type | Description |
|---|---|---|
items | array | The items of this page, in the order the endpoint describes (usually oldest first). |
next_cursor | string or null | The cursor of the next page. null means this is the last page. |
{
"items": [
{ "id": 101, "first_name": "Anna" },
{ "id": 102, "first_name": "Liam" }
],
"next_cursor": "eyJpZCI6MTAyfQ"
}
Reading every page#
- Request the first page without
cursor. - Process
items. - If
next_cursorisnull, stop. Otherwise request again withcursor=<next_cursor>and the same other parameters, and go back to step 2.
GET /api/public/v1/customers?limit=100 HTTP/1.1
Authorization: Bearer lk_live_...
GET /api/public/v1/customers?limit=100&cursor=eyJpZCI6MTAyfQ HTTP/1.1
Authorization: Bearer lk_live_...
let cursor = null;
do {
const url = new URL('https://api.lynked.ie/api/public/v1/customers');
url.searchParams.set('limit', '100');
if (cursor) url.searchParams.set('cursor', cursor);
const response = await fetch(url, { headers: { Authorization: `Bearer ${process.env.LYNKED_API_KEY}` } });
const page = await response.json();
for (const customer of page.items) {
// process the customer
}
cursor = page.next_cursor;
} while (cursor !== null);
A page can hold fewer than limit items even when more pages follow. Rely on next_cursor, not on
the number of items, to know whether you are done.