Skip to content

Commit 721fb24

Browse files
authored
Merge pull request AdobeDocs#384 from AdobeDocs/revise-webhooks
Badging for webhooks
2 parents 488f42e + 558fe24 commit 721fb24

File tree

10 files changed

+339
-186
lines changed

10 files changed

+339
-186
lines changed

src/data/navigation/sections/webhooks.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ module.exports = [
5050
]
5151
},
5252
{
53-
title: "Manage webhooks from the Admin",
53+
title: "Create a webhook",
5454
path: "/webhooks/create-webhooks.md"
5555
},
5656
{
57-
title: "Configure hooks",
57+
title: "Configure hook contents",
5858
path: "/webhooks/hooks.md"
5959
},
6060
{
61-
title: "Create conditional webhooks",
61+
title: "Define conditional webhooks",
6262
path: "/webhooks/conditional-webhooks.md"
6363
},
6464
{

src/pages/webhooks/commands.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Webhooks commands
33
description: Provides details about the commands needed to use Adobe Commerce webhooks.
4+
edition: paas
45
keywords:
56
- Extensibility
67
---

src/pages/webhooks/conditional-webhooks.md

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: Create conditional webhooks
2+
title: Define conditional webhooks
33
description: Learn how to create conditional webhooks, which can reduce the amount of remote API calls.
44
keywords:
55
- Webhooks
66
- Extensibility
77
---
88

9-
# Create conditional webhooks
9+
# Define conditional webhooks
1010

1111
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.
1212

@@ -33,18 +33,22 @@ Conditional webhooks can have one or more rules. Each rule contains the followin
3333

3434
* 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.
3535

36-
## Define conditional webhooks in `webhooks.xml`
36+
## Example: Calculate tax
3737

3838
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:
3939

4040
* The value of `quoteDetails.shipping_address.country_id` must be equal to `US`.
4141
* The `quoteDetails.billing_address.postcode` must begin with `123`.
4242

43+
<CodeBlock slots="heading, code" repeat="2" languages="XML, YAML" />
44+
45+
#### webhooks.xml (PaaS)
46+
4347
```xml
4448
<method name="plugin.magento.tax.api.tax_calculation.calculate_tax" type="after">
4549
<hooks>
4650
<batch name="Order_Updates">
47-
<hook name="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+
<hook name="update_order" url="{env:APP_URL}/calculate-taxes" method="POST" timeout="5000" softTimeout="1000" priority="300" required="false" fallbackErrorMessage="The taxes cannot be calculated">
4852
<fields>
4953
<field name="quoteDetails" />
5054
<field name="storeId" />
@@ -59,8 +63,52 @@ The following example creates and registers a conditional webhook for the event
5963
</method>
6064
```
6165

66+
##### Admin (SaaS)
67+
68+
```yaml
69+
Hook Settings
70+
71+
Webhook method: plugin.magento.tax.api.tax_calculation.calculate_tax
72+
Webhook type: after
73+
Batch name: Order_Updates
74+
Hook name: update_order
75+
Hook priority: 300
76+
URL: <Host>/calculate-taxes
77+
Timeout: 5000
78+
Soft timeout: 1000
79+
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+
62106
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.
63107
108+
<CodeBlock slots="heading, code" repeat="2" languages="XML, YAML" />
109+
110+
#### webhooks.xml (PaaS)
111+
64112
```xml
65113
<method name="observer.catalog_product_save_before" type="before">
66114
<hooks>
@@ -80,6 +128,46 @@ The following example sends a webhook to a third-party service when the product
80128
</method>
81129
```
82130

131+
#### Admin (SaaS)
132+
133+
```yaml
134+
Hook Settings
135+
136+
Webhook method: observer.catalog_product_save_before
137+
Webhook type: before
138+
Batch name: Product_Updates
139+
Hook name: generate_description
140+
Hook priority: 300
141+
URL: <Host>/generate-product-description
142+
Timeout: 5000
143+
Soft timeout: 1000
144+
Fallback Error Message: The product could not be updated
145+
Required: `true`
146+
Active: `true`
147+
148+
Hook Fields
149+
150+
Name: product.name
151+
Source: data.product.name
152+
Active: Yes
153+
154+
Name: product.category_ids
155+
Source: data.product.category_ids
156+
Active: Yes
157+
158+
Name: product.sku
159+
Source: data.product.sku
160+
Active: Yes
161+
162+
Hook Rules
163+
164+
Name: product.short_description
165+
Operation: isEmpty
166+
Active: Yes
167+
```
168+
83169
## Command line
84170
171+
<Edition name="paas" />
172+
85173
You can use the `bin/magento webhooks:list` command to display the contents of your subscribed webhooks, including rules information.

0 commit comments

Comments
 (0)