Mammoth API pagination
Most list endpoints page with limit and offset. Two use a cursor. Assuming otherwise gives you a loop that never advances.
Which endpoints page, and how
| Parameter | Operations carrying it |
|---|---|
limit | 37 |
offset | 34 |
cursor | 2 |
Not every endpoint pages at all. Those that do overwhelmingly use limit and offset, with a total in the body so you know when to stop.
Offset pagination
LIMIT=100
OFFSET=0
while : ; do
BODY=$(curl -sS "https://app.mammoth.io/api/v2/workspaces/$WS/projects/$P/datasets?limit=$LIMIT&offset=$OFFSET" \
-H "Authorization: Bearer $MAMMOTH_API_TOKEN")
TOTAL=$(echo "$BODY" | jq -r '.total')
echo "$BODY" | jq -c '.datasets[]?'
OFFSET=$((OFFSET + LIMIT))
[ "$OFFSET" -ge "$TOTAL" ] && break
done
Through the SDK and the CLI this is handled for you in most cases. Going direct to HTTP, read total and advance offset by your limit until you have them all.
Paging through the CLI
mammoth view data get, mammoth view export list and mammoth view pipeline items page with offset and limit in --input. The offset is 0-based and counts the rows to skip: offset: 0 is the first page. The response reports the limit and offset it used in a paging block with next_command and previous_command, ready to run. Each is null when there is no such page.
mammoth view data get 1039 --project 180 --input '{"offset": 0, "limit": 50}'
Follow paging.next_command until it is null. A script that passed 1 for the first page must now pass 0.
The two cursor exceptions
Cursor pagination is the exception, not the rule. It appears on the Resources v2 surface only:
GET /workspaces/{workspace_id}/resources
GET /workspaces/{workspace_id}/projects/{project_id}/resources
These return a cursor to pass back on the next request. Do not write a cursor loop against anything else; the parameter is not there.
Next up
- Errors and exit codes—how failures are reported, and what is worth retrying.
- Command contract—every capability with its CLI, SDK and API forms.