> This page is for version v2024-05-25 (default).
> For other versions, use one of these documentation indexes:
> - v2024-05-25 (default): https://docs.monite.com/v-2024-05-25/llms.txt
> - v2024-01-31: https://docs.monite.com/v2024-01-31/llms.txt
> - v2023-09-01: https://docs.monite.com/v2023-09-01/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.monite.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.monite.com/_mcp/server.

# Pagination, sorting, and filtering

You can control what and how data is returned from the Monite API by using the following techniques:

* [pagination](#pagination)
* [sorting](#sorting)
* [filtering](#filtering)

## Pagination

Pagination is a process of dividing the resulting set of data into discrete blocks of information (pages). It decreases both the server payload and the network traffic and increases the speed of page loading.

For example, in Monite you may have 1000 payables registered and want to receive them in groups of 1-100, where 100 is the maximum of documents that can be requested at a time.

### Page size (limit)

To avoid server and network overloading, the number of returned records in `GET` requests is restricted. In API requests the `limit` query parameter defines the number of records that the API consumer wants to receive in the response. Possible values are 1 to 100. Values outside of this range will result in the HTTP error 416 (Requested range not satisfiable).

## Sorting

When querying collections (for example,`GET /payables` or `GET /counterparts`), you can sort the results by using the `sort` and `order` query parameters.

The `sort` parameter specifies the data field by which the results should be sorted. The available sort fields vary depending on the endpoint. The default sort field is `created_at`. Endpoints without the `sort` parameter also return the results sorted by `created_at`.

The `order` can be `asc` (ascending) or `desc` (descending). Default is `asc`.

> **Info**
>
> If the response is paginated, all pages use the same sorting and filters as specified in the initial request. Sorting and filters cannot be modified for subsequent pages.

## Filtering

Very often API consumers may want to retrieve only selected records rather than all available sets of records. For example, a user is interested only in payables created 10 days ago or later. To achieve this, you can provide filters in the request query string.

Filters can be of two types:

* Exact match (case-sensitive):

  ```
  FIELD=VALUE
  ```

  For example, `name=Acme` or `price=1000`.

* Comparison filters:

  ```
  FIELD__OPERATOR=VALUE
  ```

  For example, `created_at__gte=2022-01-01T00%3A00%3A00` returns items created on or after January 1, 2022. See the list of operators below.

Multiple filters can be combined using `&` (logical AND).

> **Info**
>
> The supported filter fields and operators vary per endpoint. Refer to the endpoint reference for the exact supported filters.

### Filter operators

| Operator    | Applicable field types | Description                                                                                                                                                                                                                      | Example                              |
| ----------- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
| `iexact`    | string                 | Case-insensitive equals.                                                                                                                                                                                                         | `name__iexact=acme`                  |
| `contains`  | string                 | Contains the specified string (case sensitive).                                                                                                                                                                                  | `name__contains=Acme`                |
| `icontains` | string                 | Contains the specified string (case insensitive).                                                                                                                                                                                | `name__icontains=acme`               |
| `in`        | string                 | Represents the value in \[a, b, c] condition, that checks if the field value equals one of the specified values (case-sensitive). Each value requires a separate in filter, for example: `field__in=value1&field__in=value2&...` | `status__in=draft&status__in=issued` |
| `gte`       | number, date-time      | Greater than or equal to the specified value.                                                                                                                                                                                    | `price__gte=5000`                    |
| `gt`        | number, date-time      | Greater than the specified value.                                                                                                                                                                                                | `price__gt=5000`                     |
| `lte`       | number, date-time      | Less than or equal to the specified value.                                                                                                                                                                                       | `price__lte=5000`                    |
| `lt`        | number, date-time      | Less than the specified value.                                                                                                                                                                                                   | `price__lt=5000`                     |
| `isnull`    | any                    | `isnull=true` finds items where the specified field value is `null`.`isnull=false` finds items where the specified field value is *not* `null`.                                                                                  | `entity_user_id__isnull=false`       |

### Query examples

* No filters. Only the sorting and limit fields are specified:
  ```
  GET /products?limit=10&sort=name&order=desc
  ```

* Filtering by date and limiting the result set:
  ```
  GET /products?limit=2&created_at__gte=2021-10-05T00:00:00
  ```

* Filtering by two fields with the default pagination:
  ```
  GET /products?currency=EUR&price__lte=10
  ```

### Response example

If the data is selected based on the specified conditions, the response will look like this:

```json
{
    "data": [
      // array of records
      { ... },
      { ... },
      ...
    ],
    "prev_pagination_token": "bGltaXQ9MiZmaXJzdF9vaWQ9MSZwcmV2X3Rva2VuPTM=",
    "next_pagination_token": "bGltaXQ9MiZmaXJzdF9vaWQ9MSZuZXh0X3Rva2VuPTQ="
}
```

The `next_pagination_token` and `prev_pagination_token` values can passed in the `pagination_token` query parameter to receive the next or previous page in the result set.

## Error codes

When something goes wrong with pagination or filtering, one of the following HTTP response codes is returned:

* 406 Not Acceptable
* 416 Range Not Satisfiable