Send SMS Transactional Messages Through Direct Send API

Use Direct Send APIs to send transactional SMS messages to one or more phone numbers. The message text comes from the published Salesforce CMS content that’s linked to the send definition, and you personalize it with values that you pass in the request.

SMS 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 SMS Messaging Channel and its record ID.
  • Published SMS content in Salesforce CMS, of type sfdc_cms__sms, and its ContentKey.
  • An opt-in for each recipient’s phone number. See Consent.

If you already have a send definition ID, skip to step 2.

Step 1: Create an SMS Send Definition 

Create the send definition on your org’s My Domain host. The sender is the record ID of an active SMS Messaging Channel, which starts with 0Mj.

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

Replace the placeholders with your own values.

  • YOUR_DOMAIN: Your org’s My Domain name.
  • YOUR_ACCESS_TOKEN: Your access token.
  • YOUR_SMS_MESSAGING_CHANNEL_ID: The record ID of the SMS Messaging Channel.
  • YOUR_SMS_CONTENT_KEY: The ContentKey of the published sfdc_cms__sms content.
  • YOUR_SUBSCRIPTION_NAME: The name of the communication subscription. Whether SMS requires one depends on your org’s consent settings. When a promotional subscription is required and you omit it, the API uses the Marketing subscription, which must be configured in your org.

messageSendTiming controls whether the message can be sent during an active or open messaging session with the recipient. See Send Timing.

The response contains the sendDefinitionId. Save it for the next step.

You can also pass these optional fields.

FieldDescription
messagePurposePROMOTIONAL or TRANSACTIONAL. Required if you don’t pass managedContentKey, or if the content has no purpose. If the content has a purpose, this value must match it. See Message Purpose.
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 SMS - 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/sms/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        "orderNumber": "ORD-1234"
11      }
12    },
13    "messageId": "sms-order-ORD-1234"
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.
ttlSecondsNoThe maximum lifetime of the message, from 1 through 86,400 seconds (24 hours).

SMS doesn’t accept content overrides. The text comes from the content that’s linked to the send definition.

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 2,000 recipients. Split larger sends into batches of 2,000 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/sms/v1/bulk?sendDefinitionId=YOUR_SEND_DEFINITION_ID" \
2  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
3  -H "Content-Type: application/json" \
4  -d '{
5    "requestId": "sms-batch-001",
6    "recipients": [
7      {
8        "to": "+14155550100",
9        "individualId": "Individual__dlm/customer-001",
10        "attributes": {"$content": {"firstName": "Alice"}},
11        "messageId": "sms-001"
12      },
13      {
14        "to": "+14155550101",
15        "individualId": "Individual__dlm/customer-002",
16        "attributes": {"$content": {"firstName": "Bob"}},
17        "messageId": "sms-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.

Personalize the Message 

Put personalization values under the $content key in attributes. Three things must line up.

  1. The CMS content declares the property in its schema, which is stored in contentBody["sfdc_cms:schema"] on the published content.
  2. The content’s text references the property under $content.
  3. The send request supplies the value under attributes.$content.

The $content key is case-sensitive, and the property names must match the schema exactly. Values keep their JSON types, so send a number as a number, not as a string. Supply every property that the schema requires.

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.

Consent 

When consent checking applies, make sure that the recipient has opted in to the communication subscription that the send definition uses. The send looks for an opt-in for the phone number under that subscription and the SMS channel. A number that has no consent record counts as opted out, and the message is suppressed.

A suppressed message can still return "status": "SUCCESS", because SUCCESS means that the message was accepted for delivery. If a test message doesn’t arrive, check the recipient’s opt-in first.

An opt-out on the phone number, such as one recorded when someone replies STOP, overrides a subscription opt-in. The number stays suppressed until the opt-out is reversed.

See Also