Lapozás

Lists that can grow long, such as spaces, folder contents, file versions, search results, conversations and the trash, come back one page at a time:

{
  "items": [{ "id": "…" }, { "id": "…" }],
  "next_cursor": "eyJrIjoiMDE5…"
}

Parameters

  • limit: how many items a page holds. Most lists take 1 to 100 and return 25 by default. A folder’s contents (listEntries) take 1 to 200 and return 100 by default. The API reference gives the range for each list.
  • cursor: where the page starts. Leave it out for the first page; for the next one, pass the next_cursor of the page before.

When a response has no next_cursor (or it is null), you have the last page. A page can hold fewer items than limit and still have a next_cursor.

Reading a whole list

cursor=""
while :; do
  page=$(curl -s "$IVY_API_URL/v1/organisations/$IVY_ORGANISATION_ID/spaces?limit=100${cursor:+&cursor=$cursor}" \
    -H "Authorization: Bearer $IVY_API_KEY")
  echo "$page" | jq -r '.items[].name'
  cursor=$(echo "$page" | jq -r '.next_cursor // empty')
  [ -z "$cursor" ] && break
done

Rules

  • A cursor is opaque: don’t build, change or store it for long. Use it with the same operation and the same other parameters (for example the same parent_id, sort and order for a folder’s contents) that produced it.
  • Items added or removed while you page can appear or be missed, as with any cursor. Read the list again if you need an exact snapshot.
  • A limit outside the allowed range, or a cursor Ivy can’t read, gets 422 with the code validation_failed. A limit that isn’t a number gets 400 with invalid_query.

Some short lists aren’t paged and come back whole, for example the agent models, a space’s agents, and a space’s code runs (the newest 50 from the last 90 days, or the newest 50 of one file with file_id).