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/hooks.md
+87Lines changed: 87 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -134,6 +134,93 @@ The following example configures the webhook described above.
134
134
</hook>
135
135
```
136
136
137
+
If the default payload of a webhook contains an array of objects, use the following construction to select fields from that array:
138
+
139
+
```text
140
+
<object_name>[].<field_name>
141
+
```
142
+
143
+
For example, the payload of the `plugin.magento.quote.api.shipment_estimation.estimate_by_extended_address` event contains a top-level `results[]` array. The array contains details about two individual shipping estimates.
144
+
145
+
```json
146
+
{
147
+
"subject": [],
148
+
"result": [
149
+
{
150
+
"carrier_code": "tablerate",
151
+
"method_code": "bestway",
152
+
"carrier_title": "Best Way",
153
+
"method_title": "Table Rate",
154
+
"amount": 15,
155
+
"base_amount": 15,
156
+
"available": true,
157
+
"error_message": "",
158
+
"price_excl_tax": 15,
159
+
"price_incl_tax": 15
160
+
},
161
+
{
162
+
"carrier_code": "flatrate",
163
+
"method_code": "flatrate",
164
+
"carrier_title": "Flat Rate",
165
+
"method_title": "Fixed",
166
+
"amount": 20,
167
+
"base_amount": 20,
168
+
"available": true,
169
+
"error_message": "",
170
+
"price_excl_tax": 20,
171
+
"price_incl_tax": 20
172
+
}
173
+
],
174
+
"cartId": "21",
175
+
"address": {
176
+
"street": "123 Test Road",
177
+
"city": "Test City",
178
+
"region_id": 12,
179
+
"region": "California",
180
+
"country_id": "US",
181
+
"postcode": "90000",
182
+
"firstname": "Test",
183
+
"lastname": "Test",
184
+
"company": "",
185
+
"telephone": "1800000000",
186
+
"save_in_address_book": 1,
187
+
"region_code": "CA",
188
+
"extension_attributes": []
189
+
}
190
+
}
191
+
```
192
+
193
+
To transmit the `postcode` property of the `address` object and the `carrier_code`, `method_code`, and `base_amount` for each shipping estimate, the webhook's fields can be configured as follows:
194
+
195
+
```xml
196
+
<fields>
197
+
<fieldname='postcode'source='address.postcode' />
198
+
<fieldname='result[].carrier_code' />
199
+
<fieldname='result[].method_code' />
200
+
<fieldname='result[].base_amount' />
201
+
</fields>
202
+
```
203
+
204
+
The following object would then be sent to the remote application:
205
+
206
+
```json
207
+
{
208
+
"postcode": "90000",
209
+
"result": [
210
+
{
211
+
"carrier_code": "tablerate",
212
+
"method_code": "bestway",
213
+
"base_amount": 15
214
+
},
215
+
{
216
+
"carrier_code": "flatrate",
217
+
"method_code": "flatrate",
218
+
"base_amount": 20
219
+
}
220
+
]
221
+
}
222
+
```
223
+
137
224
### Field converters
138
225
139
226
You can implement a converter class to convert a field to a different data type. For example, Commerce stores order IDs as numeric values. If the hook endpoint expects order IDs to be text values, you must convert the numeric value to a string representation before sending the payload.
0 commit comments