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

# Pagination

> Learn how to paginate results for list and search endpoints

## How pagination works

The API has list and search endpoints that can return multiple objects, such as listing campaigns or searching for results. To mitigate negative impacts to performance, these endpoints don't return all results at once. Instead, the API returns one page of results per API call, with each page containing up to 10 results by default. Use the `limit` parameter to change the number of results per page.

For example, this is an API request to list campaigns results that uses role based evaluations, with a `limit` of 3:

<CodeGroup>
  ```bash cURL theme={null}
  curl -G https://api.external.hirednow.ai/v1/campaigns/role/results \
    -H "Authorization: Bearer <YOUR_API_KEY>" \
    -d campaign_id=320009f5-eb09-4a58-94a8-aad39e6ddd14 \
    -d limit=3
  ```
</CodeGroup>

The response from the API contains one page with 3 results:

<CodeGroup>
  ```bash Response theme={null}
  {
    "data": [
      {
        "id": "aa430250-883a-46be-98ce-a978847740a6",
        "campaign": {
          "id": "320009f5-eb09-4a58-94a8-aad39e6ddd14"
        }
        "user":{
          "id": "1c493040-b756-4aea-a043-54d9c2dd1857"
        }
        ...
        "order_index": 100
      },
      {
        "id": "0265ea37-d286-4395-b9d0-f0d21b9ad634",
        "campaign": {
          "id": "320009f5-eb09-4a58-94a8-aad39e6ddd14"
        }
        "user":{
          "id": "3e19b1dc-d32d-49e2-82c6-260fb81996c3"
        }
        ...
        "order_index": 101
      },
      {
        "id": "9c0a3ed8-44ee-47f1-a497-c1ccd2893711",
        "campaign": {
          "id": "320009f5-eb09-4a58-94a8-aad39e6ddd14"
        }
        "user":{
          "id": "0d1fea0f-6415-42f2-a92d-bdb82b0fe4fd"
        }
        ...
        "order_index": 105
      }
    ],
    "has_more": true,
    "last_record_id": 105
  }
  ```
</CodeGroup>

Keep in mind the following details when using these endpoints:

* Objects are inside the `data` property.
* Objects are sorted by `created_at` in descending order (newest first) by default.
* The `has_more` property indicates if there are additional objects that weren't returned in this request.

### Follow these steps to paginate results

1. Make an API call to list the objects that you want to find.

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.external.hirednow.ai/v1/campaigns/role/results \
    -H "Authorization: Bearer <YOUR_API_KEY>"\
    -d campaign_id=320009f5-eb09-4a58-94a8-aad39e6ddd14
  ```
</CodeGroup>

2. In the response, check the value of `has_more`:
   * If the value is `false`, you've retrieved all the objects.
   * If the value is `true`, get the ID from `last_record_id`, and make a new API call with the `starting_after` parameter set to that ID.

Repeat this step until you've retrieved all of the objects that you want to find.

<CodeGroup>
  ```bash cURL theme={null}
  curl -G https://api.external.hirednow.ai/v1/campaigns \
    -H "Authorization: Bearer <YOUR_API_KEY>" \
    -d campaign_id=320009f5-eb09-4a58-94a8-aad39e6ddd14 \
    -d starting_after=105
  ```
</CodeGroup>

## Parameters

<ParamField query="limit" default="10" type="integer">
  A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
</ParamField>

<ParamField query="starting_after" type="string">
  A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 10 objects, ending with ID `105`, your subsequent call can include `starting_after=105` in order to fetch the next page of the list.
</ParamField>

## Response format

All paginated endpoints return responses in the following format:

<CodeGroup>
  ```bash Response theme={null}
  {
    "data": [...],
    "has_more": true,
    "last_record_id": 105
  }
  ```
</CodeGroup>

<ResponseField name="data" type="array">
  Array of objects for the current page
</ResponseField>

<ResponseField name="has_more" type="boolean">
  Whether there are more objects available after this page
</ResponseField>

<ResponseField name="last_record_id" type="string">
  ID of the last record in the current page. Use this as the `starting_after` parameter for the next page. `null` if there are no more pages.
</ResponseField>
