Sort Collections
Overview
Sorting is another feature that makes it easier to work with data-heavy resources.
URL Format for Collection Resource Parameters
You can sort items returned from a collection resource using the orderBy query parameter.
orderby
- Specifies a comma-separated list of pairs to order the response by.- You must sort the results using only unique attributes, such as
customerId
or_id
, to get predictable paging results. -
For example, to get to the first page of accounts, add the orderby string to the Get Accounts endpoint:
https://sitename.oracle.com/rest/v17/accounts?orderBy=customerId
Sorting Sequence
Use asc for ascending order and desc for descending order. The default sequencing order is asc. Items returned in the response payload are sorted in a case-sensitive order.
Sorting string examples
-
To sort items by
documentId
in descending order, append the following string to an applicable REST endpoint:?orderBy=documentId:desc
-
To sort items by
Deptno
in ascending order, append the following string to an applicable REST endpoint:?orderBy=Deptno:asc
Alternatively, you can simply append the following string, because asc is the default sorting order.
?orderBy=Deptno
-
If you include multiple fields in the query parameter, the order in which you specify the fields determines the sorting order.
For example, to sort items by
title
in ascending, and then sort bydateAdded
in descending order, append the following string to an applicable REST endpoint:?orderBy=title,dateAdded:desc