Pagination
Endpoints that return lists, such as employees or leave requests, return them one page at a time.
Asking for a page
Two query parameters control paging:
| Parameter | Default | Meaning |
|---|---|---|
page | 1 | Which page to return, starting at 1. |
per_page | 20 | How many records per page. Each list states its maximum on its reference page (often 50). |
bash
curl "https://qhr-api.qdev.it/open/v1/employees?page=2&per_page=50" \
-H "Authorization: Bearer $QHR_TOKEN"
Reading the response
A list response has two keys: records with the items on this page, and pagination describing the whole list.
json
{
"records": [
{ "id": 1203, "full_name": "Sara Ahmed", "status": "active" }
],
"pagination": {
"current_page": 2,
"per_page": 50,
"total_entries": 137,
"pages": 3
}
}
| Field | Meaning |
|---|---|
current_page | The page you received. |
per_page | The page size actually used. |
total_entries | How many records match, across all pages. |
pages | How many pages there are. When current_page equals pages, you have reached the end. |
Asking for a page past the end returns an empty records array, not an error.
Fetching everything
Loop until you have read the last page:
js
async function fetchAll(path) {
const all = [];
for (let page = 1; ; page++) {
const res = await fetch(`https://qhr-api.qdev.it/open/v1${path}?page=${page}&per_page=50`, {
headers: { Authorization: `Bearer ${process.env.QHR_TOKEN}` },
});
if (!res.ok) throw new Error((await res.json()).code);
const { records, pagination } = await res.json();
all.push(...records);
if (page >= pagination.pages) return all;
}
}
const employees = await fetchAll("/employees");
python
import os, requests
def fetch_all(path):
headers = {"Authorization": f"Bearer {os.environ['QHR_TOKEN']}"}
page, records = 1, []
while True:
res = requests.get(f"https://qhr-api.qdev.it/open/v1{path}", headers=headers,
params={"page": page, "per_page": 50}, timeout=30)
res.raise_for_status()
body = res.json()
records += body["records"]
if page >= body["pagination"]["pages"]:
return records
page += 1
Tips
- Keep any filters (
q,statusand so on) the same on every page, or the pages won't line up. - Data can change while you page through it. If a record is added on page 1 while you are on page 3, one record may shift between pages. For exact snapshots, page quickly and de-duplicate by
id. - Use the largest
per_pagethe list allows for bulk reads; at 50 you need less than half the requests the default needs.