Skip to main content

Version: 24.10

Sort query results

Some APIs in Workspaces make use of an optional "sorts" attribute in the JSON Query object. If specified, the results returned will be ordered according to the string provided. By default, results are ordered by id.

APIs that do not have the "sorts" attribute are ordered by id.

Sort Strings

Sorting is defined by providing a list of sort strings in the format "ATTRIBUTE ORDER".

ItemDescription
attributeRequired. A supported sort criteria attribute.
The available sort criteria attributes are specific to each API, and documented for each API that supports sorting.
orderRequired. The order to return records, either ascending or descending.
Values: "asc", "desc".
"asc" is short for "ascending", while "desc" is short for descending.

Specify multiple "sorts" items to order results based on two or more attributes.

Examples

Single attribute sort

This example orders Txn records by submitKey (a supported attribute in the POST Txn Query) in ascending order.

Single attribute sort
{
"fetchLimit": 100,
...
"sorts": [
"submitKey asc"
]
}

The equivalent pseudo-query is:

Single attribute sort - Equivalent pseudo-query
SELECT * FROM
SUBMISSIONS S
ORDER BY S.submitKey ASC

Multiple attribute sort

This example illustrates Txn records ordered first by spaceName in ascending order then by clientCode in descending order.

Multiple attribute sort
{
"fetchLimit": 100,
...
"sorts": [
"spaceName asc",
"clientCode desc"
]
}

Records are returned, ordered by spaceName in alphabetical (asc) order. Records that have the same spaceName are orderd by clientCode in reverse alphabetical (desc) order. For example:

#clientCodespaceName
1client1Web-Plugin
2ZClientWorkspace
3testClientWorkspace
4client1Workspace

The equivalent pseudo-query is:

Multiple attribute sort - Equivalent pseudo-query
SELECT * FROM
SUBMISSIONS S
ORDER BY S.spaceName ASC, S.clientCode DESC