# Sorting

Source: https://developers.swell.is/backend-api/querying/sorting

Use the `sort` parameter to sort results. The format consists of `<field> <direction>`. Direction is recognized as a case-insensitive word like `ascending` and `descending`, or as abbreviated `asc` and `desc`.

You can combine multiple sort fields in a single comma-separated string, with the first taking precedence in order. The sort value must be a string—array values are ignored.

By default, list results are sorted by `id desc` (newest first). Any direction word that doesn't start with `desc` is treated as ascending.

## Example request

**Example query using sort**

**cURL**

```bash
$ curl https://api.swell.store/products?sort=name+asc
  -u store-id:secret-key
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.get('/products', {
  sort: 'name asc', // or desc
});
```

**PHP**

```php
<?php $swell = new \\Swell\\Client('store-id', 'secret-key');

$swell->get('/products', [
  'sort' => 'name asc' // or desc
]);
```
