
This blog post provides a step-by-step guide on integrating SAP Sales Cloud V2 with SAP Emarsys using the SAP Integration Suite. The focus is on setting up a straightforward integration flow (iFlow) to extract contact data from SAP Sales Cloud V2 and create corresponding contacts in SAP Emarsys.
The goal is to demonstrate how to connect both systems, using APIs and middleware to automate data transfer. This serves as a foundation for more complex integrations in the future, making it easier to extend the process with additional functionality. A key aspect of this integration is OpenID Connect (OIDC, OAuth 2.0, JWT) based API authentication, which is required to securely access SAP Emarsys. We will cover how authentication works in this context and how to configure it properly within the iFlow.
Before implementing this iFlow ensure that you have the following:
Overview of the iFlow between SAP Sales Cloud V2 and SAP Emarsys using SAP Integration SuiteThe diagram above provides an overview of the iFlow, which connects SAP Sales Cloud V2 with SAP Emarsys using the Cloud Integration component within the SAP Integration Suite. This process automates retrieving contact data from SAP Sales Cloud V2, processes the information, and transfers it to SAP Emarsys to create corresponding contacts.
In the following sections, each step of the iFlow will be explained in detail.
The iFlow is initiated by a timer-based trigger, which ensures that contact data is regularly synchronized between SAP Sales Cloud V2 and SAP Emarsys.
As shown in the screenshot, the timer is configured using a Simple Schedule, where the iFlow runs every hour between February 27, 2025, at 09:00 UTC and March 6, 2025, at 18:00 UTC.
Configure SAP Sales Cloud V2 Request
In this step, we apply a filter to ensure that only the necessary contacts are fetched from SAP Sales Cloud V2. First, we limit the selection to contacts associated with the United States. Second, we include only those that have been newly created or updated within the last hour.
After adding the timer to trigger the iFlow, the next step is to insert a Content Modifier to define the query parameters for retrieving the relevant contact data.
The filter dynamically adjusts the timestamp to the beginning of the current hour, ensuring that each execution of the integration flow retrieves only the latest contact records.
To retrieve contact data from SAP Sales Cloud V2, we need to set up a Request Reply and connect it to an HTTP Receiver Adapter. This ensures that the iFlow sends a request to SAP Sales Cloud V2 and processes the response dynamically.
The Request Reply step is required to handle synchronous communication with SAP Sales Cloud. It ensures that the request is sent, and the response is processed before moving to the next step in the iFlow.
The HTTP Receiver Adapter is responsible for sending the request to SAP Sales Cloud V2. The configuration is as follows:
Configure the connection to SAP Sales Cloud V2
The dynamic filter query that was set up in the Content Modifier is passed automatically in the request to ensure only relevant contact data is retrieved.
In this step, we process the contact data retrieved from SAP Sales Cloud V2, extract the relevant fields, and format them for further use in the integration. To achieve this, we use a Groovy script that structures the data according to SAP Emarsys' requirements. For simplicity, this example extracts only the first name, last name, and email address, but additional fields can be included as needed.
import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.json.JsonSlurper;
import groovy.json.JsonOutput;
def Message processData(Message message) {
def body = message.getBody(String)
def jsonSlurper = new JsonSlurper()
def jsonResponse = jsonSlurper.parseText(body)
if (!jsonResponse || !jsonResponse.value || jsonResponse.value.isEmpty()) {
throw new RuntimeException("No contact data found. API Response: " + body)
}
def contactsList = jsonResponse.value.collect { contact ->
return [
"3": contact.eMail ?: "",
"1": contact.givenName ?: "",
"2": contact.familyName ?: ""
]
}
def emarsysPayload = [
key_id: "3",
contacts: contactsList
]
message.setProperty("EmarsysBody", JsonOutput.toJson(emarsysPayload)) // Store entire JSON in a property
return message;
}
We start by retrieving the API response as a string and parsing it into a JSON object. If no contacts are found, we throw an exception to prevent unnecessary API calls.
Next, we extract the key attributes needed for SAP Emarsys. In this example, we focus on:
We iterate over the contact list and map each contact’s attributes into a structured format. If any of these fields are missing, we assign an empty string to ensure consistency in the data structure.
Once we have extracted the required fields, we structure the data into a JSON payload that SAP Emarsys can process. Since SAP Emarsys uses the email address as the unique identifier, we set the key_id to 3
Finally, we store the structured JSON in a message property (EmarsysBody), making it available for the next step in the iFlow.
In this step, we prepare the data extracted from SAP Sales Cloud V2 for submission to the SAP Emarsys API. This involves setting up a Content Modifier and configuring the necessary OpenID Connect (OIDC, OAuth 2.0, JWT) based API authentication using the Integration Suite.
First, add a Content Modifier step in the iFlow after the Groovy script. The purpose of this step is to store the payload that will be sent to the SAP Emarsys API.
Before creating the new headers, delete the existing CamelHttpQuery header to avoid conflicts with the new request configuration. To do this, add a new row in the Message Header section and select Delete as the action. Enter CamelHttpQuery as the header name and leave the other fields empty.
HTTP headers for Emarsys request and OAuth authentication
Next, we need to add the required headers for the OAuth 2.0 request and data exchange with the SAP Emarsys API:
Next, we need to define the message body that will be sent to the SAP Emarsys API. This body contains the structured contact data extracted and formatted in the Groovy script:
To connect to the SAP Emarsys API, you need to configure OAuth 2.0 authentication in the Integration Suite. This is done by setting up OAuth 2.0 Client Credentials in the Security Material.
Configuring Security Material for Emarsys Authentication
You can obtain the OAuth 2.0 credentials directly from SAP Emarsys or configure them using OpenID Connect with SAP Cloud Identity. For detailed steps on setting up credentials via OpenID Connect, refer to the official SAP Emarsys documentation here.
Alternatively, you can create API credentials directly in SAP Emarsys. You can find the detailed steps here. Ensure that the Token Service URL is correctly set to the SAP Emarsys token endpoint.
When configuring OAuth 2.0 credentials in the Security Material of the Integration Suite, make sure to populate the SCOPE field (e.g.'api'). Missing scope values can lead to authentication errors. For more details on setting up OAuth 2.0 authentication, refer to this SAP Community blog.
In this step, we create new contacts in SAP Emarsys using the extracted and formatted data from SAP Sales Cloud V2. To achieve this, we need to configure a Request Reply Step and an HTTP Receiver Adapter to send the contact data to SAP Emarsys.
At this point, the contact data extracted from SAP Sales Cloud V2 is ready to be created in SAP Emarsys. The HTTP Receiver Adapter sends the formatted data as a POST request to the SAP Emarsys API.
After setting up the iFlow and configuring all necessary steps, we can now test the integration to confirm that contact data is successfully transferred from SAP Sales Cloud V2 to SAP Emarsys.
To validate the integration, we start by creating a new contact in SAP Sales Cloud V2. In this example, a contact named Emma Evans with the email address emma.evans@alpha.cx.demo.sap was created in SAP Sales Cloud V2.
Next, we search for the newly created contact in SAP Emarsys using the email address. As shown in the screenshot, the search returns no results, confirming that the contact is not yet present in SAP Emarsys.
We then manually trigger the iFlow to push the newly created contact from SAP Sales Cloud V2 to SAP Emarsys. The iFlow sends a POST request to the SAP Emarsys API with the contact details extracted and formatted in the previous steps.
Finally, we search for the contact in SAP Emarsys again using the email address. This time, the contact is successfully found, confirming that the data transfer was successful. The contact's first name, last name, and email address are correctly displayed in SAP Emarsys, indicating that the iFlow is working as expected.
In this post, we walked through the process of setting up an end-to-end integration between SAP Sales Cloud V2 and SAP Emarsys using the Cloud Integration component within the SAP Integration Suite. We started by configuring the connection to SAP Sales Cloud V2, filtering the data to retrieve only relevant contacts, and extracting the necessary fields using a Groovy script. We then prepared the data for SAP Emarsys, set up OpenID Connect (OIDC, OAuth 2.0, JWT) based API authentication, and sent the data to SAP Emarsys using an HTTP Receiver Adapter.
The successful execution of the integration was confirmed when the contact created in SAP Sales Cloud V2 appeared in SAP Emarsys after the process ran. This demonstrates how easily the SAP Integration Suite can be used to connect SAP Sales Cloud V2 and SAP Emarsys - laying the foundation for more complex processes in the future.
By following these steps, you can build a similar integration in your environment, adapting the filter conditions and field mapping to meet your specific business needs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |