Ordering

When requesting multiple instances of a content type, you can use the sort parameter to define the order in which items are returned.

The sort parameter accepts a comma separated list of field names that the results should be sorted by.

Note

By default, fields specified in the sort parameter are sorted in ascending order. To sort a field in descending order, you can prefix the field name with the hyphen.

Sort Ascending

The following example retrieves books sorted by their rating field in ascending order:

GET /book?sort=rating
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?sort=rating \
     -H 'Content-Type: application/vnd.api+json'

Sort Descending

The following example retrieves books sorted by their rating field in descending order:

GET /book?sort=-rating
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?sort=-rating \
     -H 'Content-Type: application/vnd.api+json'

Sort Multiple Fields

The following example retrieves books sorted by their rating field in descending order, followed by their publishedDate field in ascending order.

GET /book?sort=-rating,publishedDate
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?sort=-rating,publishedDate \
     -H 'Content-Type: application/vnd.api+json'
Integrates with your favourite tools and frameworks

© 2022 Status200 Ltd.