Sorting and Paging

List and Query endpoints that return a list of entities allow you to specify sorting and paging options in the request.

This articles gives a general overview of sorting and paging. The implementation changes depending on whether an endpoint is a GET or POST request. Check your API's documentation for specific details, including which fields are sortable.

Sorting

Most APIs default to sorting by createdDate in DESC (descending) order, although some APIs have a different default sort order. You can override the default sorting by specifying a new field and order.

Sort List endpoints

List endpoints are designed to be lightweight HTTP GET requests. For this reason, sorting is applied through the query parameters, typically with sort.fieldName and sort.order.

For example, to list contacts by last name in ascending order, append these query parameters to the request:

Copy
1
?sort.fieldName=info.name.last&sort.order=ASC

Your API's List endpoint may support sorting by multiple fields. This is done by adding a new &sort.fieldName and &sort.order parameter for each sort field:

Copy
1
?sort.fieldName=info.name.last&sort.order=ASC&sort.fieldName=createdDate&sort.order=ASC

Sort Query endpoints

Query endpoints offer more robust filtering capabilities. When working with a Query endpoint, sorting is specified in an array in the request body, typically query.sort. For each sort object, sorting is applied with the fieldName and order parameters.

For example, to list contacts by last name in ascending order, include this structure in the request body:

Copy
1
{
2
"query": {
3
"sort": [
4
{
5
"fieldName": "info.name.last",
6
"order": "ASC"
7
}
8
]
9
}
10
}

Paging

The standard Wix API pagination includes:

  • limit: amount of items per response (default is 0)

  • offset: number of items to skip

The following examples:

Copy
1
?limit=100&offset=20

and

Copy
1
"limit": 100,
2
"offset": 20

Should return items 21-120 in the results.

Was this helpful?
Yes
No