Skip to main content

Sorting

Some list resources allow an ordering query parameter to sort the results. The default ordering for a provided field is ascending, a minus - sign before the field will return the results in descending order. Multiple fields can be accepted by separating with a comma ,.

These will be marked as orderable in the relevant resource section.

Sample request with ordering parameter

By adding the query parameter ordering=-description,is_generic_item, the below request would return the results in the following order:

  • description (descending)
  • is_generic_item (ascending)
curl --request GET \
--url 'https://myfood24.org/api/1.0/food_items?search=cornflakes&offset=0&limit=1&ordering=-description,is_generic_item' \
--header 'Authorization: Api-Key API-KEY' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json'