Integrating SAP Commerce and SAP Emarsys using Cloud Integration
This blog post is part of a series of blogs demonstrating how to feed data on the SAP Emarsys from SAP Commerce.
In this part, I demonstrate the developments on the SAP CPI that receives the customer data from SAP Commerce, does the necessary transformations and enrichments, then send it to SAP Emarsys.
My colleague Rodrigo Cardoso wrote a great blog showing how to enable this integration on the SAP Commerce Cloud.
The SAP CPI package with all the artifacts can be downloaded on GitHub.
This blog demonstrates the following process:
- A customer is created on the SAP Commerce, triggering an event;
- This event starts a job that sends the customer data to an iFlow on the SAP Cloud Integration through an HTTP post;
- This first iFlow transforms the data to the SAP Emarsys expected format and stores it on a JMS queue, making this replication process asynchronous;
- A second iFlow pools the JMS queue, fetch the data, and calls a third iFlow. This last iFlow is responsible for generating the HTTP Header WSSE necessary to authenticate in the SAP Emarsys tenant;
- The data is sent to the SAP Emarsys tenant.
This diagram briefly shows the process described above.
Import of Digital Certificates
The communication between the SAP Commerce, SAP CPI, and SAP Emarsys tenants use the HTTPS protocol.
The following steps are necessary to acquire and import the digital certificates on the SAP CPI tenant:
- Go to the Connectivity Tests app on the Integrations Monitor.
- Enter api.emarsys.net on the host, uncheck the Valid Server Certificate Required, and click on Send button;
- Download the digital certificate chain locally;
- Decompress the ZIP file locally;
- On the SAP CPI, open the Keystore app;
- Click on Add, Certificate;
- In the popup, click on browse and select the file on the image. This file is the root certificate and the only one necessary to establish the HTTPS connection between SAP CPI and SAP Emarsys;
- Execute steps 1 and 2 again, but with the flag, Valid Server Certificate Required checked. You must see a successful response.
Creation of Security Materials
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.
As mentioned in the Process Flow, I created three iFlows:
1. Receive Contacts from SAP Commerce
This iFlow receives the customer data from SAP Commerce, transforms this customer data to the SAP Emarsys contact data format, and stores the data on a JMS queue.
The iFlows proceed as follows:
- SAP Commerce sends the customer data using the HTTPS protocol (method POST). Just for simplicity, I disabled the CSRF protection;
- The Set Parameters step creates two parameters, SourceAgency and TargetAgency, in case of a value mapping usage;
- The generic Mapper step is a script that converts the customer data to the contact data format. It uses the POGOs concept described in Eng Swee Yeoh’s blog;
- Then the data is sent to a JMS queue, making the replication process asynchronous, as explained on Mandy Crimmel’s blog.
2. Replicate Contacts to SAP Emarsys
This iFlow pools the JMS queue, enriches the data, logs the customers processed, and calls the HTTP WSSE Header generator.
Also, this iFlow contains an exception subprocess with the necessary controls to retry to send the customer data to SAP Emarsys in case of failure.
The iFlow proceeds as follows:
- Pools the JMS queue, to fetch the contact data;
- Set the following message headers’:
- Secure Material – The secure material is an external parameter that must be set with the object created on step creation of security materials, this header is used by the HTTP WSSE Header generator iFlow.
- Set the following properties. These properties are externalized parameters to make the iFlow flexible.
- KeyId – This is the SAP Emarsys ID key field;
- ContactListId – The SAP Emarsys contact list ID to which the contact will be added;
- MaxRetries – Number of maximum retries if an error when sending the contact data to the SAP Emarsys fails.
- Set the message body with the format expected by the SAP Emarsys API;
- Logs the processed contacts, based on the SAP Emarsys ID key that is provided in the earlier step.
- Calls the HTTP WSSE Header generator passing the secure material on the message header.
- Send the contact data to the SAP Emarsys tenant.
3. Generating the HTTP Header WSSE
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:
- Fetch the SAP CPI security material data;
- Generates the HTTP Header WSSE.
Through the SAP CPI Monitor Messaging Processing app, you can check the processed messages.
To check all the related iFlows to a specific customer replication you can use the correlation ID that is shared between all the iFlows related to a message received from the SAP Commerce.
Also, as the iFlow that sends the contact data to SAP Emarsys logs the key ID, you can filter the messages based on the SAP Emarsys contact key ID, in this case, the field e-mail (id=3), and then obtain the correlation ID to find all the related messages.
Please, share your feedback and thoughts in a comment.
Also, take the time to visit my colleague Rodrigo Cardoso‘s profile to find out more information about the SAP Commerce and SAP Emarsys integration.
And, I encourage you to visit the SAP Emarsys Commerce Cloud Integration blogs to read other posts on this topic and the SAP Emarsys Commerce Cloud Integration questions to post and answer questions.
- Integration between SAP Commerce Cloud and CPI using Integration Object – one case with Emarsys
- Cloud Integration – Configure Asynchronous Messaging with Retry Using JMS Adapter
- Modularising CPI Groovy scripts using POGO
- SAP Emarsys API – Authentication
- SAP Emarsys API – Create Contacts
Thanks for the blog post David, more of that please! 🙂
Thank you for a detailed and informative blog on this topic, David Pietroniro 👍🏻
Great post David Pietroniro! Can you please also add the SAP Emarsys Customer Engagement tag so that more people will see this? Thanks!
Hi Will Young,
Thanks for your comment, and I added the tag that you mentioned.
Nice for the post david , Nice Info Good learning for us