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/responses.md
+155-9Lines changed: 155 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -7,19 +7,28 @@ keywords:
7
7
8
8
# Webhook responses and logging
9
9
10
-
Currently, Adobe Commerce webhooks only support two responses: `success` and `exception`. Responses that require additional processing, such as parsing the results of a GET response, are not supported.
10
+
Currently, Adobe Commerce webhooks support responses in JSON format only. The response may be a single operation or an array of operations to be executed afterward.
11
+
Each operation must contain some required fields based on the desired operation.
11
12
12
13
Exceptions and notices are logged in the `<installation_directory>/var/log/system.log` file.
13
14
14
15
## Responses
15
16
16
-
The endpoint is expected to return a `200` response and a JSON object that indicates the result of the operation. The object can contain the following fields:
17
+
The endpoint is expected to return a `200` response and a JSON object or array of objects that indicates the result of the operation. Each operation object can contain the list of fields based on the operation (`op`) which should be performed.
17
18
18
-
Field | Description
19
+
Adobe Commerce webhooks support the following operations:
20
+
21
+
Operation | Description
19
22
--- | ---
20
-
`op` | The status of the operation: either `success` or `exception`.
21
-
`class` | If the `op` status is `exception`, optionally specifies the exception class. If `class` is not set, the `\Magento\Framework\Exception\LocalizedException` will be thrown.
22
-
`message` | If the `op` status is `exception`, optionally specifies the exception message. If this field is not explicitly set, then the message defined in the `fallbackErrorMessage` configuration field will be returned. If `fallbackErrorMessage` is not set, the system default error message will be shown.
23
+
`success` | The process that triggered the original event continues without any changes.
24
+
`exception` | Causes Commerce to terminate the process that triggered the original event.
25
+
`add` | Updates the arguments in the original event by adding data described in the operation
26
+
`replace` | Replaces argument values in the original event, based on the response.
27
+
`remove` | Removes values or nodes from the arguments in the original event by the provided path
28
+
29
+
### Success operation
30
+
31
+
The `success` operation is returned when changes are not needed. The process that triggered the original event continues without any changes.
23
32
24
33
The response of a successful request is as follows:
25
34
@@ -29,19 +38,156 @@ The response of a successful request is as follows:
29
38
}
30
39
```
31
40
32
-
The process that triggered the original event continues without any changes.
41
+
### Exception operation
42
+
43
+
The `exception` operation causes Commerce to terminate the process that triggered the original event. The exception is logged in `<installation_directory>/var/log/system.log`.
44
+
45
+
Field | Type | Description
46
+
--- | --- | ---
47
+
`op` | Required | Contains `exception`.
48
+
`class` | Optional | Specifies the exception class. If `class` is not set, `\Magento\Framework\Exception\LocalizedException` will be thrown.
49
+
`message` | Optional | Specifies the exception message. If this field is not explicitly set, then the message defined in the `fallbackErrorMessage` configuration field will be returned. If `fallbackErrorMessage` is not set, the system default error message will be returned.
33
50
34
51
If an error occurs, the response is similar to the following:
35
52
36
53
```json
37
54
{
38
55
"op": "exception",
39
56
"class": "Path\\To\\Exception\\Class",
40
-
"message": "The product can not be added to the cart as it is out of the stock"
57
+
"message": "The product cannot be added to the cart because it is out of the stock"
41
58
}
42
59
```
43
60
44
-
The `exception` operation causes Commerce to terminate the process that triggered the original event. The exception is logged in `<installation_directory>/var/log/system.log`.
61
+
### Add operation
62
+
63
+
The `add` operation causes Commerce to add the provided `value` to the provided `path` to the triggered event arguments
64
+
65
+
Field | Type | Description
66
+
--- |----------| ---
67
+
`op` | Required | Contains `add`.
68
+
`path` | Required | Specifies the path at which the `value` should be added to the triggered event arguments.
69
+
`value` | Required | Specifies the value to be added. This can be as a single value or in an array format.
70
+
`instance` | Optional | Specifies the `DataObject` class name to create, based on the `value` and added to the provided `path`. Use this field for cases when the object should be added in provided path.
71
+
72
+
For example, we want to add a new shipping method to the triggered event result payload.
73
+
The result is an array of `Magento\Quote\Model\Cart\ShippingMethod` objects:
Based on this operation, the new instance of `Magento\Quote\Model\Cart\ShippingMethodInterface` will be created and added to the result array of shipping methods.
0 commit comments