This blog post is to demonstrate how to feed data on the SAP Emarsys from SAP CDC.
In this part, I demonstrate the developments on the SAP CPI that receives the customer data from SAP CDC, does the necessary transformations and enrichments, then send it to SAP Emarsys.
This blog demonstrates the following process:
This diagram briefly shows the process described above.
As described in the SAP Emarsys API documentation, their API requires a WSSE authentication. For this reason, I created the Emarsys security material with the user and password provided by the SAP Emarsys tenant administrator.
Products/Solutions/Services used:
As mentioned in the Process Flow, I created three Iflows:
This IFlow is used to generate the HTTP Header WSSE required by the SAP Emarsys API as the authentication method. It is called through the process direct adapter and expects to receive the message header SecureMaterial, which contains the SAP CPI security material ID used to generate the HTTP Header.
It is composed of three Groovy scripts that do the following:
There are 4 functions present in WsseHelper script with each having their own responsibility:
This IFlow receives the contact data from SAP CDC and stores it into Data Store.
The Iflows proceed as follows:
In this IFlow, we are picking the data from the above-mentioned data store and performing several steps to convert the data into Emarsys understandable format.
The steps are as follows:
Step 1. We are picking the data from the data store and converting it into XML format from JSON format as SAP CPI needs the data to be in XML format to perform the required operations.
Step 2. In the next step, we are storing “Email” into exchange properties from the payload and then making a “GET” call to Emarsys to check whether we already have a contact into our database with this email or not.
Step 3. In this step, we are saving the API call response in the exchange properties and routing the data to “Create contact (same)” IFlow or “Update Contact” IFlow based on the router condition.
Step 4. In this step, based on the country we are routing the contacts to normal opt-in or double opt-in depending on our requirements.
Step 5. If a contact is not from country where Double Opt-in is required then, it will enter the “Normal Opt-in” sub-IFlow. Otherwise, it will enter the Double Opt-in Sub-IFlow. For e.g.: Contact will enter DOI Flow only if it is from “DE” or “AT”.
Step 6. After entering the Opt-in Sub-IFlow, contacts will enter the mapping sub-IFlow via the process call and based on the router conditions, mapping will happen.
Step 7. After the mapping and gathering of data, it again gets converted into JSON format from XML format and then the data is sent to Emarsys after changing the header type to “application/json”.
Step 8. To trigger the DOI event for contacts entering double opt-in sub-IFlow, we are using Emarsys trigger event API.
Note: If a DOI event or Double Opt-in event is triggered for any contact, then that contact will receive one confirmation email asking for the confirmation of opt-in. If the contacts click on the confirm button, only then it’s opt-in will get changed to “True”.
DOI event will only be triggered for the contact if they are fulfilling the given router condition:
The payload for the API is stored in the content modifier:
And the API are:
Note: In the API, 457 is the event ID from Emarsys.
Note: In Emarsys, we had a requirement to maintain all the id origins i.e., to maintain the information about all the source system or to recognize all the source systems from where we have received the information for this contact.
Therefore, to maintain all ID origins of a particular contact in Emarsys, we came up with another custom solution.
Step 1. We created a multiple-choice field with the name “ID Origin” and inserted all the possible ID origin values.
Step 2. Created one sub-IFlow, to check the ID Origin from the payload and compare it with the existing Id Origin value in Emarsys using the Groovy Script after fetching the data from Emarsys using a Post API Call.
This script checks that whether we have the ID Origin from the payload already in Emarsys ID Origin field or not. If we already have that, then we don’t do change anything and send the same value again. If we have some new value which is not there in Emarsys field, then we append that value in the pre-existing values and then send it to Emarsys.
With this design, you will be able to replicate contacts in Emarsys from SAP CDC. If you have any queries, please drop a comment. Kindly like and share this blog if you find it helpful.
Thanks & Regards,
Aman Jain.