Filter your events
Shopify provides you with a way to you manage the number of event messages your app receives. Unlike payload modifications, filters are made up of rules, applied to a webhook subscription, which then act as a gate for whether or not webhooks are delivered when an event occurs.
Example: Filtering when products are updated
Anchor link to section titled "Example: Filtering when products are updated"Suppose you are building an app that relies on data when a product is updated. Because of your use case, you are only interested in this data if at least one product variant's price is greater than or equal to $10.00.
However, because you have subscribed your app to the products/update
webhook topic, your app receives webhooks any time the product is updated, regardless of the variant price. As a result, you receive far more webhooks than you care about, and must process them all, in order to get the information you really care about (webhooks for products where the variant price is at least $10.00).
In this case, you can use the filter capability to define a rule on your webhook subscription.
After you apply this filter, your app will receives products/update
webhooks for updates to products where at least one variant's price is at least $10.00.
How to configure filters
Anchor link to section titled "How to configure filters"There are two ways in which you can filter webhooks:
- In the
filters
argument when you create or update a subscription using your app configuration file - With the
filter
input field in thewebhookSubscription
argument when you create or update a subscription using the GraphQL Admin API
To determine what are valid values for your filter rules, refer to the sample payloads in the Webhooks reference.
You denote nested fields by using a period:
Differences between Filters and Search
Anchor link to section titled "Differences between Filters and Search"Webhook filters leverage Shopify API's Search syntax. However there are slight differences in the behavior between Filters and Search.
Filters | Search |
---|---|
If you specify an invalid field, then no webhooks will be delivered. | If you specify an invalid field, then all documents are returned. |
: operator is an equality operator for Filters. |
: operator does fuzzy matching when fields are tokenized. |
You must explicitly specify the fields that you want to filter on. | Term searches are supported (query:“bob” ). |
Case-sensitive. | Case-insensitive. |
Debugging Filters
Anchor link to section titled "Debugging Filters"In instances when an invalid filter is applied to a subscription, expect the following behavior:
Scenario | Expected behavior |
---|---|
Filter uses field that doesn’t exist in payload | Filter can be created but no event messages will be sent |
include_fields , includeFields or metafieldNamespaces does not include fields that are included in the filter definition |
Subscription will not be created and an error will be provided. |
Filter uses a rule that is not possible (type mismatch) | Filter can be created but no event messages will be sent. |
Incorrect filter syntax | Filter will not be created and an error message is returned. |