# Pagination

Some API endpoints will return paginated results. When results are paginated, the server will return 3 headers related to pagination:

* `X-Per-Page`: number of results return per page
* `X-Page`: Id of the current page
* `X-Total`: total number of results available
* `Link`: URLs helpers for navigation

### Using the Link Header

The `Link` header may contain up to 4 different URLs:

```
<https://api.tability.app/workspaces/:workspaceID/search/outcomes?page=1>; rel="first",
<https://api.tability.app/workspaces/:workspaceID/search/outcomes?page=12>; rel="last",
<https://api.tability.app/workspaces/:workspaceID/search/outcomes?page=6>; rel="next",
<https://api.tability.app/workspaces/:workspaceID/search/outcomes?page=4>; rel="prev"
```

* `rel="first"`: first page of the results
* `rel="last"`: last page of the results
* `rel="next"`: next page of results
* `rel="prev"`: previous page of results

To iterate on results, you simply need to parse the `Link` header to find the `rel="next"` link. If the link doesn't exist, then it means that there are no more pages to display.

### Example

Using JS

```typescript
import parse from 'parse-link-header';

const getNextPage = (response) => {
  if (response && response.headers && response.headers.link) {
    const links = response.headers.link;
    const parsed = parse(links);
    if (parsed && parsed.next) {
      return parsed.next.page;
    }
  }
  return null;
};
```


---

# Agent Instructions: 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:

```
GET https://guides.tability.io/api/tability-api/pagination.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
