Send transactional emails from Salesforce Marketing Cloud through its REST API, from any external tool such as SOAP UI or Postman.
Authenticate with the client credentials of an API Integration package to get an access token, then call the transactional messaging endpoint of your instance.
Preparation
Create client id & secret on Installed Packages>Components βAPI Integrationβ /cloud/#app/Setup/InstalledPackages.
Walkthrough
Get token
Create a request with the client id & secret from the preparation, endpoint https://xxx.auth.marketingcloudapis.com/v2/token and the following body:
{
"grant_type": "client_credentials",
"client_id": "[client id]",
"client_secret": "[client secret]",
"scope": "email_read email_write email_send",
"account_id": "[account id]"
}Response:
{
"access_token": "eyJhbGciOiJIUzI1NiIsxxx",
"token_type": "Bearer",
"expires_in": 1079,
"scope": "email_read email_write email_send",
"soap_instance_url": "https://xxx.soap.marketingcloudapis.com/",
"rest_instance_url": "https://xxx.rest.marketingcloudapis.com/"
}REST Call
- Create another request with the endpoint set as the previous
rest_instance_url - Use below request with endpoint
[rest_instance_url]messaging/v1/email/messages/
{
"definitionKey": "[transactionalDefKey]",
"recipients": [
{
"contactKey": "[contactId]",
"to": "[contactEmail]",
"attributes": {
"FirstName": "John",
"LastName": "Doe"
}
}
]
}Response:
{
"requestId": "xxx",
"errorcode": 0,
"responses": [
{
"messageKey": "xxx"
}
]
}Going further
- Apex cheatsheet: call this REST API from Apex (POST to REST API)
- Salesforce SOAP API: the equivalent external calls for Service Cloud
- Marketing Cloud SQL data model: tables to query the sends