In Pabbly Hook, Filters allow you to permit events conditionally based on the contents of their Headers, Body, Query, or Path.
Purpose of Filters: Filters in Pabbly hooks allow you to control which webhook requests are processed based on specific criteria. They help ensure that only relevant requests trigger actions, making the process efficient and targeted. Filters can be applied to the body, headers, query parameters, and path segments of incoming requests. In simple words ,A filter is a condition or rule applied to incoming data to determine if it should be processed further or blocked the request based on condition.
Use Case for Rate Filters:
Filters utilize JSON, and support matching on any value (string, number, boolean, null), on nested objects, and on arrays. There is also support for special operators. For a full rundown of supported schema.
This way, any payload outside the specified range for price or category would result in the request being blocked by the filter.
Here's how to structure the payload to pass and block the request based on the provided filter:
Alternatively, this payload also passes because product.category is "clothing" and product.availability is "in_stock":
In this blocked payload, product.price is not less than 50, product.category is not "clothing", and product.availability is not "in_stock".
Purpose of Filters: Filters in Pabbly hooks allow you to control which webhook requests are processed based on specific criteria. They help ensure that only relevant requests trigger actions, making the process efficient and targeted. Filters can be applied to the body, headers, query parameters, and path segments of incoming requests. In simple words ,A filter is a condition or rule applied to incoming data to determine if it should be processed further or blocked the request based on condition.
Use Case for Rate Filters:
- Allowing only events with useful information to pass through to a destination.
Filters utilize JSON, and support matching on any value (string, number, boolean, null), on nested objects, and on arrays. There is also support for special operators. For a full rundown of supported schema.
1. Body Filter
A Body Filter is used to apply rules on the content within the request body. This type of filter is useful when you need to check if certain fields in the payload contain specific values.- Example: Body Filtering on the status field to process only messages with "status": "active".
- If "status": "active" is not matched in body it will block the request.
- Example: Filtering on the status field to process messages with "status": "Inactive".
2. Header Filter
A Header Filter checks specific headers in the request, allowing you to validate metadata or control data processing based on headers.- Example: Header Filtering on Content-Type to process only requests where "Content-Type": "application/json".
- If "Content-Type": "application/json" is not matched it will block the request.
- Example: Filtering on the Content-Type field to process messages with "Content-Type": "plain/text".
3. Query Filter
A Query Filter is used to filter requests based on query parameters. This is helpful when specific information, like IDs or action types, is passed as URL query parameters.- Example: Query Params Filtering on the user_id query parameter to process requests only for a specific user "user_id":"12345".
- If "user_id":"12345" is not matched it will block the request.
- Example: Filtering on the field to process messages with "user_id":"678910".
Complex matches using operators.
Operators allow for more complex matching strategies, beyond simple equivalency tests.Operator | Supported Type | Description |
---|---|---|
$gte | number, string | Greater than or equal to |
$gt | number, string | Greater than |
$lt | number, string | Less than |
$lte | number, string | Less than or equal to |
$eq | array, number, object, string | Equal (or deep equal) |
$neq | array, number, object, string | Not Equal (or deep not equal) |
$in | array, string | Contains |
$nin | array, string | Does not contain |
$startsWith | string | Starts with text |
$endsWith | string | Ends with text |
$or | array | Array of conditions to match |
$and | array | Array of conditions to match |
$exist | boolean | Undefined or not undefined |
$not | Valid syntax | Negation |
1. Value Operators
These operators are used for comparisons between values such as numbers, dates, or even strings.- $eq: Matches if the value is equal to the specified value.
- $neq: Matches if the value is not equal to the specified value.
- $lt: Matches if the value is less than the specified value.
- $lte: Matches if the value is less than or equal to the specified value.
- $gt: Matches if the value is greater than the specified value.
- $gte: Matches if the value is greater than or equal to the specified value.
- $in: Matches if the value is in the array.
Example:
Code:
{
"product": {
"price": {
"$gte": 100,
"$lte": 500
},
"category": {
"$in": ["electronics", "furniture"]
}
}
}
- Explanation: This filter will match if the price of the product is between 100 and 500, and the category is either "electronics" or "furniture".
Code:
{
"product": {
"price": 250,
"category": "electronics"
}
}
Blocking Payload
For the payload to block, any of the following can be true:- price is less than 100 or greater than 500
- category is not "electronics" or "furniture"
Code:
{
"product": {
"price": 50,
"category": "clothing"
}
}
This way, any payload outside the specified range for price or category would result in the request being blocked by the filter.
2. String Operators
These operators are useful for pattern matching or working with string values.- $contains: Matches if the string contains the specified value.
- $notContains: Matches if the string does not contain the specified value.
- $startsWith: Matches if the string starts with the specified value.
- $endsWith: Matches if the string ends with the specified value.
- $regex: Matches if the string matches the given regular expression.
Example:
Code:
{
"product": {
"title": {
"$startsWith": "Smart",
"$regex": {
"pattern": "Pro$",
"flags": "i"
}
}
}
}
- Explanation: This filter matches products where the title starts with "Smart" and ends with "Pro" (case-insensitive).
Passing Payload
Code:
{
"product": {
"title": "SmartPhone Pro"
}
}
- Explanation: The title starts with "Smart" and ends with "Pro", meeting both the $startsWith and $regex conditions.
Blocking Payload
- Title does not start with "Smart":
Code:{ "product": { "title": "Phone Pro" } }
- Title does not end with "Pro":
Code:{"product": { "title": "SmartPhone Plus" } }
- Title starts with "Smart" but is case-sensitive mismatch for regex:
Code:{"product": { "title": "smart Pro" } }
3. Existence Operators
These operators deal with the presence or absence of certain fields.- $exists: Matches if the field exists or not.
- $empty: Matches if the field is empty or not (works for strings, arrays, and objects).
Example:
Code:
{
"user": {
"email": {
"$exists": true
},
"address": {
"$empty": false
}
}
}
Here's how to structure the payload to pass and block the request based on the provided filter:
Explanation of the Filter:
- user.email.$exists: true — The payload must have an email field under user.
- user.address.$empty: false — The address field under user should not be empty (for strings, this means it shouldn't be an empty string ""; for arrays, it shouldn't be []; for objects, it shouldn't be {}).
Payload for Passing (matches filter):
Code:
{
"user": {
"email": "[email protected]",
"address": "123 Main St, Springfield"
}
}
Payload for Blocking (does not match filter):
- Missing email:
Code:{ "user": { "address": "123 Main St, Springfield" } }
- Empty address:
Code:{ "user": { "email": "[email protected]", "address": "" } }
- Explanation: This filter will match users that have an email field and whose address field is not empty.
4. Logical Operators
Logical operators allow you to combine multiple conditions.- $and: Matches if all of the specified conditions are true.
- $or: Matches if any of the specified conditions are true.
- $not: Matches if the specified condition is false.
Example (nested with logical operators):
Code:
{
"$or": [
{
"product": {
"price": {
"$lt": 50
}
}
},
{
"$and": [
{
"product": {
"category": {
"$eq": "clothing"
}
}
},
{
"product": {
"availability": {
"$eq": "in_stock"
}
}
}
]
}
]
}
- Explanation: This filter matches if the price of the product is less than 50, or if the category is "clothing" and the product is in_stock.
- product.price is less than 50.
- OR product.category is "clothing" and product.availability is "in_stock".
1. Payload to Pass the Filter:
The following payload meets the filter because product.price is less than 50.
Code:
{
"product": {
"price": 45,
"category": "electronics",
"availability": "out_of_stock"
}
}
Alternatively, this payload also passes because product.category is "clothing" and product.availability is "in_stock":
Code:
{
"product": {
"price": 100,
"category": "clothing",
"availability": "in_stock"
}
}
2. Payload to Block the Filter:
The following payload does not meet any condition and thus would be blocked:
Code:
{
"product": {
"price": 75,
"category": "electronics",
"availability": "out_of_stock"
}
}
In this blocked payload, product.price is not less than 50, product.category is not "clothing", and product.availability is not "in_stock".
Attachments
Last edited: