Skip to navigation

Pagination

Every list endpoint on https://api.paid.ai/v1 returns one page at a time, newest first. Each page tells you whether another follows and gives you a cursor to fetch it, so you can read a list of any length with the same loop.

Use pagination to:

  • Read a whole list. Follow nextCursor until hasMore is false.
  • Control page size. Ask for up to 100 objects a page with limit.
  • Resume where you stopped. Keep the last nextCursor and send it later to continue from the same place.

How it works

  1. Call a list endpoint without a cursor. You get the newest objects first.
  2. If hasMore is true, send the page’s nextCursor as the cursor query parameter to get the next page.
  3. Repeat until hasMore is false. The last page’s nextCursor is null.

Objects are ordered by createdAt, newest first, with id breaking ties, so a page never repeats or skips an object that existed when you started. Objects created after your first request appear only on a new first page.

Query parameters

ParameterTypeDefaultDescription
limitinteger10How many objects to return, 1 to 100.
cursorstringnoneThe nextCursor of the previous page. Omit it for the first page.

A list endpoint can take its own filters too, such as a status. Send the same filters with every page: the cursor marks a position in the list, not the filters that made it.

The list object

Every paginated response has the same shape:

FieldTypeDescription
objectstringAlways list.
dataarrayThe objects on this page, newest first.
hasMorebooleanWhether another page follows this one.
nextCursorstring or nullSend it as cursor to get the next page. null on the last page.
{
"object": "list",
"data": [
{ "id": "cus_8HqL2xT", "object": "customer", "name": "Northwind Traders" },
{ "id": "cus_3Fw9KpR", "object": "customer", "name": "Halberd LLP" }
],
"hasMore": true,
"nextCursor": "eyJjIjoiMjAyNi0xMS0wMVQwOTowMDowMC4wMDBaIiwiaSI6ImN1c18zRnc5S3BSIn0"
}

Read every page

This loop reads a whole list with curl and jq. It works the same way for every list endpoint.

cursor=""
while :; do
page=$(curl -sG https://api.paid.ai/v1/customers \
-H "Authorization: Bearer $PAID_API_KEY" \
--data-urlencode "limit=100" \
${cursor:+--data-urlencode "cursor=$cursor"})
echo "$page" | jq -c '.data[]'
[ "$(echo "$page" | jq -r '.hasMore')" = "true" ] || break
cursor=$(echo "$page" | jq -r '.nextCursor')
done

Cursors

Treat a cursor as an opaque string: don’t build, parse or change one. Only send a cursor to the list that returned it, with the same filters. The API doesn’t check which list produced a cursor, so one from another list or with other filters can silently skip objects. A cursor that isn’t one the API produced returns a 400 invalid_request error with param set to cursor.

A few lists are short, fixed sets, such as the betas your account can use. They return every object in data with no hasMore, nextCursor or limit. The API Reference shows which lists those are.