Edit in GitHubLog an issue

Webhooks example

The Adobe Commerce Extensibility Starter Kit can use the Adobe Commerce webhook module to allow intercepting flows in Adobe Commerce.

This reference implementation makes a real-time query to a third-party system to determine whether the product a shopper placed in their cart is in stock.

Webhooks are enabled by default. If you initially disabled webhooks, you can reenable them by uncommenting the webhook section of the app.config.yaml file. Additionally, you will need to redeploy the project and repeat the onboarding process.

The runtime action included is in the Starter Kit package in the following location:

  • actions/webhook/check-stock/index.js

Configure webhook

Follow admin configuration to modify your webhook and define the connection between Adobe Commerce and your backoffice system using the observer.checkout_cart_product_add_before method.

Copied to your clipboard
{
"data": {
"cart_id": "cart id",
"items": [
{
"item_id": 1,
"sku": "Product SKU",
"qty": "Cart item qty"
}
]
}
}

Validation

The following parameters are required:

  • data
  • data.cart_id
  • data.items

Sample validation logic is provided in the following location in the Starter Kit package.

  • webhook\check-stock\validator.js

You can modify this file to add more validations to the validateData method, if necessary.

Business logic

The example runtime action webhook\check-stock\index.js references the checkAvailableStock() method in the webhook\check-stock\stock.js file. You must add custom business logic to the params in the stock.js file in order to test authentication with your third-party backoffice system.

You can also add custom responses.

Modify .env parameters

You can access any environment parameters from params. Add any required parameters to the actions/webhook/check-stock/actions.config.yaml under check-stock -> inputs:

Copied to your clipboard
check-stock:
function: check-stock/index.js
web: 'yes'
runtime: nodejs:16
inputs:
LOG_LEVEL: debug
HERE_YOUR_PARAM: $YOUR_CUSTOM_PARAMETER
annotations:
require-adobe-auth: false
final: true

Responses

Error response:

Copied to your clipboard
return {
statusCode: 200,
body: {
op: 'exception',
message: 'Error message'
}
}

Success response:

Copied to your clipboard
return {
statusCode: 200,
body: {
op: 'success'
}
}
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.