Skip to content

REST API

Pagination

Listings in the REST API return their records in pages. This article explains the two ways of paging, the headers that come with them, and how to tell that you have reached the end.

Mechanism Used by Parameters
By page every listing except one page, per_page, offset
By cursor GET /api/rest/v1/webhook_endpoints/{id}/deliveries limit, cursor

The delivery listing is the exception because sedisto reads it from the delivery provider on every call, and the provider returns a cursor rather than a count.

  • page is the page number, starting at 1.
  • per_page is the number of records per page, 10 by default and at most 100. A larger value is refused with 400.
  • offset skips that many records before the page begins. It defaults to 0.

Every response carries seven headers:

Header Meaning
X-Total records matching the query, across all pages
X-Total-Pages number of pages at this per_page
X-Per-Page records per page, as applied
X-Page the page in this response
X-Next-Page next page number, empty on the last page
X-Prev-Page previous page number, empty on the first page
X-Offset records skipped before this page

X-Next-Page and X-Prev-Page are present and empty at the ends, not absent. Read them as text and stop when X-Next-Page is empty. A client that parses them as numbers fails on the last page.

Nothing in the body says that a listing was cut short. Compare X-Total with the number of records you received. A page beyond the last one returns an empty array, not 404.

Terminal window
curl -i "$SEDISTO_HOST/api/rest/v1/units?page=2&per_page=100" \
-H "Authorization: Bearer $SEDISTO_TOKEN"

limit sets the number of records, 20 by default and between 1 and 100. Take the value of the X-Next-Cursor response header and send it back as cursor to get the next records. When there is nothing further, the header is absent. There is no total and no page number. A cursor does not expire; a malformed cursor is refused with 400.

at the end
X-Next-Page present and empty
X-Next-Cursor absent

Write the stop condition for each mechanism separately.

A listing narrowed with a _search filter can be incomplete however far you page. The X-Search-Truncated header says so. See Filtering, searching and sorting.