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

ParameterTypeDefaultDescription
pageinteger1Page number to retrieve
page_sizeinteger20Number of results per page (max 100)

Response Fields

FieldTypeDescription
resultsarrayArray of objects for the current page
countintegerNumber of results in current page
pageintegerCurrent page number
page_sizeintegerResults per page
nextinteger|nullNext page number (null if last page)
previousinteger|nullPrevious 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 patients

Best 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