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
Webhooks can be managed via the WooCommerce settings screen or by using the REST API endpoints. The `WC_Webhook` class manages all data storage and retrieval of the custom post type, as well as enqueuing webhook actions and processing/delivering/logging the webhook. On `woocommerce_init`, active webhooks are loaded and their associated hooks are added.
373
-
374
-
Each webhook has:
375
-
376
-
* status: active (delivers payload), paused (delivery paused by admin), disabled (delivery paused by failure)
377
-
* topic: determines which resource events the webhook is triggered for
378
-
* delivery URL: URL where the payload is delivered, must be HTTP or HTTPS
379
-
* secret: an optional secret key that is used to generate a HMAC-SHA256 hash of the request body so the receiver can verify authenticity of the webhook
380
-
* hooks: an array of hook names that are added and bound to the webhook for processing
381
-
382
-
### Topics ###
383
-
384
-
The topic is a combination resource (e.g. order) and event (e.g. created) and maps to one or more hook names (e.g. `woocommerce_checkout_order_processed`). Webhooks can be created using the topic name and the appropriate hooks are automatically added.
Custom topics can also be used which map to a single hook name, for example you could add a webhook with topic `action.woocommerce_add_to_cart` that is triggered on that event. Custom topics pass the first hook argument to the payload, so in this example the `cart_item_key` would be included in the payload.
394
-
395
-
### Delivery/Payload ###
396
-
397
-
Delivery is done using `wp_remote_post()` (HTTP POST) and processed in the background by default using wp-cron. A few custom headers are added to the request to help the receiver process the webhook:
398
-
399
-
*`X-WC-Webhook-Topic` - e.g. `order.updated`
400
-
*`X-WC-Webhook-Resource` - e.g. `order`
401
-
*`X-WC-Webhook-Event` - e.g. `updated`
402
-
*`X-WC-Webhook-Signature` - a base64 encoded HMAC-SHA256 hash of the payload
403
-
*`X-WC-Webhook-ID` - webhook's post ID
404
-
*`X-WC-Delivery-ID` - delivery log ID (a comment)
405
-
406
-
The payload is JSON encoded and for API resources (coupons, customers, orders, products), the response is exactly the same as if requested via the REST API.
407
-
408
-
### Logging ###
409
-
410
-
Requests/responses are logged as comments on the webhook custom post type. Each delivery log includes:
411
-
412
-
* Request duration
413
-
* Request URL, method, headers, and body
414
-
* Response Code, message, headers, and body
415
-
416
-
Only the 25 most recent delivery logs are kept in order to reduce comment table bloat.
417
-
418
-
After 5 consecutive failed deliveries (as defined by a non HTTP 2xx response code), the webhook is disabled and must be edited via the REST API to re-enable.
419
-
420
-
Delivery logs can be fetched through the REST API endpoint or in code using `WC_Webhook::get_delivery_logs()`
421
-
422
-
### Endpoints ###
423
-
424
-
[See the webhook resource section](#webhooks7).
425
-
426
-
### Visual Interface ###
427
-
428
-
You can find the Webhooks interface going to "WooCommerce" > "Settings" > "API" > "Webhooks", see our [Visual Webhooks docs](https://docs.woothemes.com/document/webhooks/) for more details.
429
-
430
368
## Troubleshooting ##
431
369
432
370
* Nginx - Older configurations of Nginx can cause issues with the API, see [this issue](https://github.com/woothemes/woocommerce/issues/5616#issuecomment-47338737) for details.
Copy file name to clipboardExpand all lines: source/includes/wp-api-v1/_webhooks.md
+54
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,60 @@
2
2
3
3
This section lists all API endpoints that can be used to create, edit or otherwise manipulate webhooks.
4
4
5
+
Webhooks can be managed via the WooCommerce settings screen or by using the REST API endpoints. The `WC_Webhook` class manages all data storage and retrieval of the custom post type, as well as enqueuing webhook actions and processing/delivering/logging the webhook. On `woocommerce_init`, active webhooks are loaded and their associated hooks are added.
6
+
7
+
Each webhook has:
8
+
9
+
*`status`: active (delivers payload), paused (delivery paused by admin), disabled (delivery paused by failure).
10
+
*`topic`: determines which resource events the webhook is triggered for.
11
+
*`delivery URL`: URL where the payload is delivered, must be HTTP or HTTPS.
12
+
*`secret`: an optional secret key that is used to generate a HMAC-SHA256 hash of the request body so the receiver can verify authenticity of the webhook.
13
+
*`hooks`: an array of hook names that are added and bound to the webhook for processing.
14
+
15
+
### Topics ###
16
+
17
+
The topic is a combination resource (e.g. order) and event (e.g. created) and maps to one or more hook names (e.g. `woocommerce_checkout_order_processed`). Webhooks can be created using the topic name and the appropriate hooks are automatically added.
18
+
19
+
Core topics are:
20
+
21
+
* Coupons: `coupon.created`, `coupon.updated` and `coupon.deleted`.
22
+
* Customers: `customer.created`, `customer.updated` and `customer.deleted`.
23
+
* Orders: `order.created`, `order.updated` and `order.deleted`.
24
+
* Products: `product.created`, `product.updated` and `product.deleted`.
25
+
26
+
Custom topics can also be used which map to a single hook name, for example you could add a webhook with topic `action.woocommerce_add_to_cart` that is triggered on that event. Custom topics pass the first hook argument to the payload, so in this example the `cart_item_key` would be included in the payload.
27
+
28
+
### Delivery/Payload ###
29
+
30
+
Delivery is done using `wp_remote_post()` (HTTP POST) and processed in the background by default using wp-cron. A few custom headers are added to the request to help the receiver process the webhook:
31
+
32
+
*`X-WC-Webhook-Topic` - e.g. `order.updated`.
33
+
*`X-WC-Webhook-Resource` - e.g. `order`.
34
+
*`X-WC-Webhook-Event` - e.g. `updated`.
35
+
*`X-WC-Webhook-Signature` - a base64 encoded HMAC-SHA256 hash of the payload.
36
+
*`X-WC-Webhook-ID` - webhook's post ID.
37
+
*`X-WC-Delivery-ID` - delivery log ID (a comment).
38
+
39
+
The payload is JSON encoded and for API resources (coupons, customers, orders, products), the response is exactly the same as if requested via the REST API.
40
+
41
+
### Logging ###
42
+
43
+
Requests/responses are logged as comments on the webhook custom post type. Each delivery log includes:
44
+
45
+
* Request duration.
46
+
* Request URL, method, headers, and body.
47
+
* Response Code, message, headers, and body.
48
+
49
+
Only the 25 most recent delivery logs are kept in order to reduce comment table bloat.
50
+
51
+
After 5 consecutive failed deliveries (as defined by a non HTTP 2xx response code), the webhook is disabled and must be edited via the REST API to re-enable.
52
+
53
+
Delivery logs can be fetched through the REST API endpoint or in code using `WC_Webhook::get_delivery_logs()`.
54
+
55
+
### Visual Interface ###
56
+
57
+
You can find the Webhooks interface going to "WooCommerce" > "Settings" > "API" > "Webhooks", see our [Visual Webhooks docs](https://docs.woothemes.com/document/webhooks/) for more details.
0 commit comments