Orderby

Purpose

  • The $orderby parameter specifies the sorting of the returned results based on one or more properties.

Key Points

  • You can specify the sorting order (ascending or descending) of a resource property.
  • Sorting is supported only on properties of the root resource.
  • By default, the order is ASC by creation date.

Syntax of $orderby Expression

  • The expression follows the format:
[PROPERTY_NAME (asc)|desc]
  • Example
[cat_ref asc]

Supported Properties

  • The list of available properties for the Product resource can be found in the JSON schema returned by the /$metadata endpoints
  • Example: When making a request to /Products/$metadata, you will get a schema detailing all available properties like prod_title, prod_ref, etc.

How to Use $orderby in a Request

  • When constructing your API request, add the $orderby parameter to specify the fields you want to retrieve
http://api2.saleslayer.com/rest/Catalog/Products?$select=[prod_ref,cat_ref,prod_description]&$orderby=[prod_ref asc]

Response Format

  • When constructing your API request, add the $orderby parameter to specify how the results should be sorted. The response will include the results sorted according to the specified order.
{
    "value": [
        {
            "prod_ref": "Atrius",
            "cat_ref": "OMA",
            "prod_description": {
                "en": "Atrius"
            }
        },
        {
            "prod_ref": "Zatrius",
            "cat_ref": "OMA",
            "prod_description": {
                "en": "Zatrius"
            }
        }
    ],
    "@count": 2,
    "@readLink": "http://api2.saleslayer.com/rest/Catalog/Products?$select=[prod_ref,cat_ref,prod_description]&$orderby=[prod_ref asc]"
}