Sorting
Order list results with the sort query parameter and the -field descending convention.
Order a list with the sort query parameter. Name a field to sort ascending, or
prefix it with a hyphen (-) to sort descending.
GET https://api.flavours.sa/dev/api/v2/products?sort=-created_atAPI-TOKEN: <your-key>X-API-Version: 2.0.0Returns products newest first.
Syntax
| Value | Meaning |
|---|---|
sort=order | Sort by order, ascending. |
sort=-created_at | Sort by created_at, descending. |
- A leading hyphen (
-) selects descending order; no prefix means ascending. sorttakes a single field. Comma-separated multi-field sorting (sort=a,-b) is not supported.
Sort by one field at a time
Only one sort field is applied. A comma-separated value is treated as a single
(invalid) column name and is rejected with a 422.
Sortable fields
A field is sortable if it is a real column on the resource's table. An unknown or non-column value is rejected with a validation error:
{
"meta": {
"code": 422,
"status": "error",
"message": "The selected sort is invalid."
},
"data": [
{
"code": 0,
"message": "The selected sort is invalid.",
"field": "sort"
}
]
}Commonly available columns on most resources include created_at, updated_at,
order, and id. The exact list is the resource's own columns — check the
endpoint's page in the reference for the fields it exposes.
Stable ordering
Results are always finally ordered by id ascending as a tie-breaker, so items
that share your sort value keep a stable, repeatable order across pages. Some
resources also apply a fixed pre-sort (for example, products list active items
before inactive ones) before your sort is applied.
Combining with filtering and pagination
sort composes with filters and pagination:
GET https://api.flavours.sa/dev/api/v2/products?filter[is_active]=1&sort=-created_at&page=1&per_page=50API-TOKEN: <your-key>X-API-Version: 2.0.0