Item Filtering for Webhooks

Filters allow you to control which items are sent to a webhook and which ones are filtered out. For example, you can create filters so that only certain items are delivered based on their attribute values.

Filters should avoid manipulating the item attributes. If certain values need to be formatted differently in the payload, use virtual attributes. If items need to be persisted with changed attribute values, use persistence interceptors. For information about virtual attributes and interceptors, see Virtual Attributes and Interceptors respectively.

Although webhooks are processed asynchronously, it's still important to avoid slow-running operations in the filter as it can impact webhook processing performance. For more information, see the "Performance Implications for Webhooks" section of this topic.

Configuration Example

This example demonstrates the steps to filter for products only found in an Online catalog to send any applicable product changes to a webhook.

The first step is to create a filter. Filters must be written as platform scripts, and they must implement de.hybris.platform.webhookservices.filter.WebhookFilter interface. For more information about how to implement an interface and how dependencies can be injected, see the "Using Return Objects as Interfaces" section in Scripting Engine.

Create a Groovy script:
The second step is to save the script in the platform. You can do this using Backoffice, ImpEX, or the Script Service Meta API. This example uses the Script Service Meta API (for more information, see Script Service Meta API for Virtual Attributes). To create the filter script in the platform, execute this POST request:
The third step is to create a WebhookConfiguration. This example uses the same Integration Object and consumed destinaton from the above webhook configuration example.
Now that the WebhookConfiguration including the filter has been created, only changes for products in the Online catalog are sent to the external webhook site.
Because filters can be used to prevent sensitive data from being sent to an external system, any of the following issues prevent items from being sent to the external webhook site:
  • The filterLocation contains an invalid or malformed URL.
  • The filter script specified by the filterLocation does not exist.
  • The filter script does not implement de.hybris.platform.webhookservices.filter.WebhookFilter interface.
  • The filter script throws an exception during its execution.
  • The filter script returns an item that is not of a type or a subtype of the original item sent through the filter.

If a filter is no longer needed, you can remove it by updating the filterLocation attribute in the WebhookConfiguration to null or an empty value.

Use Filtering for General Data Protection Regulation (GDPR)

You can use filtering for situations that require specific customer data to be protected based on GDPR requirements. For example, not exposing a customer's email address when sending an Order. Because an Order Integration Object contains a customer's name, address, and email, filtering can mask the email address so that it's not exposed. The following is a sample Order Integration Object:
The following script masks the email address before sending the Order:
The resulting payload looks like this: