Handle Responses, Errors, and Retries in Direct Send API

Direct Send APIs return the same response shape and error behavior on every channel. Use this guidance to read send responses, retry failed sends safely, and troubleshoot common send and send definition errors.

Response Shape 

A single send returns 200 with a result object.

1{
2  "requestId": "sms-order-ORD-1234",
3  "to": "+14155550100",
4  "status": "SUCCESS",
5  "properties": {
6    "deliveryId": "delivery-123",
7    "channel": "sms"
8  }
9}

A bulk send returns 200 with the batch requestId and a recipients array that has one result for each recipient, in request order.

1{
2  "requestId": "sms-batch-001",
3  "recipients": [
4    {
5      "to": "+14155550100",
6      "individualId": "Individual__dlm/customer-001",
7      "messageId": "sms-001",
8      "status": "SUCCESS",
9      "properties": {
10        "deliveryId": "delivery-123"
11      }
12    },
13    {
14      "to": "+14155550101",
15      "individualId": "Individual__dlm/customer-002",
16      "messageId": "sms-002",
17      "status": "FAIL",
18      "reasonCode": "SEND_FAILED",
19      "reason": "Downstream send rejected"
20    }
21  ]
22}
FieldDescription
requestIdOn a single send, the messageId that you sent, or a generated value. On a bulk send, the batch requestId.
toThe recipient’s address. For Push, this field contains the deviceId from the request.
individualIdBulk only. The recipient’s identity from the request.
messageIdBulk only. The messageId from the request.
statusSUCCESS or FAIL.
reasonCodeThe failure code. Returned only when status is FAIL.
reasonA description of the failure. Returned only when status is FAIL.
properties.deliveryIdThe delivery tracking ID.
properties.channelThe delivery channel, such as email or sms.

Store the requestId, messageId, deliveryId, and status for each send so that you can trace the message later.

A 200 Response Can Include Failures 

A 200 response means that the request was processed. It doesn’t mean that every message was accepted for delivery. Malformed requests and requests that are missing required recipient fields return 400 before anything is sent. When recipient results are returned, check each result’s status. A single send works like a bulk send with one recipient, so a recipient-level failure also returns 200, with "status": "FAIL". Always check status, and on a bulk send, check every recipients[].status.

A SUCCESS status means that the channel accepted the message for delivery. It doesn’t confirm that the carrier, the device, or the recipient received the message. To get the final delivery state, use channel delivery events or reporting.

Reason Codes 

When a recipient fails, reasonCode contains a code such as INVALID_RECIPIENT, SEND_FAILED, or RETRYABLE_SEND_FAILED. These aren’t the only codes. A channel can return other, channel-specific codes, so handle codes that you don’t recognize.

This table describes the common codes. Read the reason text along with the code before you decide whether to retry a recipient.

Reason CodeWhat It Usually MeansBefore You Retry
INVALID_RECIPIENTThe recipient’s data isn’t valid, such as a malformed address.Correct the recipient’s data. Resending the same data is likely to fail again.
SEND_FAILEDThe channel rejected the send.Check reason to find the cause, and fix it before you resend.
RETRYABLE_SEND_FAILEDThe send failed, possibly because of a temporary problem.A later retry with backoff can succeed. Limit the number of attempts.

Idempotency 

Use messageId and requestId to make retries safe.

  • messageId identifies one message. Set it on a single send and on each recipient in a bulk send.
  • requestId identifies a bulk batch.

Generate unique values, such as UUIDs, before the first attempt. Reuse the same values when you retry the same send, and never reuse them for a new message. Each messageId must be unique within a bulk request. If you omit messageId, the service generates one.

The deduplication window depends on the channel. Push deduplicates on the tenant, requestId, and messageId for 24 hours. The other channels don’t document a window, so assume that a retry can produce a second message.

Retry Policy 

The same retry policy applies to every channel.

StatusMeaningWhat to Do
429A rate or concurrency limit was exceeded.Retry with exponential backoff and jitter.
503A downstream service failed temporarily.Retry with exponential backoff and jitter.
401The token is missing, expired, or invalid.Request a new token and then retry.
500An unexpected server error occurred.Investigate before you retry broadly.
Other 4xxThe request is invalid.Correct the request. Don’t retry it unchanged.

When you retry a 429 or 503 response:

  1. Keep the same requestId and messageId values.
  2. Wait with exponential backoff and add random jitter. For example, wait about 1 second, then 2 seconds, then 4 seconds. The schedule is an example, not a service guarantee.
  3. Stop after a limited number of attempts.
  4. For a bulk 200 response, don’t resend the whole batch. Resend only the failed recipients that you want to retry.

Base your error handling on the HTTP status code, not the message text. Error messages are general and can change.

This Node.js example retries 429 and 503 responses with exponential backoff and jitter.

1async function sendWithRetry(url, token, payload, maxAttempts = 4) {
2  for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
3    const response = await fetch(url, {
4      method: "POST",
5      headers: {
6        Authorization: `Bearer ${token}`,
7        "Content-Type": "application/json",
8      },
9      body: JSON.stringify(payload),
10    });
11    if (response.ok) {
12      return response.json();
13    }
14    if (![429, 503].includes(response.status) || attempt === maxAttempts) {
15      throw new Error(`Send failed with status ${response.status}`);
16    }
17    const delayMs = Math.min(30000, 1000 * 2 ** (attempt - 1)) + Math.random() * 250;
18    await new Promise((resolve) => setTimeout(resolve, delayMs));
19  }
20}

