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

# Paginate results from InfraAudit list endpoints

> InfraAudit list endpoints return paginated results. Learn how to use the page and pageSize query parameters and read the meta fields in each response.

All InfraAudit list endpoints return paginated results. Pagination is page-based using `page` and `pageSize` (or `per_page` on some endpoints) query parameters. This page covers the request parameters, the response shape, and a pattern for fetching all results programmatically.

## Request parameters

<ParamField query="page" type="integer" default="1">
  The page number to return, 1-indexed.
</ParamField>

<ParamField query="pageSize" type="integer" default="20">
  The number of items per page. Maximum is 100. Some endpoints use `per_page` as an alias.
</ParamField>

Example — request page 2 with 50 items per page:

```bash theme={null}
curl "https://api.infraaudit.dev/v1/resources?page=2&pageSize=50" \
  -H "Authorization: Bearer $TOKEN"
```

## Response format

Paginated responses wrap the result set in a `data` array and include a `pagination` or `meta` object:

```json theme={null}
{
  "data": [
    {
      "id": 21,
      "name": "web-server-21",
      "resource_type": "ec2_instance"
    }
  ],
  "pagination": {
    "page": 2,
    "pageSize": 50,
    "total": 234,
    "totalPages": 5
  }
}
```

<ResponseField name="data" type="array" required>
  The list of items for the requested page.
</ResponseField>

<ResponseField name="pagination.page" type="integer" required>
  The current page number.
</ResponseField>

<ResponseField name="pagination.pageSize" type="integer" required>
  The number of items returned on this page.
</ResponseField>

<ResponseField name="pagination.total" type="integer" required>
  The total number of items across all pages.
</ResponseField>

<ResponseField name="pagination.totalPages" type="integer" required>
  The total number of pages at the current `pageSize`.
</ResponseField>

<Note>
  Some endpoints return the pagination envelope under a `meta` key rather than `pagination`. The field names (`total`, `page`, `per_page`) are the same regardless of which key wraps them.
</Note>

## Fetch all results

To collect every item across all pages, loop until you reach the last page:

```bash theme={null}
page=1
all_items="[]"

while true; do
  response=$(curl -s "https://api.infraaudit.dev/v1/resources?page=$page&pageSize=100" \
    -H "Authorization: Bearer $TOKEN")

  items=$(echo "$response" | jq '.data')
  total_pages=$(echo "$response" | jq '.pagination.totalPages')

  all_items=$(echo "$all_items $items" | jq -s 'add')

  [ "$page" -ge "$total_pages" ] && break
  page=$((page + 1))
done

echo "Total items fetched: $(echo $all_items | jq 'length')"
```

<Tip>
  Use `pageSize=100` (the maximum) when fetching all results to minimise the number of requests.
</Tip>
