Sorting

Sorting

Result set can be sorted on one or more attributes, ascending or descending. Sort order is specified per attribute. For instance, one may query deals added in specified quarter, ordered ascending by the date they were added, with highest value deals first for the same day.

Fetch deals

POST /v3/deals/search
Authorization: Bearer $ACCESS_TOKENContent-Type: application/json
{  "items": [    {      "data": {        "query": {          "projection": [            {              "name": "decimal_value"            },            {              "name": "name"            },            {              "name": "added_at"            }          ],          "filter": {            "filter": {              "attribute": {                "name": "added_at"              },              "parameter": {                "range": {                  "gte": "2016-10-01",                  "lt": "2017-01-01"                }              }            }          },          "sort": [            {              "attribute": {                "name": "added_at"              },              "order": "ascending"            },            {              "attribute": {                "name": "decimal_value"              },              "order": "descending"            }          ]        }      }    }  ]}
Content-Type: application/json; charset=UTF-8
{  "items": [    {      "successful": true,      "items": [        {          "data": {            "added_at": "2016-10-02",            "decimal_value": 17500,            "name": "A Deal",            "currency": "USD",            "id": 63425234,            "version": 5          },          "meta": {            "type": "deal"          }        },        {          "data": {            "added_at": "2016-11-24",            "decimal_value": 29000,            "name": "Other deal",            "currency": "USD",            "id": 543567,            "version": 5          },          "meta": {            "type": "deal"          }        },        {          "data": {            "added_at": "2016-11-24",            "decimal_value": 16000,            "name": "Other deal on the same day",            "currency": "USD",            "id": 867358,            "version": 5          },          "meta": {            "type": "deal"          }        },        {          "data": {            "added_at": "2016-12-05",            "decimal_value": 6500,            "name": "Yet another",            "currency": "USD",            "id": 8967345,            "version": 5          },          "meta": {            "type": "deal"          }        }
      ],      "meta": {        "count": 4,        "http_status": "200 OK",        "links": {},        "total_count": 4,        "type": "collection"      }    }  ]}