generated from AdobeDocs/dev-site-documentation-template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
257 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ properties: | |
- Performance | ||
- REST | ||
- Security | ||
- Starter Kit | ||
- Tools | ||
- Upgrade | ||
- Webhooks | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
* Have an Adobe Developer account with System Administrator or Developer Role permissions. [Getting started with Adobe Developer Console](https://developer.adobe.com/developer-console/docs/guides/getting-started/) describes how to enroll in the Adobe developer program. | ||
|
||
* Be familiar with [Adobe I/O Runtime](https://developer.adobe.com/runtime/docs/guides/getting-started/). | ||
|
||
* Install the [`aio CLI`](https://developer.adobe.com/runtime/docs/guides/getting-started/setup/). | ||
|
||
* Have access to an Adobe Commerce on cloud infrastructure or to an on-premises instance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
title: Sample Code for Consuming Events | ||
description: View sample code demonstrating how to consume Commerce Events sent to Adobe I/O. | ||
keywords: | ||
- Events | ||
- Extensibility | ||
--- | ||
|
||
# Sample Code for Consuming Events Overview | ||
|
||
The sample code in this section demonstrates how to consume Commerce Events sent to Adobe I/O. |
90 changes: 90 additions & 0 deletions
90
src/pages/events/consume-events-examples/runtime-action-commerce-callback.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--- | ||
title: Runtime Action with a Callback to Commerce | ||
description: Provides details about how a runtime action can consume events and fetch additional details from Commerce. | ||
keywords: | ||
- Events | ||
- Extensibility | ||
--- | ||
|
||
# Runtime Action with a Callback to Commerce | ||
|
||
This example provides sample code for a runtime action that can consume an Adobe Commerce event and make an API call back to Commerce to obtain more information before sending data to a third-party system. | ||
|
||
## Runtime action example code | ||
|
||
You could use the following JavaScript code sample to create a runtime action for consuming `observer.sales_order_save_after` events. | ||
|
||
```js | ||
const { Core } = require('@adobe/aio-sdk') | ||
const { errorResponse } = require('../utils') | ||
const { getCommerceOauthClient } = require('../oauth1a') | ||
const { sendOrderToErpSystem } = require('../erp') | ||
|
||
async function main (params) { | ||
const logger = Core.Logger('main', { level: params.LOG_LEVEL || 'info' }) | ||
|
||
try { | ||
event_payload = params.data.value | ||
if (!event_payload.hasOwnProperty('extension_attributes')) { | ||
// Fetch extension attributes for order and add to order event payload | ||
const oauth = getCommerceOauthClient( | ||
{ | ||
url: params.COMMERCE_BASE_URL, | ||
consumerKey: params.COMMERCE_CONSUMER_KEY, | ||
consumerSecret: params.COMMERCE_CONSUMER_SECRET, | ||
accessToken: params.COMMERCE_ACCESS_TOKEN, | ||
accessTokenSecret: params.COMMERCE_ACCESS_TOKEN_SECRET | ||
}, | ||
logger | ||
) | ||
const content = await oauth.get('orders/' + event_payload.entity_id) | ||
event_payload.extension_attributes = content.extension_attributes | ||
} | ||
|
||
// Send event data to a third-party ERP system | ||
await sendOrderToErpSystem(event_payload) | ||
|
||
return { | ||
statusCode: 200, | ||
body: event_payload | ||
} | ||
} catch (error) { | ||
// log any server errors | ||
logger.error(error) | ||
// return with 500 | ||
return errorResponse(500, 'server error', logger) | ||
} | ||
} | ||
|
||
exports.main = main | ||
``` | ||
|
||
The `main` action first accesses the payload for a received `observer.sales_order_save_after` event: | ||
|
||
```js | ||
event_payload = params.data.value | ||
``` | ||
|
||
The event payload for this event could not contain the saved order's extension attributes. If needed, you can fetch the extension attributes for the specific order captured by the event using a Commerce API call: | ||
|
||
```js | ||
const oauth = getCommerceOauthClient( | ||
{ | ||
url: params.COMMERCE_BASE_URL, | ||
consumerKey: params.COMMERCE_CONSUMER_KEY, | ||
consumerSecret: params.COMMERCE_CONSUMER_SECRET, | ||
accessToken: params.COMMERCE_ACCESS_TOKEN, | ||
accessTokenSecret: params.COMMERCE_ACCESS_TOKEN_SECRET | ||
}, | ||
logger | ||
) | ||
const content = await oauth.get('orders/' + event_payload.entity_id) | ||
``` | ||
|
||
This example uses functions from the `oauth1a` module, as defined in the [adobe-commerce-samples repo](https://github.com/adobe/adobe-commerce-samples/blob/main/admin-ui-sdk/menu/custom-menu/actions/oauth1a.js). | ||
|
||
You can retrieve the `consumerKey`, `consumerSecret`, `accessToken`, and `accessTokenSecret` provided in the input to the `getCommerceOauthClient` function from Commerce after creating and activating an [Integration](https://experienceleague.adobe.com/en/docs/commerce-admin/systems/integrations) in the Commerce admin. You can configure these values in an App Builder [.env file](https://developer.adobe.com/app-builder/docs/guides/configuration/#env) and then [pass them as inputs to the App Builder action](https://developer.adobe.com/app-builder/docs/guides/configuration/#using-environment-variables-in-runtime-actions) through the action's configuration. | ||
|
||
You can now add the order's extension attributes retrieved from Commerce to the order event payload, and send the payload to a third-party Enterprise Resource Planning (ERP) system using a custom module. | ||
|
||
After creating a runtime action using this code, you can create an event registration can to subscribe to the `observer.sales_order_save_after` event, and configure the new runtime action to receive the event notifications. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: Consume Events | ||
description: Learn how to consume events sent from Adobe Commerce to Adobe I/O Events. | ||
keywords: | ||
- Events | ||
- Extensibility | ||
--- | ||
|
||
You can consume events sent from Adobe Commerce to Adobe I/O events in several ways. The following options for consuming events are available when adding events to your App Builder project and creating an event registration: | ||
|
||
* [Using the Journaling API](#using-the-journaling-api) (enabled by default) | ||
* [Using a Webhook URL](#using-a-webhook-url) | ||
* [Using a Runtime Action](#using-a-runtime-action) | ||
* [Using Amazon EventBridge](#using-amazon-eventbridge) | ||
|
||
## Using the Journaling API | ||
|
||
When you create an Adobe I/O event registration, the subscribed events added to an ordered list, referred to as the journal, by default. You can consume these events using a journaling endpoint URL that is unique to the registration. For more information on reading events from the journal, see the [Introduction to Journaling](https://developer.adobe.com/events/docs/guides/journaling_intro/). | ||
|
||
You can also consume events from the Journaling API using the [Adobe I/O Events SDK](https://github.com/adobe/aio-lib-events). See [Subscribe to Events Using Journaling](https://developer.adobe.com/events/docs/guides/sdk/sdk_journaling/) for details and sample code. | ||
|
||
## Using a Webhook URL | ||
|
||
Consuming an event using a webhook URL is useful for cases that do not require App Builder to handle transformations to the event structure or additional API calls, which simplifies forwarding events from Adobe Commerce to a 3rd-party system using App Builder. The destination system must have an endpoint that can receive webhook requests to use this option. | ||
|
||
You can register the webhook URL when creating or editing an event registration. If you are setting up the registration through the developer console UI, this option will appear in the final configuration step. | ||
|
||
![Webhook registration](../_images/events/register-webhook.png) | ||
|
||
See [Introduction to Adobe I/O Events Webhooks](https://developer.adobe.com/events/docs/guides/) for more details. | ||
|
||
<InlineAlert variant="warning" slots="text"/> | ||
|
||
Be careful not to confuse this method of consuming events with [Runtime Actions as a Webhook](https://developer.adobe.com/events/docs/guides/runtime_webhooks/#benefits-of-using-runtime-action-as-webhook). Runtime Actions as a Webhook is a functionality for creating a URL for App Builder to receive events from a 3rd party system. | ||
|
||
## Using a Runtime Action | ||
|
||
An [Adobe I/O Runtime Action](https://developer.adobe.com/runtime/docs/guides/overview/entities/#actions) allows you to receive Commerce events in an event registration. You can create actions from JavaScript functions, as described in [Creating Actions](https://developer.adobe.com/runtime/docs/guides/using/creating_actions/). Within an action, you can execute business logic based on the received event payload, make API calls back to Adobe Commerce to update data, access additional information, and send data to another system. | ||
|
||
See [Runtime Action with a Callback to Commerce](./consume-events-examples/runtime-action-commerce-callback.md) for an example of how a runtime action can consume an event and make an API call back to Commerce to get more information. | ||
|
||
See more examples of end-to-end integrations between Commerce and 3rd party systems like ERPs that use runtime actions in our [Starter Kit](https://developer.adobe.com/commerce/extensibility/starter-kit/send-data/) documentation. | ||
|
||
## Using Amazon EventBridge | ||
|
||
You can configure an Adobe I/O event registration to forward received Commerce events to Amazon EventBridge. See [Adobe I/O Events and Amazon EventBridge Integration](https://developer.adobe.com/events/docs/guides/amazon_eventbridge/) for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ keywords: | |
- API Mesh | ||
- Events | ||
- REST | ||
- Starter Kit | ||
- Tools | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ keywords: | |
- API Mesh | ||
- Events | ||
- REST | ||
- Starter Kit | ||
- Tools | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ keywords: | |
- API Mesh | ||
- Events | ||
- REST | ||
- Starter Kit | ||
- Tools | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ keywords: | |
- API Mesh | ||
- Events | ||
- REST | ||
- Starter Kit | ||
- Tools | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ keywords: | |
- API Mesh | ||
- Events | ||
- REST | ||
- Starter Kit | ||
- Tools | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ keywords: | |
- API Mesh | ||
- Events | ||
- REST | ||
- Starter Kit | ||
- Tools | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ keywords: | |
- API Mesh | ||
- Events | ||
- REST | ||
- Starter Kit | ||
- Tools | ||
--- | ||
|
||
|
Oops, something went wrong.