Filtering and sorting

Filtering

Alerts API provides capabilities to filter and sort its output. It's achieved by using the where argument on the alerts node of the Craft API.
where allows constructing an expression that will be matched against the available Alerts and filter. The general syntax is to use the field from the Alert entity and compare it with a certain value using a specific operator.
1
alerts(
2
where: {
3
field: { operator: value }
4
}
5
)
Copied!
Please, see the AlertBoolExpression type definition for all of the available fields and operators available.
It's also possible to specify multiple fields which will be combined with a logical "AND":
1
alerts(
2
where: {
3
firstField: { operator: value },
4
secondField: { operator: value }
5
}
6
)
Copied!
In such case, API will return Alerts where firstField and secondField are matching provided values.

Sorting

By default Alerts API output is sorted chronologically by publishedAt field in descending (most recent Alerts first) order. To change the order to ascending order (oldest published Alerts first), it's possible to specify the orderBy argument on the alerts node:
1
query getAlerts {
2
alerts(
3
orderBy: { publishedAt: ASC }
4
)
5
}
Copied!
Please, see the orderBy type definition for all the possible fields and values.
Last modified 5mo ago
Copy link