Pagination: reading long lists
A list route answers one page of rows at a time. You pick the page with
limit and offset, and the answer says how many rows there are in all.
Every list route works this way, except the few in
Lists that answer in one piece.
Ask for a page
Section titled “Ask for a page”limitis how many rows to return: 1 to 100. Without it you get 50.offsetis how many rows to skip first: 0 or more. Without it, 0.
curl -s "$HARDCOUNT/v1/plans?limit=100&offset=100" \ -H "Authorization: Bearer $HARDCOUNT_KEY"The answer holds plans 101 to 200, in this shape:
{ "data": [{ "id": "hc_pln_…", "…": "…" }], "total": 230}datais the page’s rows. An empty page is[], nevernull.totalcounts every row that matches your filters, not only this page.
Read everything
Section titled “Read everything”Add 100 to offset until offset reaches total:
offset=0while :; do page=$(curl -s "$HARDCOUNT/v1/plans?limit=100&offset=$offset" \ -H "Authorization: Bearer $HARDCOUNT_KEY") echo "$page" | jq -c '.data[]' offset=$((offset + 100)) [ "$offset" -lt "$(echo "$page" | jq .total)" ] || breakdoneA row added or removed while you read can shift the pages, so a row can be
skipped or read twice. Match rows by id if that matters.
Values Hardcount refuses
Section titled “Values Hardcount refuses”Hardcount never rounds a bad value to a valid one. Each of these is a 422
with param naming the parameter:
- a
limitbelow 1 or above 100; - a negative
offset; - a
limitoroffsetthat is not a whole number, or that is sent twice; after, like any query parameter a list does not take: there is no cursor. Page withoffset.
{ "error": { "type": "invalid_request_error", "code": "validation_error", "message": "limit must be a whole number from 1 to 100", "request_id": "req_…", "param": "limit" }}Lists that stop at a limit
Section titled “Lists that stop at a limit”- The audit log’s
totalstops at 10,001. A value above 10,000 means “more than 10,000”. - The customer list with
searchlooks at 5,000 customers at most. Its rows and itstotalstop there. A sort by name or email does the same, on a server that encrypts customer data (HARDCOUNT_).ENCRYPTION_ KEY - The invoice list’s
searchmatches a customer’s name or email among the 5,000 customers created last. An invoice of an older customer is still found by its invoice number.
Lists that answer in one piece
Section titled “Lists that answer in one piece”These routes answer a set of rows in one response. They have no total, and
they take no limit or offset: a request that sends one is refused with
422, param naming it:
GET /lists the 200 external customers whose held usage arrived last.v1/ usage-events/ held total_andcustomers total_count all of it. Release or discard held usage to see the rest.rows GET /andv1/ subscriptions/ {id}/ timeline GET /can leave rows out. They then answerv1/ invoices/ {id}/ payment-timeline truncated: true.GET /,v1/ webhook_ events/ {id}/ deliveries GET /,v1/ members GET /andv1/ credits/ balance/ {customer_ id} GET /answer every row.v1/ credits/ grants/ {customer_ id}
Stuck, or found a bug? Ask in Discussions · Open an issue