> For the complete documentation index, see [llms.txt](https://manual.firstresonance.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.firstresonance.io/api/pagination.md).

# Pagination

For any query that returns a list of results, we highly recommend using pagination. If pagination is not applied, it is much more likely that a network timeout error (in the form of a 502 error) will be returned. This occurs when an API call doesn't receive a response for 30 seconds. Pagination allows you to return a smaller data payload by returning a subset of the  results to avoid the timeout error. It subsequently gives you a way to query further results as needed.

We use a cursor pagination pattern for our GraphQL API. See more info on GraphQL pagination [here](https://graphql.org/learn/pagination/).

## Example

In this example, the parts query grabs the first five parts by utilizing the `first` parameter and fetch the `endCursor` in the `pageInfo` object as shown in the request as shown below.

```graphql
{
  parts(first: 5) {
    edges {
      node {
        id
      }
    }
    pageInfo {
      endCursor         #use this to grab the next set of parts
      hasNextPage       #are their more parts after the ones returned in this query?
      totalCount        #total number of parts
      count             #number of parts returned by this query
    }
  }
}
```

Example Response

```json
  "data": {
    "procedures": {
      "edges": [
        {
          "node": {
            "id": 20
          }
        },
        {
          "node": {
            "id": 22
          }
        },
        {
          "node": {
            "id": 24
          }
        },
        {
          "node": {
            "id": 26
          }
        },
        {
          "node": {
            "id": 28
          }
        }
      ],
      "pageInfo": {
        "endCursor": "YXJyYXljb25uZWN0aW9uOjE5",
        "hasNextPage": true,
        "totalCount": 1259,
        "count": 5
      }
    }
  }
}
```

In addition to `first`, ION queries have pagination parameters of `last`, `before`, and `after`.

In this next example, this parts query returns the next five 5 parts after the part identified by the `endCursor` from the previous query.  If all parts in ION were to be queried, this pattern can be used to fetch all parts in batches of 5. In addition, use the `hasNextPage` to determine if there are more results remaining after this query.

```graphql
{
  parts(first: 5, after: "YXJyYXljb25uZWN0aW9uOjE5") {
    edges {
      node {
        id
      }
    }
    pageInfo {
      endCursor         #use this to grab the next set of parts
      hasNextPage       #are their more parts after the ones returned in this query?
      totalCount        #total number of parts
      count             #number of parts returned by this query
    }
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://manual.firstresonance.io/api/pagination.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
