Source: https://docs.debitura.com/developer-concepts/filtering-and-sorting

# Filtering and Sorting

Debitura APIs support filtering and sorting on list endpoints.

<a id="sorting"></a>

## Sorting

Use the `Sort` parameter with syntax `field:direction`.

```http
GET /cases?Sort=date:desc
```

| Direction | Meaning |
| --- | --- |
| `asc` | Ascending (oldest first, A-Z) |
| `desc` | Descending (newest first, Z-A) |

**Sortable fields vary by endpoint.** Common fields include `Date`, `GrossAmount`, `Debtor`. On `GET /cases` in the Customer API and Collection Partner API, and on Referral Partner API transactions, a request naming an unsupported field is rejected with `400` and a `ValidationError` listing the supported fields. Results with equal sort values use a unique identifier as a tie-breaker. This keeps pagination consistent while the matching data is unchanged; changes between requests can still cause rows to repeat or be skipped.

Sorting is available on all three external APIs:

-   **Customer API**: Case endpoints (`Date`, `GrossAmount`, `Debtor`, and more)
-   **Collection Partner API**: Case endpoints (`Date`, `GrossAmount`, `Debtor`, and more)
-   **Referral Partner API**: `/clients` (`dateCreated`, `name`) and `/reporting/transactions` (`collectionDate`, `amount`)

<a id="array-parameters"></a>

## Array Parameters

Repeat the plain parameter key for each array value:

```http
GET /cases?Statuses=Active&Statuses=Paused
GET /cases?Ids=uuid1&Ids=uuid2
```

The indexed form (`Statuses[0]=Active&Statuses[1]=Paused`) also works.

See each API's reference documentation for available filter parameters.

<a id="combining-with-pagination"></a>

## Combining with Pagination

Filters work with [pagination](https://docs.debitura.com/developer-concepts/pagination.md) parameters. The `totalResults` reflects the filtered count.

```http
GET /cases?Statuses=Active&Sort=date:desc&Page=1&PageSize=50
```

<a id="need-additional-filters-or-sort-options"></a>

## Need Additional Filters or Sort Options?

Debitura can add new filters and sort options quickly. Contact [contact@debitura.com](mailto:contact@debitura.com) with your use case.
