Skip to content

Salesforce Marketing Cloud Access Token Generation

This guide explains how to generate an access token in Salesforce Marketing Cloud using an Installed Package. Follow the steps below for a complete walk through from creating the package to obtaining the token using tools like Postman or curl.

Step 1: Log in to Marketing Cloud

  1. Navigate to your Salesforce Marketing Cloud login page and log in with your credentials.

SFMC login

  1. Once logged in, click on your username in the top right corner and select Setup from the dropdown menu.

SFMC setup

Step 2: Create an installed package

  1. In the Setup menu, scroll down to the Platform Tools section.
  2. Click on Apps and then select Installed Packages.

SFMC installed packages

  1. Click the New button.
  2. Enter a Name and Description for your package (for example, API Integration Package).
  3. Click Save.

SFMC installed package component

Step 3: Add an API integration component

  1. After saving, click on the package you just created to view its details.

SFMC installed package component details

  1. Click on Add Component.
  2. Choose API Integration as the component type.

SFMC installed package component type

  1. Select Server-to-Server as the integration type.

SFMC installed package integration type

  1. In the list of available scopes, check the required permissions for your integration. For most token generation and API calls, you might need:
  2. Read and Write access to Email Studio
  3. Access to the REST API
  4. Any additional scopes based on your specific use case

    SFMC component scopes

  5. Click Save to add the component.

Step 4: Retrieve the Client ID and Client Secret

On the package detail page, note down the Base URIs, Client ID and Client Secret generated for your integration. These credentials are required to authenticate API calls. If necessary, click on Edit to update any integration details or to add further scopes.

SFMC client secret

SFMC client id

Step 5: Retrieve your user subdomain (Required for setting up MI)

Extract the subdomain by taking the portion between https:// and .auth.marketingcloudapis.com in your base URI. For example, from https://mczl3z3cmqr47kmts5x34v1cdlky.auth.marketingcloudapis.com/, the subdomain is mczl3z3cmqr47kmts5x34v1cdlky.

Step 6: Obtain the access token

To generate the access token, you need to make an HTTP POST request to the Salesforce Marketing Cloud authentication endpoint you retrieved in Step 4.

  1. Your Authentication Base URI typically looks like:
   https://YOUR_SUBDOMAIN.auth.marketingcloudapis.com/
  1. Replace YOUR_SUBDOMAIN with the subdomain provided in your Salesforce Marketing Cloud account (found in your account details).
  2. Construct the token request:

The token endpoint is:

   https://YOUR_SUBDOMAIN.auth.marketingcloudapis.com/v2/token

  1. The POST request must include your Client ID and Client Secret along with the grant_type set to client_credentials.

  2. Using Postman:

Open Postman and create a new POST request. Set the URL to:

   https://YOUR_SUBDOMAIN.auth.marketingcloudapis.com/v2/token

In the Body tab, select raw and JSON as the format, then enter:

{
   "grant_type": "client_credentials",
   "client_id": "YOUR_CLIENT_ID",
   "client_secret": "YOUR_CLIENT_SECRET"
}

Click the Send button. The response will include an access_token along with its expiration time.

  • Using curl:

Open your terminal and run the following command (replace placeholders with your actual values):

   curl -X POST \
     https://YOUR_SUBDOMAIN.auth.marketingcloudapis.com/v2/token \
     -H "Content-Type: application/json" \
     -d '{
           "grant_type": "client_credentials",
           "client_id": "YOUR_CLIENT_ID",
           "client_secret": "YOUR_CLIENT_SECRET"
         }'
The output will be a JSON object that contains your access token.

  1. Verify the token:

Confirm that your response includes an access_token. Save the token securely. It is valid for the duration specified in the response and will be required for subsequent API calls.

Note

WSO2 MI will handle token generation and expiration internally. You only need to provide the Client ID and Client Secret in your API configuration.