Sorting

Sorting the data response.

Sorting

You can control the order of resource collections by using the sort query parameter.
Sorting allows API consumers to specify one or more fields to define how results should be ordered.


Sort Query Parameter

The sort parameter accepts one or more field names, separated by commas (,).

?sort=fieldName

Default Sort Order

  • The default sort order is ascending
  • To sort in descending order, prepend a minus sign (-) to the field name
?sort=-fieldName

Sortable Fields

  • Not all fields may be sortable
  • Refer to each endpoint’s parameter description to see which fields support sorting
  • Unsupported fields may be ignored or return a validation error

Example: Sort by a Single Field (Ascending)

curl -H 'Authorization: <Access-Token>' \
     --request GET 'https://api.timeero.app/api/public/users?sort=firstName'

Example: Sort by a Single Field (Descending)

curl -H 'Authorization: <Access-Token>' \
     --request GET 'https://api.timeero.app/api/public/users?sort=-firstName'

Sorting by Multiple Fields

You can sort by multiple fields by separating them with commas (,). Sorting is applied in the order the fields are provided.

curl -H 'Authorization: <Access-Token>' \
     --request GET 'https://api.timeero.app/api/public/users?sort=firstName,roleId'

Usage Guidelines

  • Always verify sortable fields in the endpoint documentation
  • Use descending sorting (-field) only when necessary
  • Combine sorting with pagination for large datasets