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:
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:
As shown above, let's check out the following 5 essential steps for the simple procedure:
Excited? Let's get started:
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:
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:
Configure the parameters – ensuring the destination is activated and employing the Default_Template as the support Destination Target:
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:
Now I can paste the unique URL as the destination URL of my new Consumed Destination, and click on Finish:
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.
I can observe that the dummy ping request has arrived in my webhook receiver site:
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.)
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:
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:
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.
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:
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):
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'):
I’ll also expose the “totalPrice” and the “user” (no need to check 'Unique' in this case):
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:
Now, I can save the newly created POJO integration object by clicking on Save on the top right.
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.
In the Webhook configuration wizard, I'll associate the POJO integration object with the Consumed destination.
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.
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:
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:
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
6 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |