diff --git a/src/data/navigation/sections/webhooks.js b/src/data/navigation/sections/webhooks.js index f15feb6c..989f95db 100644 --- a/src/data/navigation/sections/webhooks.js +++ b/src/data/navigation/sections/webhooks.js @@ -31,6 +31,10 @@ module.exports = [ title: "Signature Verification", path: "/webhooks/signature-verification.md" }, + { + title: "API reference", + path: "/webhooks/api.md", + }, { title: "Command reference", path: "/webhooks/commands.md", diff --git a/src/pages/events/api.md b/src/pages/events/api.md index 7a941f50..e4f0f20f 100644 --- a/src/pages/events/api.md +++ b/src/pages/events/api.md @@ -42,7 +42,7 @@ The `POST /rest//V1/eventing/eventSubscribe` endpoint subscribe -After you subscribe to a `plugin-type` event, you must manually generate the module that defines the event plugins. [events:generate:module](commands.md#generate-a-commerce-module-based-on-a-list-of-subscribed-events) +After you subscribe to a `plugin-type` event, you must manually generate the module that defines the event plugins with the [events:generate:module](commands.md#generate-a-commerce-module-based-on-a-list-of-subscribed-events) command. **Headers:** @@ -81,6 +81,64 @@ curl -i -X POST \ '/rest/all/V1/eventing/eventSubscribe' ``` +## Unsubscribe from events + +The `POST /rest//V1/eventing/eventUnsubscribe/` endpoint unsubscribes from the specified event. + +**Header:** + +`Authorization: Bearer ` + +The administrator must be granted access to the `Magento_AdobeCommerceEventsClient::event_unsubscribe` resource. + +**Example usage:** + +The following cURL command unsubscribes from the `observer.catalog_category_save_after` event. + +```bash +curl -i -X POST \ + -H "Authorization:Bearer " \ + '/rest/all/V1/eventing/eventUnsubscribe/observer.catalog_category_save_after' +``` + +## Get a list of all subscribed events + +The `GET /rest/all/V1/eventing/getEventSubscriptions` endpoint returns a list of all subscribed events that are enabled. The response body is similar to the following: + +```json +[{ + "name": "observer.catalog_product_save_after.price_check", + "parent": "observer.catalog_product_save_after", + "fields": [ + "price", + "name", + "sku" + ], + "rules": [ + { + "field": "price", + "operator": "lessThan", + "value": "300.00" + } + ], + "destination": "default", + "priority": false, + "hipaa_audit_required": false +}] +``` + +The administrator must be granted access to the `Magento_AdobeCommerceEventsClient::event_subscriptions` resource. + +**Example usage:** + +The following cURL command returns returns a list of all subscribed events that are enabled. + +```bash +curl --request GET \ + --url /rest/all/V1/eventing/getEventSubscriptions \ + --header 'Authorization: Bearer ' +``` + ## Update event subscriptions The `PUT /rest//V1/eventing/eventSubscribe/` endpoint updates an existing subscription to the specified event. The request body has the following format: @@ -145,26 +203,6 @@ curl -i -X PUT \ '/rest/all/V1/eventing/eventSubscribe/observer.catalog_category_save_after' ``` -## Unsubscribe from events - -The `POST /rest//V1/eventing/eventUnsubscribe/` endpoint unsubscribes from the specified event. - -**Header:** - -`Authorization: Bearer ` - -The administrator must be granted access to the `Magento_AdobeCommerceEventsClient::event_unsubscribe` resource. - -**Example usage:** - -The following cURL command unsubscribes from the `observer.catalog_category_save_after` event. - -```bash -curl -i -X POST \ - -H "Authorization:Bearer " \ - '/rest/all/V1/eventing/eventUnsubscribe/observer.catalog_category_save_after' -``` - ## Configure Commerce eventing The `PUT /rest//V1/eventing/updateConfiguration` endpoint updates the Adobe I/O [eventing configuration](configure-commerce.md) originally defined on the **Stores** > Settings > **Configuration** > **Adobe Services** > **Adobe I/O Events** > **General configuration** page of the Admin. diff --git a/src/pages/webhooks/api.md b/src/pages/webhooks/api.md new file mode 100644 index 00000000..80c71024 --- /dev/null +++ b/src/pages/webhooks/api.md @@ -0,0 +1,70 @@ +--- +title: REST Endpoints for Webhooks +description: Provides details about the webhook API endpoints. +keywords: + - Webhooks + - Extensibility +--- + +# REST endpoints for webhook. + +Adobe Commerce provides several REST endpoints that interact with the webhooks processes. These endpoints require an [admin token](https://developer.adobe.com/commerce/webapi/rest/tutorials/prerequisite-tasks/). + +## Get a list of all subscribed webhooks + +The `GET /rest/all/V1/webhooks/list` endpoint returns a list of all subscribed webhooks. The response body is similar to the following: + +```json +[ + { + "webhook_method": "observer.sales_order_place_before", + "webhook_type": "after", + "batch_name": "sales_order", + "batch_order": 100, + "hook_name": "sales_order_status", + "url": "/hook-url", + "priority": 100, + "required": true, + "soft_timeout": 1000, + "timeout": 2000, + "method": "", + "fallback_error_message": "Unable to validate product", + "ttl": 6000, + "fields": [ + { + "name": "name", + "source": "data.product.name" + }, + { + "name": "price", + "source": "data.product.price" + } + ], + "rules": [ + { + "field": "data.product.sku", + "operator": "regex", + "value": "\/.*car.*\/" + } + ], + "headers": [ + { + "name": "header-name", + "value": "header-value" + } + ] + } +] +``` + +The administrator must be granted access to the `Magento_AdobeCommerceWebhooks::webhooks_list` resource. + +**Example usage:** + +The following cURL command returns returns a list of all subscribed webhooks. + +```bash +curl --request GET \ + --url /rest/all/V1/webhooks/list \ + --header 'Authorization: Bearer ' +```