Transactional messages
Every message you send is either a marketing message or a transactional message. Marketing is the default: it ends with the unsubscribe line, and it's never sent to a number that opted out. A transactional message is for something people need from you. Once your organization is approved, it goes without the unsubscribe line, even to numbers that opted out of your marketing messages, and you can send it to anyone a marketing message can reach: one number, several, or your lists.
When to use one
Send a transactional message when the person is waiting for it, or would want it whatever their marketing choice:
- a sign-in code;
- an order update, like "Your order 1042 has shipped";
- an appointment change or reminder.
Don't use it for promotions, offers or news. Those are marketing messages: they end with the unsubscribe line, and they skip everyone who opted out.
Get access
Transactional messages need approval for your organization, once. Until then, a request with type: "transactional" is refused with 403 and feature_, and nothing is sent, scheduled or charged.
- Request access under Features on the Organization page in the portal. Tell us what you'll send, with two example messages, how people give you their number, how many messages you send a month, the countries you send to and your website. You need permission to manage the organization; if you don't have it, ask someone who does. Requests are made in the portal only: the features endpoints take a sign-in session, and an API key is refused with
403andapi_.key_ not_ allowed - We review the request and email the decision to you and your organization's owners. The Organization page shows where it stands, and the reason if it isn't approved. You can change your answers and request again.
- Once approved, any API key with
messages:sendcan send transactional messages.
The refusal is stored under its Idempotency-Key, like any answer, and the same key returns it again for 24 hours. After approval, send with a new Idempotency-Key.
Send one
Add type: "transactional" to POST /. to takes one number or several, as it does for a marketing message:
curl -X POST "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/messages" \
-H "Authorization: Bearer $CODELIA_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: appointment-5521-moved" \
-d '{
"to": [
"+442079460123",
"+442079460124"
],
"from": "InfoSMS",
"body": "The clinic is closed on October 14. Call us on 020 7946 0000 to move your appointment.",
"type": "transactional"
}'const response = await fetch(
`https://api.sms.codelia.studio/v1/organizations/${process.env.CODELIA_ACCOUNT_ID}/messages`,
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CODELIA_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "appointment-5521-moved",
},
body: JSON.stringify({
"to": [
"+442079460123",
"+442079460124"
],
"from": "InfoSMS",
"body": "The clinic is closed on October 14. Call us on 020 7946 0000 to move your appointment.",
"type": "transactional"
}),
},
);
console.log(response.status);
console.log(JSON.stringify(await response.json(), null, 2));The answer has the same shape as for any message you send: one message for each number, each with type set to transactional. The API key needs messages:send, as for any message; there's no separate permission. Your organization needs to be approved first: see Get access.
To price it first, send the same body, type included, to POST /. The price then leaves out the unsubscribe line, as sending it will.
Schedule one
To send a transactional message to your lists, or to schedule one, use the campaign endpoint, POST /, with recipients, listIds or both, as for any campaign. This one is scheduled with scheduledAt, and {listId} is read from $LIST_. Put your own time in scheduledAt:
curl -X POST "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/messages/campaigns" \
-H "Authorization: Bearer $CODELIA_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: appointment-2041-reminder" \
-d '{
"recipients": [
{
"to": "+442079460123"
}
],
"listIds": [
"'"$LIST_ID"'"
],
"from": "InfoSMS",
"body": "From Monday the clinic opens at 10:00, not 9:00. Your appointment time is unchanged.",
"type": "transactional",
"scheduledAt": "2027-01-25T09:00:00.000Z"
}'const response = await fetch(
`https://api.sms.codelia.studio/v1/organizations/${process.env.CODELIA_ACCOUNT_ID}/messages/campaigns`,
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CODELIA_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "appointment-2041-reminder",
},
body: JSON.stringify({
"recipients": [
{
"to": "+442079460123"
}
],
"listIds": [
process.env.LIST_ID
],
"from": "InfoSMS",
"body": "From Monday the clinic opens at 10:00, not 9:00. Your appointment time is unchanged.",
"type": "transactional",
"scheduledAt": "2027-01-25T09:00:00.000Z"
}),
},
);
console.log(response.status);
console.log(JSON.stringify(await response.json(), null, 2));The answer is 202 with the campaign. It works like any scheduled campaign:
scheduledAtmust be between 5 minutes and 90 days ahead. Outside that, the answer is400withinvalid_.schedule - Scheduling needs auto top-up. Without it, the answer is
409withauto_.topup_ required - Nothing is charged when you schedule it. It's priced and charged when it sends, at that day's price.
- Approval is checked again when it's due. If your organization isn't approved by then, for example because its access was turned off, it becomes
failed, withfailureReason: "feature_, and nothing is charged. Once your organization is approved, you can send it again.not_ enabled"
Leave out scheduledAt to send it now. Everyone on the list gets it, including anyone who opted out of your marketing messages. A recurring campaign can't be transactional: schedule each transactional campaign on its own.
If access is turned off while it's sending
A transactional campaign stops if your organization's access to transactional messages is turned off while it's sending. Messages already handed to the network stay sent. The rest aren't sent and are refunded: each has status failed and errorCode campaign_. The campaign finishes partial_, or failed if nothing had gone yet, with failureReason: "feature_, and the campaign.partial_ or campaign.failed webhook says so.
Once your organization is approved again, send to them with Send to the same people again and "onlyFailed": true. That sends to every message that failed, so it includes any that failed for another reason. A scheduled campaign that stopped before anything went can be sent again instead.
What's different, and what isn't
| Rule | Transactional message | Marketing message |
|---|---|---|
| Numbers | The same as marketing | Up to 500 in to, or a campaign's lists |
| Unsubscribe line | None | Added at the end |
| Counted and priced | Without it | With the unsubscribe line |
| Number opted out | Sent | Not sent, and not charged |
| Can be recurring | No | Yes |
A transactional message is counted and priced on your text alone, so it can take fewer parts than the same text sent as marketing.
Everything else is the same for both: your sender name must be approved, and allowed for the destination country; the countries you can send to are the same; and each part costs the same.
When it's refused
A transactional request that would repeat, or comes before your organization is approved, is refused, never sent as a marketing message instead. Nothing is sent, scheduled or charged.
| Status | error | What happened | What to do |
|---|---|---|---|
| 400 | transactional_ | A recurring campaign's send has type set to transactional. | Schedule each transactional message on its own, or leave out type to repeat a marketing message. |
| 403 | feature_ | Your organization isn't approved to send transactional messages. The body's feature is transactional_. | Request access, or leave out type to send a marketing message. |
Find transactional messages
- On a message. Every message you send has a
type:marketingortransactional. Campaigns have one too. - In the list.
GET /lists only transactional messages;organizations/ {accountId}/ messages?type=transactional ?type=marketingonly marketing ones. - In webhooks. The
dataofmessage.deliveredandmessage.failedevents has atypefield, and so does thedataofcampaign.completed,campaign.partial_andfailure campaign.failed. Fields are added to event data over time, astypewas, so ignore any field you don't recognize. - Sending again. Sending a message or a campaign again keeps its type. A transactional message goes again as a transactional message, without the unsubscribe line.
Related
- Opt-outs: who your marketing messages skip, and why a transactional message doesn't.
- Schedule it: how scheduled campaigns are priced, charged and canceled.
- Webhooks: be told when a transactional message is delivered or fails.