Sorting Result Data

Using the orderBy parameter

When you want to sort a list of returned data you would use the orderBy query parameter. Most REST API operations that return a list of data objects support sorting together with paging.

You can sort the list of returned data in either ascending or descending order by specifying the :asc or :desc qualifiers with the orderBy parameter. If the orderBy parameter is used but no order qualifier is specified then, by default, the returned data is sorted in ascending order.

For example, to call the GET method (used earlier in the paging example) to get the next 20 server requests but to sort them based on average response time, starting with the slowest ( descending order), use the averageResponseTime attribute:
/api/v1/requests?offset=60&limit=20&orderBy=averageResponseTime:desc
The orderBy parameter can take a comma-separated list of attributes. For example, to organize the above example based on application server name, appServerName, as well:
/api/v1/requests?offset=60&limit=20&orderBy=appServerName,averageResponseTime:desc
You can find the different attributes (and their data types) to use with the orderBy parameter by querying the /metadata resource (using the Get resource metadata operation with the OrderBy type parameter). For example, if you wanted to know what are the attributes that you can order by when retrieving browser pages, Get pages (which is the /pages resource), you can execute the following REST API query:
/api/v1/metadata/OrderBy/pages
This will list all the attributes which can then be used in the orderBy parameter of the Get pages operation. The result list will look something the following, listing each attribute and type:
{
  ...
  "items" : [ {
    "type" : "FLOAT",
    "name" : "averageResponseTime",
  }, {
    "type" : "LONG",
    "name" : "completedCount",
  }, {
    "type" : "LONG",
    "name" : "loadRate",
  }, {
    "type" : "STRING",
    "name" : "pageTitle",
  }, {
    "type" : "LONG",
    "name" : "maxResponseTime",
  }, {
    "type" : "LONG",
    "name" : "failureCount",
  }, {
    "type" : "LONG",
    "name" : "minResponseTime",
  }, {
    "type" : "STRING",
    "name" : "pageURL",
  }, {
    "type" : "LONG",
    "name" : "errorPercentage",
  } ],
  "links" : [ {
    "rel" : "self",
    "href" : "api/v1/metadata/OrderBy/pages"
  } ],
  ...
}