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.
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.
The following example retrieves books sorted by their rating field in ascending order:
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?sort=rating \
-H 'Content-Type: application/vnd.api+json'
The following example retrieves books sorted by their rating field in descending order:
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?sort=-rating \
-H 'Content-Type: application/vnd.api+json'
The following example retrieves books sorted by their rating field in descending order, followed by their publishedDate field in ascending order.
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?sort=-rating,publishedDate \
-H 'Content-Type: application/vnd.api+json'
© 2022 Status200 Ltd.