• Pages
  • /
  • Dealers
  • /
  • Data Depot
  • /
  • Version 4
  • /
  • API
  • /
  • Helpers
  • /
  • Sorting

Sorting

The sorting helpers allow you to control the arrangement of the response data in a prescribed sequence.

Arrange the API responses in the order that you wish to receive it by sending a sort parameter in your requests.

The parameter syntax structure is: ?sort[direction]=field.

Example requests

Sort by name ascending

Get a collection of Attributekeys sorted in alphabetical order by name.

https://api.wps-inc.com/attributekeys?sort[asc]=name

or

https://api.wps-inc.com/attributekeys?sort=name

Note that both these requests return the same result, sorted in the same way, because [asc] is the default behavior.

Sort by name descending

Get a collection of Attributekeys sorted in reverse-alphabetical order by name.

https://api.wps-inc.com/attributekeys?sort[desc]=name

Sort a primary collection based on it's relation field

Get a collection of Products that are sorted based on it's child Items list_price.

https://api.wps-inc.com/products?include=items&sort[desc]=items.list_price

Sorting includes

Include all the Items of a specific Product and sort those Items by list_price in descending order highest to lowest.

https://api.wps-inc.com/products/187138?include=items:sort(list_price)

As with primary collections, if the sort direction is left off, we'll assume you want asc order.

You can also explicitly pass a direction by adding a pipe character (|) between the field and the direction.

https://api.wps-inc.com/products/187138?include=items:sort(list_price|desc)