CRM and CX Blogs by SAP
Stay up-to-date on the latest developments and product news about intelligent customer experience and CRM technologies through blog posts from SAP experts.
cancel
Showing results for 
Search instead for 
Did you mean: 
cuikenjian
Product and Topic Expert
Product and Topic Expert
1,528

Hello and welcome to another exciting blog post where I'll be sharing a detailed process for creating a webhook with a POJO Integration object using the SAP Commerce Cloud’s Integration API module.

Before we delve in, it's worth noting that this post is targeted towards working with the Webhook and POJO Integration objects in the Integration API module. Should you desire a deeper exploration of the Integration API module, consider joining our expert-led live session: Configuring the Integration API Module in SAP Commerce Cloud (2 hours live sessions with fundamental introduction, demos and Q&A)

For context:

  • Webhooks provide a mechanism for SAP Commerce Cloud to send notifications to configured URLs every time an item is saved (created or updated) or deleted.
  • Meanwhile, POJO integration objects are used to model outbound business events (excluding item-specific events, but custom events included).

To integrate these two features together, by following the procedure outlined below, an Order Placed Event will be automatically triggered each time an order is placed on SAP Commerce Cloud’s storefront, thereby publishing a notification to the configured default destination:

Screenshot 2024-05-20 at 10.43.00.png

As shown above, let's check out the following 5 essential steps for the simple procedure:

  1. Preparation - prepare SAP Commerce Cloud 2211 (and optionally Composable Storefront 2211)
  2. Creating a test Consumed Destination - to receive the webhook notification
  3. Creating a POJO Integration Object - to contain the configuration of the to be published notification
  4. Creating a Webhook Configuration - to connect the Consumed Destination and the POJO Integration Object
  5. Validating the Webhook publishing - to see everything come together

Excited? Let's get started:

STEP 1: PREPARATION

Kindly include the Integration API module in the SAP Commerce Cloud system (I am using 2211.23). If you're unsure about what extensions to incorporate, consider including the 'integrationmonitoringbackoffice' and the 'webhookbackoffice' extensions in your localextensions.xml (or manifest.json).

We will be tracing the 'order placed' event in this blog post, using the Composable Storefront for the purpose. That’s why I also included the spartacussampledata extension and used it with the Composable Storefront 2211. However:

  • this isn't limited to tracking any other business event, even custom events included.
  • if you just want to have a test, an Accelerator Storefront can also be used, just keep in mind that ACC storefront will be removed soon.

STEP 2: CREATING A TEST CONSUMED DESTINATION

With the preliminary tasks completed, let's start SAP Commerce Cloud and navigate to the Backoffice. Locate the “Consumed Destinations” node in the administrative cockpit and create a new one:

Screenshot 2024-05-20 at 10.56.13.png

Configure the parameters – ensuring the destination is activated and employing the Default_Template as the support Destination Target:

Screenshot 2024-05-20 at 10.57.53.png

To set the value for the destination URL, I’ll need to utilize the https://webhook.site. Let me open a new tab and go to https://webhook.site to get the unique URL for my temporary test receiver site. I’ll copy it:

Screenshot 2024-05-20 at 11.00.27.png

Now I can paste the unique URL as the destination URL of my new Consumed Destination, and click on Finish:

Screenshot 2024-05-20 at 11.01.55.png

I can test whether my webhook receiver site can receive a dummy message from the configured Consumed Destination in Backoffice. I’ll just choose it and click on the “ping destination” icon.

Screenshot 2024-05-20 at 11.03.06.png

I can observe that the dummy ping request has arrived in my webhook receiver site:

Screenshot 2024-05-20 at 11.04.09.png

STEP 3: CREATING A POJO INTEGRATION OBJECT

Next, I will create a new POJO integration object using the Integration UI Tool. Since I’m dealing with a POJO integration object, the Class Modeling node under Integration Object Modeling will be the one to select (Remember that a typical Integration Object can also operate with Webhooks. If you wish to test this, go for the Type Modeling node instead.)

To generate the new POJO integration object, select the +(create) icon. (Please keep in mind that clicking the create icon for the first time might take longer as all Business Event classes will need to load and display.)

Screenshot 2024-05-20 at 11.08.39.png

When naming the new object, I will select OrderPlacedEvent as the root class, but feel free to opt for any other Event Class, anything that suits your testing purposes. Click 'Create' to establish the POJO integration object:

 

Screenshot 2024-05-20 at 11.11.32.png

Don’t worry if a warning message pops up- it simply means the integration object needs further configuration to be ready. In this case, at least one unique key is required:

Screenshot 2024-05-20 at 11.11.48.png

Here, I'll mark the process as the unique key (remember to scroll to the right and check the Unique box) and try to save the object.

Screenshot 2024-05-20 at 11.14.24.png

Attempting to save at this moment will yield an error (see below) because when using an attribute of a composed type as a unique key, the object value of the attribute must contain a minimum of one unique key:

Screenshot 2024-05-20 at 11.14.59.png

The solution? Select the "process" under the OrderPlacedEvent on the left, then mark “code” as the unique key (remember to scroll to the right and check the Unique box):

Screenshot 2024-05-20 at 11.22.14.png

I'll further expose the "order" as shown above, just just for a nicer display later. Since the same principle applies, I’ll flag at least one unique key for the order attribute. I'll expand the process attribute and choose "order", then mark the code as unique (remember to scroll to the right and check 'Unique'):

Screenshot 2024-05-20 at 11.25.14.png

I’ll also expose the “totalPrice” and the “user” (no need to check 'Unique' in this case):

Screenshot 2024-05-20 at 11.27.44.png

Still because of the same reason, I’ll need to mark at least one unique key for the User type as well. So I will expand the order attribute (very important, don't forget this step) and choose the user attribute under the order type, and mark the “uid” attribute unique, and also expose the “name” attribute as well:

Screenshot 2024-05-20 at 11.30.41.png

Now, I can save the newly created POJO integration object by clicking on Save on the top right.

STEP 4: CREATING A WEBHOOK CONFIGURATION

All the necessary components are now set up. We can proceed to connect the POJO integration object to the Consumed destination created earlier.

While still in the Integration UI Tool, I'll select the Webhooks node, then click on the +Create icon.

Screenshot 2024-05-20 at 11.35.07.png

In the Webhook configuration wizard, I'll associate the POJO integration object with the Consumed destination.

Screenshot 2024-05-20 at 11.36.04.png

The event type is auto-filled, indicating that when an event of this specific type is published within the SAP Commerce Cloud, it will also be published to the Consumed destination. Let's test this in the next step.

STEP 5: VALIDATING THE WEBHOOK PUBLISHING

I will visit Composable Storefront and register a test user account. I will then add any arbitrary product to the shopping basket, proceed, and complete the checkout:

Screenshot 2024-05-20 at 11.40.44.png

If you don't have Composable Storefront installed, you can use the Accelerator storefront for testing purposes. However, keep in mind that Accelerator storefronts will soon be removed from SAP Commerce Cloud.

After the order is placed, we can return to https://webhook.site. At this point, we should observe that the 'order placed event' has been published to the site, complete with the same information that was previously exposed in the POJO integration Object:

Screenshot 2024-05-20 at 11.41.44.png

 

And there you have it, a user-friendly step-by-step process to creating a simple Webhook with a POJO Integration Object in SAP Commerce Cloud.

If this blog post has been beneficial, kindly show your support by liking the post, or give me a follow to access more content related to SAP Commerce Cloud. I appreciate your time and look forward to your feedback.

Happy Learning!

1 Comment