# Sorting

Apply sorting for list endpoints like [All Documents](/apis/rest-api/endpoints.md#all-documents) and [Document Collections](/apis/rest-api/endpoints.md#document-collections). Each sorting parameter refers to one field. It is possible to provide a single or multiple sorting parameters.

Possible values for the sorting parameter are:

| **Value**      | **Function**                        |
| -------------- | ----------------------------------- |
| `ASC` or `1`   | Returns the list ordered ascending  |
| `DESC` or `-1` | Returns the list ordered descending |

{% hint style="info" %}
Lists are ordered descending by default.
{% endhint %}

## Sorted query results

<mark style="color:blue;">`GET`</mark> `https://api.cmft.io/v1/<repoName>/<endpoint>?sorting[<fields|meta>.<fieldName>]=<direction>`

#### Path Parameters

| Name     | Type   | Description                                 |
| -------- | ------ | ------------------------------------------- |
| repoName | string | The API identifier of the repository        |
| endpoint | string | The endpoint you'd like to request          |
| sorting  | string | Provide the order direction `ASC` or `DESC` |

#### Headers

| Name          | Type   | Description        |
| ------------- | ------ | ------------------ |
| Authorization | string | Provide an API Key |

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

```javascript
// Response ordered ascending by title
"data": [
    {
      "fields": {
        "title": "Roses are red"
      },
      "meta": {
        "id": "314159265358979323",
        "contentType": "poem",
        "repository": "314159265358979323",
        "revision": 1,
        "tags": [],
        "createdAt": "2018-01-01T00:00:00.000Z",
        "updatedAt": "2018-01-01T00:00:00.000Z"
      }
    },
    {
      "fields": {
        "title": "Violets are blue"
      },
      "meta": {
        "id": "314159265358979323",
        "contentType": "poem",
        "repository": "314159265358979323",
        "revision": 1,
        "tags": [],
        "createdAt": "2018-01-01T00:00:00.000Z",
        "updatedAt": "2018-01-01T00:00:00.000Z"
      }
    }
]
```

{% endtab %}
{% endtabs %}

## Field Types

Sorting can be applied for the following field types:

* `Text`
* `Richtext`
* `Number`
* `Date & Time`
* `Boolean`
* `Location`
* `Select`
* `Color`

## Examples

Find some examples on the query examples page:

{% content-ref url="/pages/-LEUFxUpSqcfapg6AIxr" %}
[Sorting](/apis/rest-api/examples/sorting.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.comfortable.io/apis/rest-api/filters/sorting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
