# Pagination

List of items returned by the API are paginated using cursor based pagination. Cursor-based pagination works by returning an alphanumeric pointer to a specific item in the list - for the Frill API this is the last item in the list.

Subsequent requests to the API can be passed this alphanumeric pointer to return the next set of results after the given pointer.

An API response that contains a list of items will contain a `pagination` object (see example below) containing information about the list of items, such as:- the `count` of items return, the `total` number of items and the `endCursor` which can be used to get the next set of results.

The cursor is returned in the `pagination.endCursor` field should be passed to the next request as an `after` parameter - eg:

`/api/ideas?after=END_CURSOR_FROM_PREVIOUS_REQUEST`

#### Pagination request params

| Name    | Description                                                 | Default |
| ------- | ----------------------------------------------------------- | ------- |
| `after` | Provide a cursor to get the results after the pointer/item  |         |
| `limit` | The number of items to return. Can't be be greater than 100 | 20      |

#### Pagination result fields

| Name          | Description                                                                                                               |
| ------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `total`       | Total number of available items                                                                                           |
| `count`       | Number of items in current response                                                                                       |
| `hasNextPage` | Is another page of items available                                                                                        |
| `startCursor` | Cursor for the start of the results                                                                                       |
| `endCursor`   | Cursor for the end of the results. Should be passed as the `after` param to subsequent request to get next set of results |

See example below

```json
{
  "data": [...],
  "pagination": {
    "total ": 20,
    "count ": 2,
    "hasNextPage ": true,
    "startCursor ": "CURSOR",
    "endCursor ": "CURSOR"
  },
}
```
