Last updated: Jun 08, 2026

Sorting

Sortinglink

Order API responses by specific fields using the sort parameter. This guide explains how to sort results in ascending or descending order.

Basic Sortinglink

Use the sort query parameter to order results:

# Sort by name (ascending)
curl "https://api.infraspeak.com/v3/locations?sort=name" \
  -H "Authorization: Bearer YOUR_TOKEN"

# Sort by name (descending)
curl "https://api.infraspeak.com/v3/locations?sort=name-" \
  -H "Authorization: Bearer YOUR_TOKEN"

Sort Directionlink

Syntax Direction Example
field Ascending (A-Z, 1-9, oldest-newest) sort=name
field- Descending (Z-A, 9-1, newest-oldest) sort=name-

Multiple Field Sortinglink

Sort by multiple fields using comma-separated values:

# Sort by priority (ascending), then by creation date (descending)
curl "https://api.infraspeak.com/v3/failures?sort=priority,created_at-" \
  -H "Authorization: Bearer YOUR_TOKEN"

The first field is the primary sort, subsequent fields break ties:

Priority 1: Creation Date Dec 15
Priority 1: Creation Date Dec 10
Priority 2: Creation Date Dec 20
Priority 2: Creation Date Dec 18

Default Sort Orderlink

When no sort parameter is provided, endpoints typically return results in one of these orders:

  • By ID/primary key (ascending) - most common
  • By creation date (descending)
  • By relevance

Due to this default sort behavior, there is no guaranteed sort order if no sort parameter is provided.

Performance Considerationslink

Use Indexed Fieldslink

Sorting on indexed fields is faster:

# Fast - sorting on indexed field
curl "https://api.infraspeak.com/v3/failures?sort=failure_id-" \
  -H "Authorization: Bearer YOUR_TOKEN"

# Slower - sorting on non-indexed field
curl "https://api.infraspeak.com/v3/failures?sort=description" \
  -H "Authorization: Bearer YOUR_TOKEN"

Limit Result Setslink

When sorting large datasets, combine with filters and pagination:

# Efficient - filter, sort, and limit
curl "https://api.infraspeak.com/v3/failures/open?s_priority=1&sort=created_at-&limit=10" \
  -H "Authorization: Bearer YOUR_TOKEN"