Filters
Filtering is used to decide what events an endpoint will receive based on the webhook event payload.
The filter is an enriched JSON syntax for both simple and complex filters
(such as special logical and numeric operators $or
, $gte
, $eq
).
Use cases
Filters can be configured on subscriptions in both incoming projects and outgoing project.
![subscription filter](https://mintlify.s3-us-west-1.amazonaws.com/convoy/images/subscription-filter.png)
The filters are configured in the Filter Schema editor and the event payload in the Event Payload editor to validate the schema.
![Subscription filter](https://mintlify.s3-us-west-1.amazonaws.com/convoy/images/subscription-filter-empty-modal.png)
Simple filters
Simple filters directly match keys to values, and they can be nested. They can also match items in an array.
Direct object match
This filter is used to validate simple JSON webhook payloads.
{
"event_type": "created"
}
![subscription filter modal](https://mintlify.s3-us-west-1.amazonaws.com/convoy/images/subscription-filter-modal.png)
Nested object match
This filter is used to validate nested webhook payloads.
{
"event": {
"type": "created"
}
}
![subscription filter modal](https://mintlify.s3-us-west-1.amazonaws.com/convoy/images/subscription-filter-modal-nested.png)
Array contains match
{
"dish": {
"ingredients": "rice"
}
}
![subscription filter modal](https://mintlify.s3-us-west-1.amazonaws.com/convoy/images/subscription-filter-array-contains.png)
Complex filters
Complex filters contain more logic such as logical operators and special operators.
Complex filters are employed to filter events using one or more conditions, e.g., $or
logical operator filter.
Equality filters
This filter matches event which directly does not match the event type in the webhook payload.
{
"event": {
"$neq": "created"
}
}
![$neq subscription filter](https://mintlify.s3-us-west-1.amazonaws.com/convoy/images/subscription-ne-filter.png)
Compound filters
These filters are used to match multiple conditions defined in the schema.
{
"$or": [
{
"cities": "london"
},
{
"type": "weekly"
}
]
}
{
"$and": [
{
"age": {
"$gte": 10
}
},
{
"$or": [
{
"type": "weekly"
},
{
"cities": "lagos"
}
]
}
]
}
![$and filter](https://mintlify.s3-us-west-1.amazonaws.com/convoy/images/subscription-or-filter.png)
Array Contains filters
This filter is used to match keys where the value can be a range of values.
It can be used in place of $or
if you are comparing on the same field.
The opposite of this operator $nin
can be used to match keys where the value is not in a range of values.
{
"operation": {
"$in": ["created", "deleted"]
}
}
{
"operation": {
"$nin": ["updated", "truncated"]
}
}
![$in filter](https://mintlify.s3-us-west-1.amazonaws.com/convoy/images/subscription-in-filter.png)
Numeric filters
These filters match events based on numeric operators.
For example, the filter below will match all events where the age is greater than 1. The operators supported are $gt
,
$gte
, $lt
, $lte
{
"age": {
"$gt": 1
}
}
Array positional filters (currently in beta)
These filters match events with payloads that are array either in the root or nested.
{
"$.venues.$.lagos": "lekki"
}
![Array positional $. filter](https://mintlify.s3-us-west-1.amazonaws.com/convoy/images/subscription-array-positional-filter.png)
Regex filters
These filters match events with payloads that match the supplied regex.
{
"event_type": {
"$regex": "^es_[a-zA-Z]+$"
}
}
![Regex filter](https://mintlify.s3-us-west-1.amazonaws.com/convoy/images/subscription-regex-filter.png)
Caveats
- Convoy only supports filters with arrays nested up to three levels i.e.
$.a.$.b.$.c.$.e
will throw an error - Array positional filters are in beta and have time complexity of
O(n^3)
Supported Filters
Here’s a full list of the supported filters:
Operator | Supported Type | Description |
---|---|---|
none | all | Match all |
$. | array | Match an array value |
$gte | number | Greater than or equal to |
$gt | number | Greater than |
$lt | number | Less than |
$lte | number | Less than or equal to |
$eq | number, object, string, bool | Equal |
$neq | number, object, string, bool | Not Equal |
$in | array | checks if an array contains a value |
$nin | array | checks if an array does not contain a value |
$or | array of conditions | matches an array of conditions |
$and | array of conditions | matches an array of conditions |
$exist | array | checks if a key exists |
$regex | string | checks if the regex matches |
Was this page helpful?