Skip to main content

Overview

The MTB Backend API uses Strapi’s powerful query syntax to filter, sort, and select specific fields from your data. These capabilities allow you to retrieve precisely the data you need.

Basic Filtering

Filter results using query parameters with the filters object:
curl "https://api.example.com/api/articles?filters[title][$eq]=Hello"

Filter Operators

Strapi provides a comprehensive set of operators for filtering:

Equality Operators

OperatorDescriptionExample
$eqEqual tofilters[status][$eq]=published
$neNot equal tofilters[status][$ne]=draft

Comparison Operators

OperatorDescriptionExample
$ltLess thanfilters[price][$lt]=100
$lteLess than or equal tofilters[price][$lte]=100
$gtGreater thanfilters[views][$gt]=1000
$gteGreater than or equal tofilters[views][$gte]=1000

String Operators

OperatorDescriptionExample
$containsContains substring (case-sensitive)filters[title][$contains]=tutorial
$notContainsDoes not contain substringfilters[title][$notContains]=draft
$startsWithStarts with substringfilters[title][$startsWith]=How to
$endsWithEnds with substringfilters[title][$endsWith]=guide
String operators are case-sensitive by default. Use $containsi, $startsWithi, and $endsWithi for case-insensitive matching.

Array Operators

OperatorDescriptionExample
$inValue in arrayfilters[status][$in][0]=published&filters[status][$in][1]=featured
$notInValue not in arrayfilters[status][$notIn][0]=draft&filters[status][$notIn][1]=archived

Null Operators

OperatorDescriptionExample
$nullIs nullfilters[publishedAt][$null]=true
$notNullIs not nullfilters[publishedAt][$notNull]=true

Logical Operators

Combine multiple conditions using logical operators:
# Both conditions must be true
curl "https://api.example.com/api/articles?filters[status][$eq]=published&filters[views][$gt]=1000"

Filtering Relations

Filter by related entity fields:
curl "https://api.example.com/api/articles?filters[author][name][$eq]=John Doe"
You can filter on any depth of relations by chaining field names: filters[author][company][name][$eq]=Acme

Sorting

Sort results using the sort parameter:
curl "https://api.example.com/api/articles?sort=title"

Sort Options

  • Ascending: sort=fieldName or sort=fieldName:asc
  • Descending: sort=fieldName:desc
  • Multiple fields: Apply sorts in order of priority

Field Selection

Select specific fields to reduce response size and improve performance:
curl "https://api.example.com/api/articles?fields[0]=title&fields[1]=description&fields[2]=publishedAt"
By default, the id field is always included. Other fields must be explicitly specified when using field selection.

Populating Relations

Include related entities in the response:
curl "https://api.example.com/api/articles?populate=author"
Use field selection with population to optimize API responses:
curl "https://api.example.com/api/articles?populate[author][fields][0]=name&populate[author][fields][1]=avatar"

Combining Parameters

Combine filtering, sorting, field selection, and pagination for powerful queries:
curl "https://api.example.com/api/articles?\
  filters[status][$eq]=published&\
  filters[views][$gt]=1000&\
  sort=publishedAt:desc&\
  fields[0]=title&\
  fields[1]=description&\
  populate=author&\
  pagination[page]=1&\
  pagination[pageSize]=10"

Best Practices

Performance optimization:
  • Use field selection to request only needed data
  • Apply filters to reduce result set size
  • Limit relation population depth to avoid deep queries
  • Combine with pagination for large datasets
URL encoding: When using filters in URLs, ensure special characters are properly encoded. Most HTTP clients handle this automatically.

Build docs developers (and LLMs) love