Pagination

Two operations answer pages: listBlocks (top-level blocks, up to 100 per page) and queryRows (database rows, up to 200). Cursors are opaque and signed, and a block walk stays correct while people edit the canvas.

How it works

Ask for the first page with an optional limit. Each page answers has_more and next_cursor; when more follow, it also carries a Link header with the next page's URL. Pass next_cursor back as cursor, unchanged, until has_more is false.

GET /api/v1/files/doc_1/blocks?limit=2

HTTP/1.1 200 OK
ETag: "c465d27bcd7e"
Link: </api/v1/files/doc_1/blocks?cursor=eyJmIjoiZG9jXzEi...&limit=2>; rel="next"

{"blocks": [...], "rev": "c465d27bcd7e", "has_more": true, "next_cursor": "eyJmIjoiZG9jXzEi..."}
OperationItemslimitDefault
GET /api/v1/files/{fileId}/blocksblocks1-100100
GET /api/v1/files/{fileId}/databases/{dbId}/rowsrows1-20050

Walk every page

Every block of a canvas
url="https://canvas.example.com/api/v1/files/doc_1/blocks?limit=100"
while [ -n "$url" ]; do
  page=$(curl -s "$url" -H "X-OpenCanvas-Host: acme" -H "X-OpenCanvas-Key: $OC_API_KEY")
  echo "$page" | jq -c '.blocks[]'
  cursor=$(echo "$page" | jq -r '.next_cursor // empty')
  url=${cursor:+"https://canvas.example.com/api/v1/files/doc_1/blocks?limit=100&cursor=$cursor"}
done

Cursors

  • Opaque and signed. Do not build or change them; a changed cursor answers 400 CURSOR_INVALID.
  • Bound to the request. A block cursor belongs to its file; a row cursor to its file, database, filter, sort and fields. Sending it with other values is CURSOR_INVALID.
  • Valid for an hour. After that, 410 CURSOR_EXPIRED: start again without one.
  • Stable under edits. A block cursor is a position after the last block you got (a Yjs relative position), not an index. A block inserted or deleted before it does not shift the next page, and if that last block is deleted, the next page starts at its successor. Every block that exists for the whole walk is returned exactly once.

Errors

StatusCodeWhen
400CURSOR_INVALIDNot a cursor this server signed for this file and query.
410CURSOR_EXPIREDOlder than an hour.
400BAD_INPUTfilter or sort is not a JSON array.

Last changed .