Send WhatsApp Transactional Messages Through Direct Send API

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.

1curl -X POST "https://YOUR_DOMAIN.my.salesforce.com/services/data/v68.0/connect/e360/whatsapp/sendDefinition" \
2  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
3  -H "Content-Type: application/json" \
4  -d '{
5    "name": "order-update-whatsapp@1.0.0",
6    "senderId": "YOUR_WHATSAPP_MESSAGING_CHANNEL_ID",
7    "managedContentKey": "YOUR_WHATSAPP_CONTENT_KEY",
8    "communicationSubscription": "YOUR_SUBSCRIPTION_NAME"
9  }'

Replace the placeholders with your own values.

  • YOUR_DOMAIN: Your org’s My Domain name.
  • YOUR_ACCESS_TOKEN: Your access token.
  • YOUR_WHATSAPP_MESSAGING_CHANNEL_ID: The record ID of the WhatsApp Messaging Channel.
  • YOUR_WHATSAPP_CONTENT_KEY: The ContentKey of the published WhatsApp template or session content.
  • YOUR_SUBSCRIPTION_NAME: The name of the communication subscription. Whether you need one depends on the content. See Communication Subscriptions for WhatsApp.

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.

FieldDescription
messageSendTimingAnytime, NotDuringActiveSession, or NotDuringOpenSession. See Send Timing.
clickTrackingEnabledIndicates whether link clicks are tracked.
dataSpaceNameThe developer name of a data space. If you omit it, the API uses the default data space.
campaignIdThe ID of a Salesforce campaign.
descriptionA description of up to 4,000 characters.

For every field, see WhatsApp - Send Definitions (Connect API). If the request fails, see Troubleshoot Send Definition Errors.

Step 2: Send to One Recipient 

Send the message through the Salesforce API gateway. Pass the send definition ID in the sendDefinitionId query parameter.

1curl -X POST "https://api.salesforce.com/automation/actions360/messaging/whatsapp/v1?sendDefinitionId=YOUR_SEND_DEFINITION_ID" \
2  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
3  -H "Content-Type: application/json" \
4  -d '{
5    "to": "+14155550100",
6    "individualId": "Individual__dlm/customer-001",
7    "attributes": {
8      "$content": {
9        "firstName": "Alice",
10        "appointmentTime": "10:30 AM"
11      }
12    },
13    "messageId": "wa-appointment-001"
14  }'

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.

FieldRequiredDescription
toYesThe destination phone number in E.164 format, such as +14155550100.
individualIdYesThe recipient’s identity, used for processing and correlation.
attributesYesThe personalization values. If the content has no variables, pass an empty object. See Personalize the Message.
messageIdNoA 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.

1curl -X POST "https://api.salesforce.com/automation/actions360/messaging/whatsapp/v1/bulk?sendDefinitionId=YOUR_SEND_DEFINITION_ID" \
2  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
3  -H "Content-Type: application/json" \
4  -d '{
5    "requestId": "wa-batch-001",
6    "recipients": [
7      {
8        "to": "+14155550100",
9        "individualId": "Individual__dlm/customer-001",
10        "attributes": {"$content": {"firstName": "Alice"}},
11        "messageId": "wa-001"
12      },
13      {
14        "to": "+14155550101",
15        "individualId": "Individual__dlm/customer-002",
16        "attributes": {"$content": {"firstName": "Bob"}},
17        "messageId": "wa-002"
18      }
19    ]
20  }'

The response contains a result for each recipient. Some recipients can fail even when others succeed, so check every recipients[].status. See Handle Responses, Errors, and Retries in Direct Send API.

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".

1{
2  "to": "+14155550100",
3  "individualId": "Individual__dlm/customer-001",
4  "attributes": {
5    "$content": {
6      "accountType": "premium",
7      "age": 10,
8      "name": "Alice"
9    }
10  }
11}

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.

ContentSubscription Behavior
SessionNo subscription is required. Omit messagePurpose and communicationSubscription.
Marketing templateIf you omit communicationSubscription, the API uses the configured Marketing subscription.
Utility or authentication templatePass 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.

1{
2  "name": "session-reply@1.0.0",
3  "senderId": "YOUR_WHATSAPP_MESSAGING_CHANNEL_ID",
4  "managedContentKey": "YOUR_SESSION_CONTENT_KEY"
5}

Consent 

WhatsApp checks consent when you send.

See Also