Connecting the Salesforce Marketing Cloud API may seem technical, but it can be broken down into manageable steps. Here’s a more granular guide on how to do it:
1. Create an API Integration in Marketing Cloud
Start by logging into your Salesforce Marketing Cloud account.
Go to Setup by clicking on your profile icon in the upper right corner.
In the left-hand menu, under the ‘Platform Tools’ section, select Apps and then Installed Packages.
Click New to create a package and give it a relevant name (e.g., ‘WordPress Integration’).
After creating the package, navigate to the Components section and click Add Component. Choose API Integration, and select the appropriate permissions for your use case (read/write, etc.).
2. Generate API keys (Client ID and Client Secret)
Once the API Integration is set up, you’ll need to generate the API keys, which include the Client ID and Client Secret. These are unique identifiers that allow your external application (e.g. WordPress) to communicate securely with Marketing Cloud.
3. Authenticate your application
Now, you need to authenticate your application with Salesforce Marketing Cloud using the generated Client ID and Client Secret.
To do this, you’ll send a POST request to the Salesforce authentication endpoint. This can be done using tools like Postman or programmatically in your application.
The POST request should include your Client ID and Client Secret as well as grant-type information. The endpoint for authentication typically looks like this:
POST https://YOUR_SUBDOMAIN.auth.marketingcloudapis.com/v2/token
{
"grant_type": "client_credentials",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET"
}
4. Make API requests
With the access token in hand, you can now interact with Marketing Cloud via the API. Here is an example that will add data records (rows) to a specific Data Extension.
HEADER (this is where you give information about your call):
Content-Type: application/json
Authorization: Bearer ACCESS TOKEN
POST https://YOUR_SUBDOMAIN}.rest.marketingcloudapis.com/hub/v1/dataeventsasync/key:DATAEXTENSION-EXTERNALKEY/rowset
[
{
"keys": {
"SubscriberKey": "any unique key"
},
"values": {
"IsActive": true,
"FirstName": "John",
"LastName": "Smith",
"LastLogin": "2024-05-23T14:32:00Z",
"FollowerCount": 2
}
},
{
"keys": {
"SubscriberKey": "another unique key"
},
"values": {
"IsActive": true,
"FirstName": "Joan",
"LastName": "Smith",
"LastLogin": "2023-04-21T14:32:00Z",
"FollowerCount": 37
}
}
]
Replace YOUR_SUBDOMAIN with your unique Marketing Cloud subdomain, and include the necessary data for the specific action (e.g. sending an email, retrieving performance reports, or managing contact data).
Replace DATAEXTENSION-EXTERNALKEY with the external key of the Data Extension you wish to add data. This can be found by locating the Data Extension in the UI.
Create the json payload to deliver to Marketing Cloud. In the example we have here, we will be adding two records (John & Joan Smith). The values need to match fields in the target Data Extension. Just as in the UI, you should match the data type of each field, otherwise there will be an error.