order_by
query parameter.
The Miru API uses field-based sorting. You can specify which field(s) to sort by and the sort direction (ascending or descending).
Resource IDs are used as a tie-breaker when multiple resources have equivalent fields to ensure deterministic sort results.
order_by
query parameter, which is optional.
<field_name>:<direction>
. The direction is optional and defaults to descending if not specified.
To illustrate, the following order by queries are all valid:
order_by=created_at
order_by=created_at:asc
order_by=created_at:desc
order_by
query parameter in the Query Parameters section of the list endpoint you want to sort.
Common sort fields include:
id
- Sort by object IDcreated_at
- Sort by creation timestampasc
- Ascending order (A-Z, a-z, 0-9, oldest first, etc.)desc
- Descending order (Z-A, z-a, 9-0, newest first, etc.)order_by
query parameter to the list endpoint URL.
The following request sorts config instances by descending creation date using the query parameter order_by=created_at:desc
.
order_by=created_at:asc
.
<field_name_1>:<direction_1>,<field_name_2>:<direction_2>,...
.
Let’s take the example of order_by=created_at:desc,id:asc
:
created_at
field in descending order (newest items appear first).created_at
timestamp, the API uses id
as a tie-breaker.id
in ascending order (lowest ID first).created_at
) in descending order. Since elements with IDs 2 and 3 have the same creation date, they are sorted by ID in ascending order.
The following request sorts devices by descending creation date and then by ascending ID:
created_at:desc
is converted to created_at:desc,id:asc
.
If a request already contains id
as a sort field, then the request is already deterministic and an additional id
sort field will not be added.
To illustrate this, the following table shows the original request ordering and the converted request ordering for a few different examples.
Original | Converted |
---|---|
created_at:desc | created_at:desc,id:asc |
created_at:desc,id:asc | created_at:desc,id:asc |
id:asc,created_at:desc | id:asc,created_at:desc |