Technical Articles
Send personalized emails with SAP Customer Data Cloud webhooks and Kyma serverless functions
SAP Customer Data Cloud webhooks send out asynchronous event notifications to custom notification URLs when specific events occur in SAP Customer Data Cloud flows such as login, registration, and account update.
This post demonstrates an example in which event notifications for the subscription updated event are sent to a Kyma serverless function, which has a code snippet that implements some business logic to eventually send a personalized welcome email to users.
Two Kyma serverless functions are used in this example and they work together as explained below.
The first serverless function receives notification messages and has a code snippet to extract all the events from each message and post them to an SAP Event Mesh Queue.
The second serverless function has a code snippet to consume the events from the SAP Event Mesh Queue and process them as follows:
- First, it makes an accounts.getLiteToken REST API call to get a regToken that is required for the next step
- Next, it makes an accounts.getAccountInfo REST API call to get the user’s preferences
- Finally, it sends a personalized email to the user based on the user’s preferences using SendGrid Email Delivery Service
Note: All the functionality presented here are subject to change and may be changed by SAP at any time for any reason without notice.
Solution Architecture
Sequence Diagram
Source code repository
Here’s a link to the source code of this example.
Build and deployment steps
This example can be setup using SAP Customer Data Cloud and a free SAP BTP Trial account via the following steps:
Note: Click the links below for more details.
- Pre-requisites
- Step 1 – Pre-requisite SendGrid setup steps
- Step 2 – Create a lite registration screen in SAP Customer Data Cloud
- Step 3 – Deploy a Memcached memory-caching service
- Step 4 – Deploy the Webhook endpoint
- Step 5 – Deploy the Event Consumer Serverless Function
- Step 6 – Apply the Webhook Event Subscription
Verification steps
- Step 1 – Verify that all the resources of the app are running
- Step 2 – Subscribe for a newsletter and receive a customized confirmation email
Conclusion
This example shows how easy it is to extend SAP Customer Data Cloud using webhooks and SAP BTP, Kyma runtime. It also shows how to effortlessly and quickly create Kyma serverless functions using the Kyma console to add some simple code snippets without having to worry about the infrastructure details, which results in faster time to market as well as lower infrastructure total cost of ownership (TCO).
As a next step, you could explore the built-in observability tools of Kyma runtime for monitoring the serverless functions. With reference to this example, you could also try to create other Kyma serverless functions for your own use cases and implement SAP Customer Data Cloud webhook endpoints for some other events such as the account logged in or account updated events.
Kindly provide your feedback or feel free to ask clarifying questions related to this post in the comment section below. Additionally, I’d like to invite you to submit any broader Kyma related questions in the Q&A area of the SAP BTP, Kyma runtime topic.
If the SAP BTP, Kyma runtime topic interests you, here are some other links that you may like:
Lastly, if you liked this post, kindly hit the like icon, leave a comment below or share this post. Thank you!