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):
For example,
name=Acme
orprice=1000
. -
Comparison filters:
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
Query examples
-
No filters. Only the sorting and limit fields are specified:
-
Filtering by date and limiting the result set:
-
Filtering by two fields with the default pagination:
Response example
If the data is selected based on the specified conditions, the response will look like this:
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