Send Transactional Messages Through On-Demand Flow
Use API-triggered transactional messaging to send prioritized, personalized messages, such as one-time passwords (OTPs) or order confirmations, from Marketing Cloud Next. By using REST API to invoke an On-Demand Flow, you can securely pass dynamic data at send time and deliver time-sensitive service communications exactly when they’re needed.
Before you begin, make sure that you have:
- Permissions to create Apex Classes, CMS Email content, Flows, and external client apps
- Ability to authenticate and invoke REST APIs
- A data source for personalization, such as an Apex class or a data graph from Data 360
Using a data graph as the personalization data source can increase the latency of your requests.
To pass real-time personalization values into the email at send time, define a data source that the Flow and email can reference.
In this example, an Apex class defines the input structure for personalization fields, such as first name and OTP code.
- In Setup, enter Apex Classes in Quick Find.
- Click New.
- Create an Apex Class that defines the required input variables required for the transactional message.
- Save the class. The Apex Class exposes variables that are later mapped in the Flow and populated through the REST API request.
Create transactional email content as CMS content and configure it with the correct data source.
- Create the Email:
- Go to Marketing App > Content.
- Click Add CMS Content and select Email.
- Open the email in Email Builder.
- Connect the data source:
- In the Email Builder, add a new data source and select Apex Data Provider.
- Choose the Apex Class that you created.
- Design the email body:
- Insert merge fields (for example, FirstName or otpCode) from the Apex Data Provider.
- Set Message Purpose to Transactional.
- Save and publish the email.
CMS channels represent publishing endpoints such as email. Publish transactional emails before you use them in a Flow.
The REST API calls the On-Demand Flow, which defines the send logic.
- Create the Flow:
- Go to the Flow tab and click New.
- Select On-Demand Flow (launched by REST API).
- Add the Apex resource:
- In the Toolbox, click New Resource.
- Set Resource Type to Variable.
- Set Data Type to Apex-Defined.
- Select your personalization class as the Apex Class.
- Turn on Available for Input. Save the API Name of this resource. You need this value when you construct the REST API request.
- Add Send Email as the first Flow element.
- Select the published transactional email.
- Configure the sender and activate the Flow.
- Save and activate the Flow.
To invoke the Flow, you must authenticate using OAuth and then call the Flow action endpoint.
- In Setup, search for
client app, and then select External Client App Manager. - Click New External Client App.
- Enter a name for the app and a contact email address.
- Enable OAuth Settings.
- Enter a Callback URL.
- Add these OAuth scopes:
- Full access (full)
- Manage user data via APIs (api)
- Save your changes.
After you save the app, open Manage Consumer Details and record the Consumer Key and Consumer Secret.