Pagination

Page through large result sets with the x-page-offset and x-page-limit headers

View as Markdown

Every GET endpoint in the Lemmy API is paginated. You control which slice of records you receive using two required request headers, and the response tells you whether more records are available.

Request headers

HeaderTypeDescription
x-page-offsetintegerThe record offset to start from, beginning at 0. To fetch the next page, increase it by x-page-limit — for example 0, then 50, then 100. The x-page-next response header gives you this value automatically.
x-page-limitintegerHow many records to return per page. The maximum is 50; you cannot retrieve more than 50 records in a single request.

Both headers are required on every GET request. If you omit them, the request returns an error. Always send x-page-offset and x-page-limit together.

Requesting a page

This requests the first 50 records, starting at offset 0:

$curl https://app.inmotionsoftware.be/Lemmy_API_IS/rest/v1/GetCustomers \
> -H "x-api-key: your-api-key" \
> -H "x-company-id: 1234" \
> -H "x-page-offset: 0" \
> -H "x-page-limit: 50"

Response headers

Each paginated response includes two headers that tell you whether to keep going:

HeaderDescription
x-page-moreA flag indicating whether more records are available beyond the page you just received.
x-page-nextThe x-page-offset value to send on your next request to fetch the following page.

To read an entire dataset, keep requesting pages — using x-page-next as your next x-page-offset — until x-page-more reports that there are no more records.

Reading every page

1import requests
2
3url = "https://app.inmotionsoftware.be/Lemmy_API_IS/rest/v1/GetCustomers"
4headers = {
5 "x-api-key": "your-api-key",
6 "x-company-id": "1234",
7 "x-page-limit": "50",
8}
9
10records = []
11offset = 0
12
13while True:
14 response = requests.get(url, headers={**headers, "x-page-offset": str(offset)})
15 response.raise_for_status()
16
17 records.extend(response.json()["Payload"])
18
19 # Stop when the API reports there are no more records.
20 if response.headers.get("x-page-more", "false").lower() != "true":
21 break
22
23 offset = int(response.headers["x-page-next"])
24
25print(f"Retrieved {len(records)} records")