Pagination
All list endpoints in the MediLoop API support pagination to help you efficiently retrieve large datasets.
Page-based Pagination
Most endpoints use page-based pagination with page and page_size parameters.
Request
bash
curl "https://api.mediloop.co/api/v1/uhid/?page=2&page_size=20" \
-H "Authorization: Bearer sk_test_..."RESPONSE200
{
"results": [
{
"uhid": "UG123456789A",
"first_name": "John",
"last_name": "Doe"
},
{
"uhid": "UG987654321B",
"first_name": "Jane",
"last_name": "Smith"
}
],
"count": 2,
"page": 2,
"page_size": 20,
"next": 3,
"previous": 1,
"source": "fhir"
}Pagination Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
page | integer | 1 | Page number to retrieve |
page_size | integer | 20 | Number of results per page (max 100) |
Response Fields
| Field | Type | Description |
|---|---|---|
results | array | Array of objects for the current page |
count | integer | Number of results in current page |
page | integer | Current page number |
page_size | integer | Results per page |
next | integer|null | Next page number (null if last page) |
previous | integer|null | Previous page number (null if first page) |
Iterating Through Pages
To retrieve all results, iterate through pages until next is null:
Python Example
python
import requests
def get_all_patients(api_key):
patients = []
page = 1
while True:
response = requests.get(
f"https://api.mediloop.co/api/v1/uhid/?page={page}&page_size=100",
headers={"Authorization": f"Bearer {api_key}"}
)
data = response.json()
patients.extend(data["results"])
if data["next"] is None:
break
page = data["next"]
return patientsBest Practices
- Use the maximum
page_size(100) to minimize API calls - Cache results when possible to reduce repeated requests
- Use filters to narrow results before paginating
- Handle rate limits gracefully when iterating through many pages