Sorting

In this guide, we will look at how to work with sorted responses when querying the Previsto API. You can filter on most properties on the entities returned.

When an API response returns a list of objects, you can decide which properties to sort the data by.

Example using sort

In this example, we sort the result by name. As a result, we get the list of contacts sorted by name alphabetically.

  • Name
    sort
    Type
    string
    Description

    The property you want to sort by. By default it will be sorted ascending, but can be sorted descending by adding ,desc after the property name (fx. name,desc)

Manual sorting using cURL

curl -G https://api.previsto.io/contacts \
  -u sk_12345 \
  -d sort="name"

Sorted response

[   
  {
    "id": "cont-WAz8eIbvDR60rouK",
    "name": "Arnold"
    // ...
  },
  {
    "id": "cont-hSIhXBhNe8X1d8Et",
    "name": "Betty"
    // ...
  },
  {
    "id": "cont-fbwYwpi9C2ybt6Yb",
    "name": "Carl"
    // ...
  }
]