Pagination, sorting, and filtering

Learn how to optimize data you receive with GET API calls from Monite.

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

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.

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).

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

Filter operators

OperatorApplicable field typesDescriptionExample
iexactstringCase-insensitive equals.name__iexact=acme
containsstringContains the specified string (case sensitive).name__contains=Acme
icontainsstringContains the specified string (case insensitive).name__icontains=acme
instringRepresents 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
gtenumber, date-timeGreater than or equal to the specified value.price__gte=5000
gtnumber, date-timeGreater than the specified value.price__gt=5000
ltenumber, date-timeLess than or equal to the specified value.price__lte=5000
ltnumber, date-timeLess than the specified value.price__lt=5000
isnullanyisnull=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:

1{
2 "data": [
3 // array of records
4 { ... },
5 { ... },
6 ...
7 ],
8 "prev_pagination_token": "bGltaXQ9MiZmaXJzdF9vaWQ9MSZwcmV2X3Rva2VuPTM=",
9 "next_pagination_token": "bGltaXQ9MiZmaXJzdF9vaWQ9MSZuZXh0X3Rva2VuPTQ="
10}

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