# Sort Results

This parameter allows you to specify the order in which objects of a particular type are retrieved.

<table><thead><tr><th width="535">Relative URL</th><th>HTTP Request Method</th></tr></thead><tbody><tr><td><code>/api/v4/</code><em><code>backend-deployment-id</code></em><code>/objects/</code><em><code>model</code></em><code>.json?sort[</code><em><code>field</code></em><code>]=</code><em><code>direction</code></em></td><td>GET</td></tr></tbody></table>

{% hint style="info" %}

* Replace *`model`* with the type of object that you wish to retrieve (as defined in your app's Data Model), for example `person`, `job` or `asset`.
* Replace *`field`* with the desired field name.
* Replace *`direction`* with a value defined below.
  {% endhint %}

### Parameters

Sort criteria are specified as a URL-encoded `sort` hash. Valid keys for this hash are the names of the fields in that model. Sort directions can be expressed in JavaScript style: `1` or `-1` - or human-readable: `asc`, `ASC`, `desc` or `DESC`

### Response

The response will contain a list of objects sorted by the specified field. The format of the objects is the same as for listing all objects (please refer to the [Retrieve all Objects](https://docs.journeyapps.com/reference/backend-api/api-reference/retrieve-all-objects) section).

### Examples

{% hint style="info" %}
**BASE-URL**

The below examples contain a `BASE-URL` placeholder. Please refer to the [HTTP Endpoints](https://docs.journeyapps.com/reference/introduction#http-endpoints) section to get the base URL relevant to your deployment.
{% endhint %}

#### Sort order - human readable:

{% tabs %}
{% tab title="HTTP" %}

```http
GET BASE-URL/api/v4/533bda53027894f69b001055/objects/tasks.json?sort[updated_at]=desc
```

{% endtab %}

{% tab title="curl" %}
{% hint style="info" %}
When using curl with queries you have to either escape the square brackets with a backslash `\` or add the `-g` option to turn off curl's globbing functionality.
{% endhint %}

```shell
curl "BASE-URL/api/v4/533bda53027894f69b001055/objects/tasks.json?sort[updated_at]=desc" \
    -g -u "533bda53027894f69b001055:7Ajj5htRY1uzw7b4w23V"
```

{% endtab %}

{% tab title="ruby" %}

```ruby
require 'rest-client'
journey = RestClient::Resource.new "BASE-URL/api/v4", "533bda53027894f69b001055", "7Ajj5htRY1uzw7b4w23V"
journey["533bda53027894f69b001055/objects/tasks.json"].get :params => {:sort=>{:updated_at=>"desc"}}
```

{% endtab %}
{% endtabs %}

#### Sort order - JavaScript style:

{% tabs %}
{% tab title="HTTP" %}

```http
GET BASE-URL/api/v4/533bda53027894f69b001055/objects/tasks.json?sort[updated_at]=-1
```

{% endtab %}

{% tab title="curl" %}

```shell
curl "BASE-URL/api/v4/533bda53027894f69b001055/objects/tasks.json?sort[updated_at]=-1" \
    -g -u "533bda53027894f69b001055:7Ajj5htRY1uzw7b4w23V"
```

{% endtab %}

{% tab title="ruby" %}

```ruby
require 'rest-client'
journey = RestClient::Resource.new "BASE-URL/api/v4", "533bda53027894f69b001055", "7Ajj5htRY1uzw7b4w23V"
journey["533bda53027894f69b001055/objects/tasks.json"].get :params => {:sort=>{:updated_at=>-1}}
```

{% endtab %}
{% endtabs %}
