Guides
Pagination
The Liveday API uses offset-based pagination with size and from parameters.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
size | integer | 100 | Number of results to return (max: 1000). The page must also fit in 6 MB; see Page size limit |
from | integer | 0 | Offset from the beginning of the result set |
Example
Fetch the first 10 results:
curl -G "https://api.liveday.se/analytics_search/api/transactions" \
-H "Authorization: Bearer sk_your_api_key" \
-d "size=10" \
-d "from=0"
Fetch the next 10:
curl -G "https://api.liveday.se/analytics_search/api/transactions" \
-H "Authorization: Bearer sk_your_api_key" \
-d "size=10" \
-d "from=10"
Response
The response includes total_count so you can calculate how many pages remain:
{
"data": {
"total_count": 342,
"orders": [...]
}
}
In this example with size=10, you'd have 35 pages total (Math.ceil(342 / 10)).
Sorting
Results can be sorted using the sort and order parameters:
| Sort field | Description |
|---|---|
date | Order creation date (default) |
price | Total price |
customer_name | Customer name alphabetically |
| Order | Description |
|---|---|
desc | Descending (default) |
asc | Ascending |
curl -G "https://api.liveday.se/analytics_search/api/transactions" \
-H "Authorization: Bearer sk_your_api_key" \
-d "sort=price" \
-d "order=asc" \
-d "size=25"
Page size limit
At most 1000 transactions, and at most 6 MB
A page holds at most 1000 transactions, and it must also fit in a 6 MB response. When the page you ask for wouldn't fit, the API answers 400 with a message naming a size=N that does. Ask again with that size, and move from on by the number of transactions each page returned.
Orders with many items can make a page of 1000 larger than a response can carry. Instead of a cut-short page, the API then answers 400 Bad Request, saying how many transactions the page had and which smaller size fits. The message counts the limit as 5.9 MB, since the rest of the 6 MB carries the response around the transactions:
{
"error": {
"message": "These 1000 transactions take 7.6 MB, more than the 5.9 MB a response can carry. Ask for fewer at a time: size=625 or less, moving from on by the number returned."
},
"trace_id": "abc123def456"
}
Fetch every page, asking again with the named size when one doesn't fit:
const orders = []
let from = 0
let size = 1000
while (true) {
const response = await fetch(
`https://api.liveday.se/analytics_search/api/transactions?size=${size}&from=${from}`,
{ headers: { Authorization: 'Bearer sk_your_api_key' } }
)
const body = await response.json()
const fits = response.status === 400 && body.error.message.match(/size=(\d+)/)
if (fits && Number(fits[1]) < size) {
size = Number(fits[1])
continue
}
if (!response.ok) throw new Error(body.error.message)
const page = body.data.orders
orders.push(...page)
from += page.length
if (page.length === 0 || from >= body.data.total_count) break
}
Move from on by the number of transactions returned, not by the size you asked for, so that no transactions are skipped when size changes between pages.