Generate the IDs in payload before you call the function. Don’t regenerate them inside the retry loop.

Error Response Body 

When the whole request fails, the response body contains the status, the error, a message, and the route that was called.

1{
2  "status": 404,
3  "error": "Not Found",
4  "message": "BulkMessage not found: 539000000000000AAA",
5  "path": "/messaging/sms/v1/bulk"
6}

The API rejects a whole request before it sends anything when:

  • sendDefinitionId is missing or blank.
  • The JSON is malformed, a required field is missing, or a field has the wrong type.
  • On a bulk request, recipients is missing or empty, or two recipients have the same messageId.

Troubleshoot Send Errors 

This table lists common errors that a send request returns, with their causes and resolutions.

ResponseCauseResolution
400 Bad RequestThe JSON is invalid, a field is missing or has the wrong type, or a messageId is duplicated in a batch.Correct the request.
401 UnauthorizedThe token is missing, expired, or invalid, or it doesn’t have the sfap_api scope.Request a new token and verify its scope. See Connect to Direct Send APIs.
403 ForbiddenThe request was authenticated, but it isn’t authorized.Ask your Salesforce admin to check the Run As user’s access.
404 with a JSON bodyThe send definition or its linked content wasn’t found.Check the send definition ID, and confirm that you’re calling the gateway for your org’s environment.
404 with an empty bodyThe channel’s send route isn’t available for your org.Contact your Salesforce admin or account team.
404 with an HTML URL No Longer Exists pageYou called your My Domain host instead of the gateway.Send to api.salesforce.com/automation/actions360.
429 Too Many RequestsA rate or concurrency limit was exceeded.Retry with backoff. See Retry Policy.
500 Internal Server ErrorAn unexpected server error occurred.Investigate before you retry broadly.
503 Service UnavailableA downstream service failed temporarily.Retry with backoff.
200 with "status": "FAIL"The request was valid, but the recipient failed.Check reasonCode and reason. See Reason Codes.
200 with "status": "SUCCESS", but no message arrivesFor SMS and RCS, a recipient who has no opt-in record is suppressed. Otherwise, the message was accepted but not yet delivered.Check the recipient’s consent, and check channel delivery events or reporting.

Troubleshoot Send Definition Errors 

When a request to create a send definition fails, the response body is an array of error objects. Each object has a message that describes the error. Match the message to find the cause.

MessageCause
Request body is required.The request has no JSON body.
name is required.name is blank.
description cannot exceed 4000 characters.description is longer than 4,000 characters.
Unrecognized field "{fieldName}"The body has a field that the channel doesn’t accept.
fromAddress is required.An Email request has no fromAddress.
fromAddress must use an authorized email domain.The sender domain isn’t authorized for email sending. Ask your Salesforce admin to authorize it.
duplicate value found: Name duplicates value on recordAn Email send definition with that name exists.
insufficient access rights on object idThe Run As user can’t create Email send definitions.
senderId is required.An SMS, WhatsApp, or RCS request has no senderId.
sender is not an active Messaging Channel.The Messaging Channel is inactive.
sender must be a {channel} Messaging Channel.The Messaging Channel is for a different channel.
sender Messaging Channel usage is not active.The WhatsApp channel setup isn’t active.
sender does not identify a usable Messaging Channel.The Messaging Channel ID is unknown or unavailable.
mobileAppId is required.A Push request has no mobileAppId.
mobileAppId does not identify a usable mobile application.The Application Identifier is unknown or unavailable.
categoryName is required when managed content is not a Basic notification.The Push content isn’t a Basic notification, and the request has no categoryName.
categoryName does not identify a category on the selected mobile application.The label isn’t configured on the mobile app.
managedContentKey does not identify usable managed content.The content key doesn’t match published content.
managedContentKey must identify {cmsType} content.The content is for a different channel.
messagePurpose is required when managedContentKey is absent.The request has no content and no purpose.
messagePurpose must be PROMOTIONAL or TRANSACTIONAL.The purpose value isn’t supported.
messagePurpose conflicts with managed content.The request purpose doesn’t match the content’s purpose.
communicationSubscription is required for transactional content.A transactional send definition that requires a subscription has no subscription name.
The Marketing Communication Subscription is unavailable.No subscription name was passed, and the default Marketing subscription isn’t configured.
You don't have access to this communication subscription. Please select a subscription from your Business Unit or a Global subscription.The subscription belongs to another business unit. Pass a subscription from your business unit or a global subscription.
messageSendTiming must be Anytime, NotDuringActiveSession, or NotDuringOpenSession.The timing value isn’t supported.

A 401 response means that the access token is missing or expired. Request a new token and retry.

Before You Go to Production 

Before you move your integration to production, follow these practices.

  • Call the API from a trusted server, never from browser code.
  • Never expose or log access tokens. Rotate client secrets, and store them in a secrets manager.
  • Treat addresses, phone numbers, device IDs, individual IDs, and attributes as sensitive data. Redact them from application logs.
  • Log the requestId, messageId, deliveryId, channel, HTTP status, and error codes.
  • Use separate send definitions and credentials for test and production.
  • Don’t set internal x-sfdc-* headers. The gateway derives tenant and user context from the token.
  • If you relaxed the external client app’s IP restrictions for testing, restrict them to your server’s IP addresses.
  • Reuse a token until it expires instead of requesting a new token for every send.

See Also