Connecting to Salesforce Marketing Cloud with MuleSoft – Setting up Basic and OAuth Configurations – Part 1

In this article, we’ll walk-through the process of connecting to Salesforce Marketing Cloud (SFMC) using the SFMC Connector in Anypoint Studio. The SFMC connector provides two ways to connect; you can connect using Basic Authentication and with OAuth Client Credentials.

Tooling Versions

A. Basic Authentication

1. Setup Salesforce Marketing Cloud

Before we can connect to Salesforce Marketing Cloud, we need to gather some properties and make sure Salesforce Marketing Cloud is setup correctly.

1.1. Login to Salesforce Marketing Cloud, click on drop-down in the top right of the screen, and click on Setup

1.2 In the left-hand navigation bar, click on Settings > Company Settings > Account Settings

1.3 Under the General Settings section, copy down the SOAP Service Endpoint property. You’ll need this URL when you setup the connector in MuleSoft.

1.4 Next, we need to make sure the user can login with the connector using their username and password. By default this is set to No. In the left-hand navigation bar again, click on Settings > Security > Security Settings

1.5 Find the Enable Username and Password for Web Services field under the Username and Logins section. If it is set to No, click on Edit. Otherwise, skip to Section 2.

1.6 Check the checkbox next to Enable Username and Password for Web Services

1.7 Click on Save

2. Setup Connection Configuration

For the sake of keeping this article short, I’m not going to walk through the process of building out an entire flow. I’ll just show you how to configure the connection properties in order to see a successful connection test. 

2.1 In your Anypoint Studio project, open the properties tab for a Salesforce Marketing Cloud connector operation and click on the green plus sign to add a new Connector configuration for the connector.

2.2 In the Global Element Properties window, configure the following fields:

  1. Connection: Select Basic Authentication
  2. General Tab:
    1. Username: Salesforce Marketing Cloud username
    2. Password: Salesforce Marketing Cloud password
    3. Service URL: URL that you copied down from Section A1 > 1.3
      (e.g. https://<sub domain>.soap.marketingcloudapis.com/Service.asmx)

2.3 Click on Test Connection. If you’ve configured everything correctly, you should see the following window.

B. OAuth Client Credentials

1. Setup Salesforce Marketing Cloud

Instead of using a user account to connect, you can connect using OAuth Client Credentials. This section will walk you through the process of setting up an Installed Package to get the properties you need to setup the SFMC connector in MuleSoft.

1.1. Login to Salesforce Marketing Cloud, click on drop-down in the top right of the screen, and click on Setup

1.2 In the left-hand navigation bar, navigate to Platform Tools > Apps > Installed Packages

1.3 In the Installed Packages screen, click on New. Give the package a Name and Description and click on Save

1.4 Click on Add Component

1.5 Keep API Integration checked and click on Next

1.6 Select Server-to-Server and click on Next

1.7 Select the scopes that you want to make available to SFMC Connector to call and click on Save (e.g. Data > Data Extensions > Read and Write)

1.8 Back on the package details screen, copy down the following fields. We’ll need these to configure the SFMC Connector in MuleSoft.

  • Client Id
  • Client Secret
  • Authenticate Base URI
  • SOAP Base URI

2. Setup Connection Configuration

For the sake of keeping this article short, I’m not going to walk through the process of building out an entire flow. I’ll just show you how to configure the connection properties in order to see a successful connection test. 

2.1 In your Anypoint Studio project, open the properties tab for a Salesforce Marketing Cloud connector operation and click on the green plus sign to add a new Connector configuration for the connector.

2.2 In the Global Element Properties window, configure the following fields:

  1. Connection: Select OAuth Client Credentials
  2. General Tab:
    1. Service URL: This the SOAP Base URI from Section B1 > 1.8. Be sure to add /Service.asmx to the end of the URL
      (e.g. https://<sub domain>.soap.marketingcloudapis.com/Service.asmx)
  1. Client Id: Client ID from Section B1 > 1.8
  2. Client Secret: Client Secret from Section B1 > 1.8
  3. Token URL: Replace the {domain} placeholder with the string from your Authenticate Base URI from Section B1 > 1.8. Be sure to keep the /v2/token at the end of the URL.

2.3 Click on Test Connection. If you’ve configured everything correctly, you should see the following window.

Summary

Hopefully this helps you get started with the MuleSoft Salesforce Marketing Cloud connector and how to get connected. In the next article, I’ll show you how to use the connector to upload data to Data Extension objects in a Mule project. If you run into any issues or have any questions, don’t hesitate to reach out to me.


Comments

13 responses to “Connecting to Salesforce Marketing Cloud with MuleSoft – Setting up Basic and OAuth Configurations – Part 1”

  1. Catello Sabatino Avatar
    Catello Sabatino

    Hi thank you for this post. I’ve a issue when try to connect to Marketing Cloud. The message is: Illegal character in authority https://{domain}.auth.marketingcloudapis.com/v2/token. Can you help me?

    1. Just to be certain, did you change the {domain} to match your account domain?

      1. Catello Sabatino Avatar
        Catello Sabatino

        Hi, yes I change.
        However I’ve resolve the error. Thanks.

  2. Acknologia Avatar
    Acknologia

    Hi, I am trying to connect using OAuth Connection, I am able to run in local but when I am deploying it to clodhub, it’s failing to deploy.
    Error:
    our application has failed with exception java.lang.IllegalStateException: com.mulesoft.ch.services.agent.muleAgent.MuleAgentException: {“errorType”:”class java.lang.IllegalArgumentException”, “errorMessage”:”There was an error on the Mule Runtime while deploying the application abcd. Error: Failed to deploy artifact [abcd]. NoSuchElementException: partition with name _defaultPersistentObjectStore does not exist in store APP_abcd__defaultPersistentObjectStor

    1. Are you running this on 4.3.0? That might be related to this known issue – https://docs.mulesoft.com/release-notes/cloudhub/cloudhub-runtimes-release-notes#known-issues

      1. Acknologia Avatar
        Acknologia

        I am using 4.2.2 runtime. I know it’s something related to object store configuration in OAuth connection, Can you please help me out here?

        1. Try configuring the SFMC connector to use a separate ObjectStore instead of the default one. It’s in the oauthStoreConfig section of the SFMC connector configuration setting.

          1. Acknologia Avatar
            Acknologia

            I am unsure how to do that, I have attached the screenshot for reference.
            Thanks.
            https://uploads.disquscdn.com/images/badb7766432d60491b3ee375e32aed879e054d2d67b4b50be87fcc70d95de999.png

          2. That looks correct. To give you some quick background. If you don’t figure that, the app and CloudHub deployment uses the default ObjectStore. This just sets up a specific ObjectStore for this app. Have you tried deploying it now to see if you get the same error?

          3. Acknologia Avatar
            Acknologia

            I am still getting error but different error, which says client must be started before use.

            https://uploads.disquscdn.com/images/cb68b6bd861b0d6286bc39c09e6745e1c7d99ea11cbffc20d0a95c98c4439eb9.png

          4. It looks like you got past the ObjectStore issue. Are you using the same runtime version in Anypoint Studio as you are using in CloudHub? And are there any connectivity restrictions from the CloudHub (firewall, blocked ports, etc…)?

          5. Acknologia Avatar
            Acknologia

            Thanks a lot. The issue is sorted, yep it could be due to some port block

  3. […] Marketing Cloud (SFMC) using MuleSoft. In the previous articles, I showed you how to set up the connection configuration of the SFMC connector as well as how to push data to Data Extensions with the SFMC […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.