You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/webhooks/conditional-webhooks.md
+92-4Lines changed: 92 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
---
2
-
title: Create conditional webhooks
2
+
title: Define conditional webhooks
3
3
description: Learn how to create conditional webhooks, which can reduce the amount of remote API calls.
4
4
keywords:
5
5
- Webhooks
6
6
- Extensibility
7
7
---
8
8
9
-
# Create conditional webhooks
9
+
# Define conditional webhooks
10
10
11
11
You may decide that you want to trigger a webhook only if its payload meets certain conditions. For example, you could decide to calculate taxes using a third-party service for specific postal codes only. If the postal code provided in the payload does not match the selected postal code, there is no value in triggering the webhook.
12
12
@@ -33,18 +33,22 @@ Conditional webhooks can have one or more rules. Each rule contains the followin
33
33
34
34
* The value to compare against. When you assign the `regex` operator, you must delimit the regular expression value with valid characters, such as forward slashes (/). For example, `/^TV .*/i`, which checks whether the string starts with `TV`, ignoring the case of the letters.
35
35
36
-
## Define conditional webhooks in `webhooks.xml`
36
+
## Example: Calculate tax
37
37
38
38
The following example creates and registers a conditional webhook for the event `plugin.magento.tax.api.tax_calculation.calculate_tax`. The webhook will be only triggered when all of the conditions are true:
39
39
40
40
* The value of `quoteDetails.shipping_address.country_id` must be equal to `US`.
41
41
* The `quoteDetails.billing_address.postcode` must begin with `123`.
<hookname="update_order"url="{env:APP_URL}/calculate-taxes"method="POST"timeout="5000"softTimeout="1000"priority="300"required="false"fallbackErrorMessage="The taxes can not be calculated">
51
+
<hookname="update_order"url="{env:APP_URL}/calculate-taxes"method="POST"timeout="5000"softTimeout="1000"priority="300"required="false"fallbackErrorMessage="The taxes cannot be calculated">
48
52
<fields>
49
53
<fieldname="quoteDetails" />
50
54
<fieldname="storeId" />
@@ -59,8 +63,52 @@ The following example creates and registers a conditional webhook for the event
Fallback Error Message: The taxes cannot be calculated
80
+
Required: `false`
81
+
Active: `true`
82
+
83
+
Hook Fields
84
+
85
+
Name: quoteDetails
86
+
Active: Yes
87
+
88
+
Name: storeId
89
+
Active: Yes
90
+
91
+
Hook Rules
92
+
93
+
Name: quoteDetails.shipping_address.country_id
94
+
Operation: equal
95
+
Value: US
96
+
Active: Yes
97
+
98
+
Name: quoteDetails.billing_address.postcode
99
+
Operation: regex
100
+
Value: /^123/
101
+
Active: Yes
102
+
```
103
+
104
+
## Example: Generate short descriptions for products
105
+
62
106
The following example sends a webhook to a third-party service when the product short description is empty. The service generates the text for the description. The webhook returns the operation with information to update the product short description. As a result, the webhook will not be triggered again for the same product.
0 commit comments