> ## Documentation Index
> Fetch the complete documentation index at: https://docs.morphic.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Pagination

> Navigate through large datasets with page-based pagination.

All list endpoints return paginated results. Use the `page` and `page_size` query parameters to control which page of results you receive.

## Parameters

| Parameter   | Type    | Default | Description                        |
| ----------- | ------- | ------- | ---------------------------------- |
| `page`      | integer | `1`     | Page number (1-indexed)            |
| `page_size` | integer | `25`    | Number of items per page (max 100) |

## Response shape

Every paginated response includes these fields:

```json theme={null}
{
  "items": [],
  "total": 142,
  "page": 1,
  "page_size": 25,
  "total_pages": 6
}
```

| Field         | Type    | Description                      |
| ------------- | ------- | -------------------------------- |
| `items`       | array   | The records for the current page |
| `total`       | integer | Total number of matching records |
| `page`        | integer | Current page number              |
| `page_size`   | integer | Items per page                   |
| `total_pages` | integer | Total number of pages            |

## Iterating through all pages

<CodeGroup>
  ```python Python theme={null}
  import requests

  headers = {"X-API-Key": "sk_your_api_key_here"}
  page = 1
  all_contacts = []

  while True:
      response = requests.get(
          "https://api.morphic.io/api/contacts",
          headers=headers,
          params={"page": page, "page_size": 100},
      )
      data = response.json()
      all_contacts.extend(data["items"])

      if page >= data["total_pages"]:
          break
      page += 1

  print(f"Fetched {len(all_contacts)} contacts")
  ```

  ```javascript JavaScript theme={null}
  const headers = { "X-API-Key": "sk_your_api_key_here" };
  const allContacts = [];
  let page = 1;

  while (true) {
    const res = await fetch(
      `https://api.morphic.io/api/contacts?page=${page}&page_size=100`,
      { headers }
    );
    const data = await res.json();
    allContacts.push(...data.items);

    if (page >= data.total_pages) break;
    page++;
  }

  console.log(`Fetched ${allContacts.length} contacts`);
  ```
</CodeGroup>

## Tips

* Use `page_size=100` for bulk fetching to minimize the number of requests
* The default `page_size` is 25 if not specified
* An empty `items` array with `total: 0` means no records match your query
