Skip to content

Commit

Permalink
Merge pull request #306 from MayurBagwe/CEXT-3925
Browse files Browse the repository at this point in the history
CEXT-3925: Get all subscribed events & webhook endpoint
  • Loading branch information
keharper authored Jan 15, 2025
2 parents cff7bc8 + a84c75b commit ea3cae8
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 21 deletions.
4 changes: 4 additions & 0 deletions src/data/navigation/sections/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
80 changes: 59 additions & 21 deletions src/pages/events/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The `POST /rest/<store_view_code>/V1/eventing/eventSubscribe` endpoint subscribe

<InlineAlert variant="info" slots="text" />

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:**

Expand Down Expand Up @@ -81,6 +81,64 @@ curl -i -X POST \
'<ADOBE_COMMERCE_URL>/rest/all/V1/eventing/eventSubscribe'
```

## Unsubscribe from events

The `POST /rest/<store_view_code>/V1/eventing/eventUnsubscribe/<event_name>` endpoint unsubscribes from the specified event.

**Header:**

`Authorization: Bearer <administrator token>`

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 <AUTH_TOKEN>" \
'<ADOBE_COMMERCE_URL>/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 <ADOBE_COMMERCE_URL>/rest/all/V1/eventing/getEventSubscriptions \
--header 'Authorization: Bearer <TOKEN>'
```

## Update event subscriptions

The `PUT /rest/<store_view_code>/V1/eventing/eventSubscribe/<event_name>` endpoint updates an existing subscription to the specified event. The request body has the following format:
Expand Down Expand Up @@ -145,26 +203,6 @@ curl -i -X PUT \
'<ADOBE_COMMERCE_URL>/rest/all/V1/eventing/eventSubscribe/observer.catalog_category_save_after'
```

## Unsubscribe from events

The `POST /rest/<store_view_code>/V1/eventing/eventUnsubscribe/<event_name>` endpoint unsubscribes from the specified event.

**Header:**

`Authorization: Bearer <administrator token>`

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 <AUTH_TOKEN>" \
'<ADOBE_COMMERCE_URL>/rest/all/V1/eventing/eventUnsubscribe/observer.catalog_category_save_after'
```

## Configure Commerce eventing

The `PUT /rest/<store_view_code>/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.
Expand Down
70 changes: 70 additions & 0 deletions src/pages/webhooks/api.md
Original file line number Diff line number Diff line change
@@ -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 <ADOBE_COMMERCE_URL>/rest/all/V1/webhooks/list \
--header 'Authorization: Bearer <TOKEN>'
```

0 comments on commit ea3cae8

Please sign in to comment.