Sorting

Learn how to sort API responses by different fields and in different orders.

Overview

Most list endpoints support sorting via query parameters. You can specify which field to sort by and the sort direction (ascending or descending).

Query Parameters

sortBy

The field to sort results by. Available fields vary by endpoint.

sortOrder

Sort direction: asc (ascending) or desc (descending). Default: desc.

Example Requests

Sort by creation date (newest first)

bash
curl "https://pxb.app/api/public/v1/customers?sortBy=createdAt&sortOrder=desc" \
  -H "X-API-Key: your_api_key_here" \
  -H "X-Organization-ID: your_organization_id_here"

Sort by name (A-Z)

bash
curl "https://pxb.app/api/public/v1/customers?sortBy=lastName&sortOrder=asc" \
  -H "X-API-Key: your_api_key_here" \
  -H "X-Organization-ID: your_organization_id_here"

Combined with pagination

bash
curl "https://pxb.app/api/public/v1/customers?sortBy=createdAt&sortOrder=desc&limit=20&offset=0" \
  -H "X-API-Key: your_api_key_here" \
  -H "X-Organization-ID: your_organization_id_here"

Common Sortable Fields

While available fields vary by endpoint, most resources support these common fields:

FieldDescription
createdAtWhen the resource was created.
updatedAtWhen the resource was last modified.
nameResource name (alphabetical sorting).
statusResource status (active, archived, etc.).

Default Sorting

When no sort parameters are provided, most endpoints return results sorted by createdAt in descending order (newest first). Check individual endpoint documentation for specific defaults.

Notes

  • Sorting is case-insensitive for text fields.
  • Null values are sorted last in ascending order, first in descending order.
  • Invalid sort field names will return a 400 Bad Request error.
Copyright © Pixelbase Inc. - All rights reserved.