Send WhatsApp Transactional Messages Through Direct Send API
This Page
All Documentation
Use Direct Send APIs to send transactional WhatsApp messages to one or more phone numbers. Each message is the published WhatsApp template or session content that’s linked to the send definition, and you personalize it with values that you pass in the request.
WhatsApp has no preview operation. Every request sends a real message, so test with a phone number that you control.
Important
Prerequisites
An access token that has the sfap_api scope. The token’s Run As user must have permission to create send definitions. See Connect to Direct Send APIs.
API version 68.0 or later for the send definition request.
An active WhatsApp Messaging Channel and its record ID.
A published WhatsApp template in Salesforce CMS, of type sfdc_cms__whatsappTemplate, and its ContentKey. The API also accepts WhatsApp session content, of type sfdc_cms__whatsappSession, but we recommend a template.
If you already have a send definition ID, skip to step 2.
Step 1: Create a WhatsApp Send Definition
Create the send definition on your org’s My Domain host. The sender is the record ID of an active WhatsApp Messaging Channel, not its configured number or developer name.
The response contains the sendDefinitionId. Save it for the next step.
You don’t need to pass messagePurpose. The send definition gets its purpose from the content or, if the content has no purpose, from the template category. A MARKETING template is promotional, and a UTILITY or AUTHENTICATION template is transactional. If you pass messagePurpose, it must match the content’s purpose, and it can’t override the template category. If you don’t link any content, messagePurpose is required. For session content, omit messagePurpose. See Message Purpose.
You can also pass these optional fields.
Field
Description
messageSendTiming
Anytime, NotDuringActiveSession, or NotDuringOpenSession. See Send Timing.
clickTrackingEnabled
Indicates whether link clicks are tracked.
dataSpaceName
The developer name of a data space. If you omit it, the API uses the default data space.
Replace YOUR_SEND_DEFINITION_ID with the ID from step 1. For a test org, use https://test.api.salesforce.com/automation/actions360 as the base URL.
Field
Required
Description
to
Yes
The destination phone number in E.164 format, such as +14155550100.
individualId
Yes
The recipient’s identity, used for processing and correlation.
attributes
Yes
The personalization values. If the content has no variables, pass an empty object. See Personalize the Message.
messageId
No
A unique ID for the message, used for idempotency and tracing. If you omit it, the service generates one.
WhatsApp doesn’t accept content overrides. The message is the WhatsApp template or session content that’s linked to the send definition. A send request also can’t change the message purpose or the communication subscription.
A 200 response means that the request was processed. Check the recipient’s status, SUCCESS or FAIL, to find out whether the message was accepted for delivery. Acceptance doesn’t confirm delivery. See Handle Responses, Errors, and Retries in Direct Send API.
Step 3: Send to Multiple Recipients
To send one message to many phone numbers, post to the /bulk endpoint. Pass a recipients array and an optional batch-level requestId. A bulk request can include up to 200 recipients. Split larger sends into batches of 200 or fewer. The maximum request size and the maximum attributes size aren’t final yet.
WhatsApp template approval and conversation-window rules still apply to messages that you send with Direct Send.
Personalize the Message
Put the values that your content references under the $content key in attributes. The property names and value types come from the content’s schema, which is stored in contentBody["sfdc_cms:schema"] on the published content. Supply every required property. The property names and casing must match the schema.
Values keep their JSON types. In this example, the request sends age as the number 10, not the string "10".
The API also accepts flat values, such as attributes.firstName. The content schema doesn’t describe or validate flat values, and a flat value doesn’t fill a $content variable. Use $content for new integrations.
Communication Subscriptions for WhatsApp
Whether a WhatsApp send definition needs a communication subscription depends on the linked content.
Content
Subscription Behavior
Session
No subscription is required. Omit messagePurpose and communicationSubscription.
Marketing template
If you omit communicationSubscription, the API uses the configured Marketing subscription.
Utility or authentication template
Pass the name of a subscription that’s configured for the sender.
This request body creates a send definition for session content. Send it to the same endpoint that you use in step 1.