Pagination & sorting
Every list endpoint that goes through the shared query builder accepts the same parameters.
Offset pagination
| Param | Type | Default | Notes |
|---|---|---|---|
p | number | — | Page number, 1-based. |
n | number | — | Page size. Hard-capped at 100000. |
Both are required to paginate. Sending only one, or neither, returns the entire matching set — on a large company that is a very expensive request. Always send both.
curl "https://api.leadx.in/api/key/protected/lead?p=2&n=50" -H "apikey: $KEY"
Walk the pages until you have totalCount rows:
const all = [];
let p = 1;
const n = 200;
for (;;) {
const { data, totalCount } = await leadx(`/lead?p=${p}&n=${n}`);
all.push(...data);
if (all.length >= totalCount || data.length === 0) break;
p += 1;
}
:::warning Offset paging drifts under writes Records created while you page shift the offsets, so a row can be skipped or repeated. For a full export of an actively-used collection, use cursor pagination. :::
Cursor pagination
Pass cursorPagination=true to start, then follow nextCursor. Stable under concurrent writes, and cheaper on deep pages.
| Param | Type | Notes |
|---|---|---|
cursorPagination | boolean | Turns cursor mode on. |
cursor | string | Opaque token from the previous response's nextCursor. Also implies cursor mode. |
n | number | Page size. Still required. |
let cursor = null;
const out = [];
for (;;) {
const qs = new URLSearchParams({ n: "200", cursorPagination: "true" });
if (cursor) qs.set("cursor", cursor);
const body = await leadx(`/lead?${qs}`);
out.push(...body.data);
if (!body.nextCursor) break;
cursor = body.nextCursor;
}
nextCursor is null on the last page. The token is base64url-encoded JSON — treat it as opaque and pass it back unchanged.
Sorting
| Param | Type | Default | Notes |
|---|---|---|---|
sortBy | string | createdAt,name (createdAt on leads) | Comma-separated field list. |
sortOrder | string | desc | asc or desc; comma-separated to pair with sortBy. |
?sortBy=stage,createdAt&sortOrder=asc,desc
Sorts are applied left to right. _id is appended automatically as a final tiebreaker, which is what makes cursor pagination deterministic.
Sorting on related fields
Leads and contacts keep denormalized snapshots of their relations, so you can sort by related data without a join. On leads:
sortBy value | Sorts on |
|---|---|
contact.name | the linked contact's name |
contact.email | the linked contact's email |
contact.contactNumber | the linked contact's phone |
productServices.name | attached product/service names |
team.name | assigned team |
teamMember.name / teamMember.email | assigned member |
createdBy.name / createdBy.email | creator |
updatedBy.name / updatedBy.email | last editor |
importId / importId.file.name | source import file |
Custom fields are sortable by their field id — see Custom fields.