Skip to main content

Stay Secure with Access Tokens

Learning Objectives

After completing this unit, you’ll be able to:

  • Integrate with a Marketing Cloud Engagement API securely.
  • Use access tokens for both REST and SOAP APIs.
  • Know when to refresh your tokens.

Get Your Token

At Salesforce, we take security seriously. And the Marketing Cloud Engagement REST and SOAP APIs are no exception. Marketing Cloud Engagement provides tenant-specific endpoints to help secure your API requests (more on this in a minute). Plus, you’re required to use OAuth tokens to access these endpoints.

To get those endpoints and tokens, you need to do a few things. Both the REST and SOAP APIs require an API integration with Marketing Cloud Engagement using an installed package. After you create the installed package in your Marketing Cloud Engagement account, you can request an access token using your client ID and secret. Any application that you create extracts that token and uses it to gain access to Marketing Cloud Engagement resources. Let’s walk through creating an installed package and finding your endpoints.


The examples in this unit use the REST API—since it’s the preferred way to interact with Marketing Cloud Engagement.

Create an Installed Package

Marketing Cloud Engagement uses installed packages to help authenticate users and API requests. For this step, you need access to your Marketing Cloud Engagement account. (Contact your Marketing Cloud Engagement admin for help.)

  1. In Marketing Cloud Engagement, go to Setup.
  2. Click Apps.
  3. Click Installed Packages.
  4. Click New.
  5. Give the package a name and description.
  6. Create the package with enhanced functionality.
  7. Save the package.
  8. Under Components, click Add Component and select API Integration.
  9. Select an integration type.
    • Server-to-Server with Client Credentials Grant Type
    • Web and Public App Integrations with Authorization Code Grant Type
  10. Set the integration properties, including scopes and the redirect URIs for web and public apps. Use as a valid redirect URI for local testing.
  11. Save the component.

Discover Your Endpoints

As we mentioned earlier, our APIs use tenant-specific endpoints. That means, instead of directing all requests to a single endpoint, your endpoints include a subdomain unique to your tenant. This also improves performance for your API requests by reducing the amount of traffic on any one endpoint. Faster and more secure—that’s a win-win.

Your Marketing Cloud Engagement account contains the information you need to implement your endpoints. If you can’t directly access the account, contact your Marketing Cloud Engagement admin for the information you need to get started.

Server-to-Server Integrations

Use server-to-server integrations to set up REST or SOAP API interactions between Marketing Cloud Engagement and your system. You can set up your integration in just three steps.

Step 1—Request an access token using a client ID and secret.

Installed packages generate these values for you when you create the integration. This example shows the information included in this REST API request. Store your client ID and secret securely. Never expose this information on the client side via JavaScript and don’t store it in a mobile application.

POST /v2/token
Content-Type: application/json
"grant_type": "client_credentials",
"client_id": "7a9j47upktedde30uedl822p",
"client_secret": "1955278925675241571",
"scope": "email_read email_write email_send",
"account_id": "12345"

Step 2—Marketing Cloud Engagement returns an access token.

Extract this token for your use. Give this token the same care and protection that you do for a username and password. In other words, don’t post it on a public message board or leave it on an unencrypted document in your system.

HTTP/1.1 200 OK
"scope": "email_read email_write email_send"

Step 3—Access your REST and SOAP API resources.

You’re good to go! Start planning and writing your requests.

Web and Public Integrations

Use this method to allow a specific user to access your app using authorization from Marketing Cloud Engagement. A web app can securely store a client secret, but a public app cannot.

Step 1—Redirect the User Web Browser to Marketing Cloud Engagement.

Include code in your app to perform the redirect to the Marketing Cloud Engagement authorization URL for your integration. Take a look at this example.

Step 2—Extract the authorization code.

A successful authorization returns a response containing an authorization code. Extract that code from the response, which appears like this.{YOUR_MARKETING_CLOUD_SUBDOMAIN}

Step 3—Request a token.

The request for the token looks like this. 

POST /v2/token
Content-Type: application/json
   "grant_type": "authorization_code",
   "client_id": "7a8j47upktedde30uedl822p",
   "client_secret": "lYkAjPxnmHP4Zarpv1U4cLf0"
   "redirect_uri": "",
   "scope": "email_read email_write email_send offline"

That request prompts Marketing Cloud Engagement to return the token. Again, take the utmost care to protect this token.

HTTP/1.1 200 OK
   "scope": "email_read email_write email_send"

Step 4—Access your REST and SOAP API resources.

Once you have your tokens in place, you’re ready to implement some REST or SOAP API requests! 

Now that you can securely access both of the APIs, let’s take a closer look at each one. First up: the REST API.


Keep learning for
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities