Skip to main content

Pagination & sorting

Every list endpoint that goes through the shared query builder accepts the same parameters.

Offset pagination

ParamTypeDefaultNotes
pnumberPage number, 1-based.
nnumberPage 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.

ParamTypeNotes
cursorPaginationbooleanTurns cursor mode on.
cursorstringOpaque token from the previous response's nextCursor. Also implies cursor mode.
nnumberPage 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

ParamTypeDefaultNotes
sortBystringcreatedAt,name (createdAt on leads)Comma-separated field list.
sortOrderstringdescasc 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.

Leads and contacts keep denormalized snapshots of their relations, so you can sort by related data without a join. On leads:

sortBy valueSorts on
contact.namethe linked contact's name
contact.emailthe linked contact's email
contact.contactNumberthe linked contact's phone
productServices.nameattached product/service names
team.nameassigned team
teamMember.name / teamMember.emailassigned member
createdBy.name / createdBy.emailcreator
updatedBy.name / updatedBy.emaillast editor
importId / importId.file.namesource import file

Custom fields are sortable by their field id — see Custom fields.