Pagination
ulex cursor pagination: the list envelope, starting_after and ending_before, limit bounds, order and ULID ordering, next_cursor semantics, filters versus pagination, SCIM's startIndex and count, and audit-log and export paging.
Every list endpoint in ulex uses opaque cursor pagination. There is no offset, and there will never be one.
#The list envelope
{
"object": "list",
"data": [],
"first_id": "usr_01M3PSV9GRT8GQGEG686AR1W9S",
"last_id": "usr_01M3PSWBPGS08FWV4NV7P9VNFN",
"has_more": true,
"next_cursor": "usr_01M3PSWBPGS08FWV4NV7P9VNFN"
}| Field | Type | Notes |
|---|---|---|
object | "list" | always literally list, so you can branch on it |
data | array | the page |
first_id | id | null | data[0].id, or null when the page is empty |
last_id | id | null | data[data.length - 1].id |
has_more | boolean | the only field you should branch on |
next_cursor | id | null | null exactly when has_more is false |
#Parameters
| Parameter | Type | Default | Bounds |
|---|---|---|---|
limit | integer | 20 | 1–200 |
starting_after | id | — | exclusive; return items after this id |
ending_before | id | — | exclusive; return items before this id |
order | asc | desc | asc |
starting_after and ending_before are mutually exclusive; sending both is 400 validation_failed with param: "starting_after".
page 1 GET /api/v1/users?limit=100
page 2 GET /api/v1/users?limit=100&starting_after=usr_01M3PSWBPGS08FWV4NV7P9VNFN
page 3 GET /api/v1/users?limit=100&starting_after=<next_cursor from page 2>
stop has_more == false#Rules
next_cursor is opaque. It happens to be a resource id today. Do not decode it, do not slice it, do not construct one, do not compare two of them. Pass it back verbatim as starting_after.
- Loop until
has_moreisfalse. Do not stop at the first page, do not assume 100 is everything. - The cursor belongs to the query that produced it. Change a filter and discard the cursor. Cursors are a hash of the filter set; a mismatched one is
400 validation_failedwithparam: "starting_after"rather than silently wrong results. - Do not use
offset. Items are inserted and deleted constantly; an offset skips or repeats. A cursor does not. order: "asc"is creation order. ulex ids are prefixed ULIDs, so lexicographic order is chronological.descis newest first.- Set
limitdeliberately. 200 is the maximum and is a good default for a bulk agent run. 20 is the default for interactive use. - Dedupe on
idanyway. Two concurrent runs can both see the same page.idis the join key.
#Idempotent, resumable drain
export async function drain<T extends { id: string }>(
fetchPage: (cursor?: string) => Promise<{ data: T[]; has_more: boolean; next_cursor: string | null }>,
handler: (item: T) => Promise<void>,
): Promise<{ processed: number; pages: number }> {
let cursor: string | undefined;
let processed = 0;
let pages = 0;
for (;;) {
const page: { data: T[]; has_more: boolean; next_cursor: string | null } =
await fetchPage(cursor);
pages++;
for (const item of page.data) {
await handler(item); // must be idempotent: a retry re-delivers page edges
processed++;
}
if (!page.has_more) break;
cursor = page.next_cursor ?? undefined;
}
return { processed, pages };
}
// Every list endpoint in ulex:
const users = await drain(
(cursor) =>
tools.ulex_list_users({ limit: 200, order: "asc", starting_after: cursor }),
(user) => syncUserToYourApp(user),
);#Filters and pagination are independent
Filters narrow the result set; the cursor pages within it. Both are applied server-side.
GET /api/v1/users?status=active&organization_id=org_01M3PSV8HGTKQFCAYF9GDWGN3C&limit=50&starting_after=usr_01M3PSWBPGS08FWV4NV7P9VNFN| Endpoint | Filters |
|---|---|
GET /organizations | connection_id, domain, search |
GET /users | email, external_id, organization_id, group_id, directory_id, status, search |
GET /users/{id}/memberships | — |
GET /organizations/{id}/members | role, group_id, search |
GET /organizations/{id}/groups | source |
GET /connections | organization_id, strategy, state, domain, search |
GET /directories | organization_id, provider, state |
GET /directories/{id}/users | status |
GET /directories/{id}/syncs | state, trigger |
GET /webhooks | status, event |
GET /webhooks/{id}/deliveries | status, event |
GET /audit-events | 17 filters, see Audit logs |
GET /deployments | application_id, environment, state, branch, commit_sha |
GET /applications | type, search |
A search filter is a prefix match, not a substring match. search=acme finds acme@…, acme.example, and acme-corp, but not contact@acme.example. There is no full-text index; that is a deliberate trade for cost at scale-to-zero.
#SCIM paginates differently
RFC 7644 uses offset paging, because that is what IdPs expect. /scim/v2/Users and /scim/v2/Groups:
| Parameter | Type | Default | Bounds |
|---|---|---|---|
startIndex | integer | 1 | 1-based |
count | integer | 20 | 1–200 |
sortBy | attribute | — | e.g. userName |
sortOrder | ascending | descending | ascending |
{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:ListResponse"],
"totalResults": 412,
"itemsPerPage": 50,
"startIndex": 51,
"Resources": []
}An empty Resources array with itemsPerPage: 0 means you have reached the end. totalResults is the count matching the filter, not the page size.
#Audit-log export is paged too
GET /audit-events/export does not take a cursor. Bound it by window and filter instead, and split a large window:
# 7 days at a time
curl -sS -G "$BASE/audit-events/export" -H "Authorization: Bearer $ULEX_API_KEY" \
--data-urlencode 'format=ndjson' \
--data-urlencode 'since=2026-09-01T00:00:00.000Z' \
--data-urlencode 'until=2026-09-08T00:00:00.000Z' \
-o audit-week-36.ndjsonExports above 100,000 events are 413. Above 10,000 in format: json they are truncated silently — use ndjson for anything you intend to verify a chain over.
#Limits and costs
| Aspect | Value |
|---|---|
Maximum limit | 200 |
Default limit | 20 |
GET /users and GET /organizations hard cap | 10,000 rows, then has_more: false and a truncated view |
| Cursor validity | 1 hour, then 400 validation_failed |
| Page consistency | not snapshot-isolated. Concurrent writes are visible between pages |
That last row is the one to internalise: if you need a consistent snapshot, filter by since/until on a timestamp (audit events) or take a checkpoint yourself. For user and organization lists, a slightly stale view across pages is the correct trade.
Deeper: Rate limits, Idempotency, Errors.