Ordering results
Sometimes, we also need to specify a particular order for sorting the results.
In short
You can order results by a specific value with the order[FIELD]=asc|desc...
parameter.
Basic sorting
Let's sort plants by year, in a ascending order:
https://trefle.io/api/v1/plants?token=YOUR_TREFLE_TOKEN&order[year]=asc
- Browser
- CURL
- NodeJS
Open your browser and navigate to
https://trefle.io/api/v1/plants?token=YOUR_TREFLE_TOKEN&order[year]=asc
And we got:
Multiple sorting
You can also add secondary sortings by chaining another order
parameter:
Let's sort plants by year, in a ascending order, then by scientific_name, in descending order:
Excluding null values
Sorting on a value that is possibly null will show the entries with null values first.
For example, if we want to get the tallest trees, we will have trees with null
maxmimum height first:
To avoid that, you can exclude null values (see Filtering):