---
schema_version: "1"
id: 8c973e20e7259a1f26a7c009e5404e119c459f6a2d9797f69be474ca61bbbed6
title: Salesforce Marketing Cloud Connector 5.0 Examples
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/salesforce-marketing-cloud-connector/latest/salesforce-mktg-connector-examples.md
canonical_url: https://docs.mulesoft.com/salesforce-marketing-cloud-connector/latest/salesforce-mktg-connector-examples
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 3c5ed1dd958304d08c617bec56e332fcae4cb71641c28a8a7a0e17b85504b1ee
description: MuleSoft Documentation Site
release: "5.0"
latest: true
---
---
product: Salesforce Marketing Cloud Connector
version: 5.0
is-latest-version: true
---

# Salesforce Marketing Cloud Connector 5.0 Examples

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

These examples show several Mule flows for Salesforce Marketing Cloud Connector:

- [Create a List](#create-list)

- [Retrieve a List](#retrieve-list)

## Configure a Connection

To secure connections, you must specify the connection field values. To do this:

- [Create a configuration file for a connection.](#create-config-file)

- [Configure the connection global elements.](#configure-conn)

- [Configure a global element for the properties file.](#configure-global)

### Create a Configuration File for a Connection

Create a configuration file that includes properties for a connection:

1.  Create a file named `mule-app.properties` in the `/src/main/resources/` folder.

2.  In the `mule-app.properties` file, create a set of properties for the connection, similar to the
    ones that follow, replacing the bracketed text (including the brackets) with the correct values
    for your configuration:

    config-with-oauth.clientId=<clientId used to initialize the connection>
    config-with-oauth.clientSecret=<clientSecret used to authenticate the user>
    config-with-oauth.soapEndpoint=<SOAP endpoint address>
    config-with-oauth.authEndpoint=<Authentication endpoint>

    This may vary depending on the selected connection configuration.

For more information about creating a properties file, refer to
[Configuring Property Placeholders](https://docs.mulesoft.com/mule-runtime/latest/mule-app-properties-to-configure).

### Configure the Connection Global Elements

Configure global elements for connection:

1.  Create a new Mule project.

2.  In the **Mule Palette** view, click **Search in Exchange** and enter
    `Salesforce Marketing Cloud`.

3.  Add **Salesforce Marketing Cloud Connector** to the **Selected modules** section and click
    **Finish**.

4.  Click the **Global Elements** tab and click **Create**.

5.  Select **Connector Configuration > Salesforce Marketing Cloud** and click **OK**.

6.  Enter the values to configure either Basic Authentication or OAuth Client Credentials.

7.  Click the **Test Connection** button to ensure there is connectivity with the Salesforce
    Marketing Cloud API. A successful message should pop up.

8.  Click **OK**.

9.  Open the HTTPS Listener config in **Global Element Configuration**.

10. Click the **TLS** tab and select TLS Configuration > Edit inline.

11. Specify the **Key Store Configuration** with the generated keystore details to enable HTTPS on
    this configuration.

12. Click **OK**.

### Configure a Global Element for the Properties File

Configure a global element for the `mule-app.properties` file so that Mule knows where to find it:

1.  Click the **Global Elements** tab and click **Create**.

2.  In the **Choose Global Type** dialog, select **Configuration properties** and click **OK**.

3.  In the **File** field, enter `mule.app.properties`.

4.  Click **OK**.

## Create a List

This Mule flow creates a list for storing subscribers.

> [!NOTE] The default value for the List type is `Public`, which makes the list visible to all
> subscribers. After creating the list, note the list ID to use it in other operations.

This example uses these operations:

- **HTTP Listener**  
  Accepts data from HTTP requests

- **Logger**  
  Shows the HTTP response from **HTTP Listener**

- **Transform Message**  
  Outputs the data in Java

  %dw 2.0 output application/java
  ---

  \[{

      ListClassification: payload.listClassification,
      ListName: payload.listName,
      "Type": payload.listType

  }\]

- **Create entities**  
  Creates new objects on the Salesforce Marketing Cloud API web server

  Enter the following values:

  <table><colgroup><col> <col></colgroup><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td><p><strong>Object type</strong></p></td><td><div><div><p><code>List</code></p></div></div></td></tr><tr><td><p><strong>Connector Configuration</strong></p></td><td><div><div><p><code>Salesforce_Marketing_Cloud_Sfdc_marketing_cloud_config</code></p></div></div></td></tr><tr><td><p><strong>Api objects</strong></p></td><td><div><div><p><code>payload</code></p></div></div></td></tr></tbody></table>

- **Transform Message**  
  Outputs the data in JSON

  output application/json
  ---

  payload

![Studio flow for the Create List operation](/mulesoft/current/en-us/salesforce-marketing-cloud-connector/latest/_images/salesforce-mktg-create-list.png)

### XML for This Example

Paste this code into the Studio XML editor to quickly load the flow for this example into your Mule
app:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:sfdc-marketing-cloud="http://www.mulesoft.org/schema/mule/sfdc-marketing-cloud"
      xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
      xmlns:http="http://www.mulesoft.org/schema/mule/http"
      xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
  http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/sfdc-marketing-cloud http://www.mulesoft.org/schema/mule/sfdc-marketing-cloud/current/mule-sfdc-marketing-cloud.xsd">

	<configuration-properties file="mule-app.properties" />
	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="2d500821-46be-4da2-a983-832ca1d829de" >
		<http:listener-connection host="localhost" port="8081" />
	</http:listener-config>

	<sfdc-marketing-cloud:config name="Salesforce_Marketing_Cloud_Sfdc_marketing_cloud_config" doc:name="Salesforce Marketing Cloud Sfdc marketing cloud config" doc:id="8c951adc-306a-4212-a33f-4be4b19a0076" >
		<sfdc-marketing-cloud:oauth-client-credentials-connection serviceUrl="${config-with-oauth-v2.serviceUrl}">
			<sfdc-marketing-cloud:oauth-client-credentials clientId="${config-with-oauth-v2.clientId}"
														   clientSecret="${config-with-oauth-v2.clientSecret}"
														   tokenUrl="${config-with-oauth-v2.tokenUrl}" />
		</sfdc-marketing-cloud:oauth-client-credentials-connection>
	</sfdc-marketing-cloud:config>

    <flow name="salesforce-marketing-cloud-oauth-demo-create-list-flow">
        <http:listener path="/create-list" doc:name="HTTP" config-ref="HTTP_Listener_config"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <ee:transform doc:name="Transform Message" doc:id="fab54a8d-4f2d-45cf-9496-9d407bf5837f" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
[{

	ListClassification: payload.listClassification,
	ListName: payload.listName,
	"Type": payload.listType
}]]]></ee:set-payload>
			</ee:message>
		</ee:transform>
        <sfdc-marketing-cloud:create config-ref="Salesforce_Marketing_Cloud_Sfdc_marketing_cloud_config" objectType="List" doc:name="Salesforce Marketing Cloud"/>
        <ee:transform doc:name="Transform Message" doc:id="a61ae2f3-0821-4884-9a4c-2306071c7ec8" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>
```

## Retrieve a List

This Mule flow retrieves the ID of a list to use in other operations.

This example uses the following operations:

- **HTTP Listener**  
  Accepts data from HTTP requests

- **Logger**  
  Shows the HTTP response from **HTTP Listener**

- **Transform Message**  
  Outputs the data in Java

  %dw 2.0 output application/java
  ---

  { query: "SELECT ID FROM List WHERE ListName ='" ++ payload.listName ++ "'" }

- **Retrieve entities**  
  Retrieves objects from the Salesforce Marketing Cloud API web server using an SQL query

  Enter these values:

  <table><colgroup><col> <col></colgroup><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td><p><strong>Connector Configuration</strong></p></td><td><div><div><p><code>Salesforce_Marketing_Cloud_Sfdc_marketing_cloud_config</code></p></div></div></td></tr><tr><td><p><strong>Query</strong></p></td><td><div><div><p><code>#[payload.query]</code></p></div></div></td></tr></tbody></table>

- **Transform Message**  
  Outputs the data in JSON format

  %dw 2.0 output application/json
  ---

  payload

![Studio flow for the Retrieve List operation](/mulesoft/current/en-us/salesforce-marketing-cloud-connector/latest/_images/salesforce-mktg-retrieve-list.png)

### XML for This Example

Paste this code into the Studio XML editor to quickly load the flow for this example into your Mule
app:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:sfdc-marketing-cloud="http://www.mulesoft.org/schema/mule/sfdc-marketing-cloud"
      xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
      xmlns:http="http://www.mulesoft.org/schema/mule/http"
      xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
  http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/sfdc-marketing-cloud http://www.mulesoft.org/schema/mule/sfdc-marketing-cloud/current/mule-sfdc-marketing-cloud.xsd">

	<configuration-properties file="mule-app.properties" />
	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="651f3647-d4c9-4536-8d6b-bee43c422625" >
		<http:listener-connection host="localhost" port="8081" />
	</http:listener-config>

	<sfdc-marketing-cloud:config name="Salesforce_Marketing_Cloud_Sfdc_marketing_cloud_config" doc:name="Salesforce Marketing Cloud Sfdc marketing cloud config" doc:id="7ef81352-ca1d-4134-bccb-b211a1951a60" >
		<sfdc-marketing-cloud:oauth-client-credentials-connection serviceUrl="${config-with-oauth-v2.serviceUrl}">
			<sfdc-marketing-cloud:oauth-client-credentials clientId="${config-with-oauth-v2.clientId}"
														   clientSecret="${config-with-oauth-v2.clientSecret}"
														   tokenUrl="${config-with-oauth-v2.tokenUrl}" />
		</sfdc-marketing-cloud:oauth-client-credentials-connection>
	</sfdc-marketing-cloud:config>

    <flow name="salesforce-marketing-cloud-oauth-demo-retrieve-list-flow">
        <http:listener path="/retrieve-list" doc:name="HTTP" config-ref="HTTP_Listener_config"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <ee:transform doc:name="Transform Message" doc:id="fe31d1a8-d189-4fbd-b96f-99c2eac092e1" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
	query: "SELECT ID FROM List WHERE ListName ='" ++ payload.listName ++ "'"
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
        <sfdc-marketing-cloud:retrieve doc:name="Salesforce Marketing Cloud" config-ref="Salesforce_Marketing_Cloud_Sfdc_marketing_cloud_config">
			<sfdc-marketing-cloud:query>#[payload.query]</sfdc-marketing-cloud:query>
		</sfdc-marketing-cloud:retrieve>
        <ee:transform doc:name="Transform Message" doc:id="d05834f2-3d96-4e95-bd3b-48057d4ca34e" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>
```

## See Also

- [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)

- [Salesforce Help](https://help.salesforce.com)
