Working with the API

Pagination

Walk a long list with a cursor.

Lists answer {"data": [...], "has_more": ...}. A list that pages adds next_cursor. Ask for a page size with ?limit=:

curl "https://v3.ghala.io/v1/messages?limit=2" \
  -H "Authorization: Bearer $GHALA_KEY"
{
  "data": [{ "id": "ef8192ab-1882-4e84-a367-faea4cad8fb9", "status": "delivered" }, { "id": "e35ee6ec-232d-4eb3-873d-62865d48c975", "status": "sent" }],
  "next_cursor": "MjAyNi0xMS0yOFQxNzo1NDo1MS4zMTg5MDNafGUzNWVlNmVjLTIzMmQtNGViMy04NzNkLTYyODY1ZDQ4Yzk3NQ",
  "has_more": true
}

Pass next_cursor back as ?cursor= for the next page. When it is absent, has_more is false and there are no more pages.

  • Treat the cursor as opaque. It encodes a position, not a page number.
  • There is no total. Counting a large table on every page is the cost cursors exist to avoid.
  • A cursor that does not decode is 400 invalid_cursor. Start again without one.
  • GET /v1/messages takes limit up to 200, and 50 when you leave it out.