Pagination
Lists come a page at a time, and you follow the cursor to get the next page.
On this page
Lists of records come in pages of 25. You can ask for up to 100 with limit. To get the next page, pass
meta.next_cursor as cursor, and keep going until it's null.
curl "$NIFTY_URL/api/v1/tags?limit=100" -H "Authorization: Bearer $NIFTY_TOKEN"
{
"data": [ … ],
"meta": { "limit": 100, "next_cursor": "eyJsIjoidDFyaEdhQTJZZ0ZNIiwiayI6WyJiaXJ0aGRheS1pZGVhcyJdfQ" }
}
| Parameter | |
|---|---|
limit |
Items per page: 1 to 100, default 25. More is treated as 100 |
cursor |
meta.next_cursor from the previous page |
count=true |
Adds meta.total_count: how many there are in all, with any filters |
- The
Linkheader holds the next page's full URL (rel="next"). The last page has noLinkheader, and itsnext_cursorisnull. - A cursor works only for the list that gave it, so keep the same filters and order. Otherwise, the request gets
400 invalid_parameter. - The order is stable. Records that tie, such as those with the same name or date, are ordered by
id.
Every page, in a script
base=$NIFTY_URL/api/v1
url="$base/tags?limit=100"
while [ -n "$url" ]; do
page=$(curl -fsS "$url" -H "Authorization: Bearer $NIFTY_TOKEN")
echo "$page" | jq -r '.data[].name'
cursor=$(echo "$page" | jq -r '.meta.next_cursor // empty | @uri')
url=${cursor:+$base/tags?limit=100&cursor=$cursor}
done