Sorting
You can use the order
attribute when retrieving a list of objects using the Read
(XML API) or read()
(SOAP API) command to sort the returned list by the specified property in ascending or descending order.
The order
attribute value must have one of the following format:
-
<property>,<direction>
where:-
<property>
is the name of the object property used to sort the objects. -
<direction>
is the sort direction which can be either of the following:-
asc
– ascending order (lowest values presented first). -
desc
– descending order (highest values presented first).
-
-
-
<property>
– An ascending sort order is used if the sort direction is not specified. -
You can specify an ascending sort order or descending sort order using a
+
sign (ascending) or-
sign (descending) before the attribute name. An ascending sort order is used if the sort order is not specified.Examples:
-
The Sorting feature supports single level sorting only. Entering a comma-separated list of attributes will return an error. A secondary sorting level by internal ID is applied by default. When reading a list of receipts sorted by date, for example, if two receipts have the same receipt date, the response lists the receipt with the lower internal ID (
id
) first. -
The Sorting feature supports standard indexed fields only. See Sortable fields.
-
Sorting by a hidden sortable field is allowed. The returned list of resources is sorted in the order specified even if the sortable field is hidden due to form permissions, form permission rules or other account configuration setting.
Examples:
-
If you set the
order
attribute tocreated,desc
, the response lists objects and sort them in descending order ofcreated
date (most recent first). -
If you set the
order
attribute toname,asc
, the response lists objects and sort them in ascending order ofname
. -
If you set the
order
attribute toname
, the response lists objects and sort them in ascending order ofname
.