Set up a transactional SMS or WhatsApp message
UpdatedTransactional SMS or WhatsApp messages are text messages that your audience implicitly opts-into, like order confirmations, password reset codes, or account verification messages. You can send transactional SMS messages programmatically through Customer.io.
New to transactional messaging?
Check out our getting started section to learn more about transactional concepts and how our transactional API works.
Before you begin
Before you can send transactional SMS messages, you need to:
- Set up your Twilio account and enable SMS in your workspace.
- Get your app API key. This is the bearer token that you’ll use when you call the transactional API to trigger a message.
We also recommend that you use different phone numbers for transactional and marketing SMS messages. This helps maintain deliverability and ensures your critical transactional messages aren’t affected by marketing message reputation.
Create a transactional SMS
Unlike transactional emails and push notifications, you cannot send a transactional SMS or WhatsApp message without a template. You must use a transactional_message_id
when you send an SMS and you cannot override the body or image URL of your message at send time.
Go to the Transactional page and click Send your first message or Create message—depending on whether there are already transactional messages in your workspace.
Give your message a Name and a Description and then click Next: Add Content. The name and description help your team members understand what kind of message this is (like “Two-Factor Authentication” or “Password Reset Code”).
Select SMS and click Add Content.
Draft your message. If you see an error in the upper-right when you try to write your message, it’s likely that you need to select a person in your Sample data who has a
phone
attributeA key-value pair that you associate with a person or an object—like a person’s name, the date they were created in your workspace, or a company’s billing date etc. Use attributes to target people and personalize messages. Attributes are analogous to traits in Data Pipelines..Selecting a representative sample person also helps you personalize your message. You can personalize messages using attributes (
{{customer.<attribute>}}
) or data from your transactional message’smessage_data
key ( in the format{{trigger.<data-object-property>}}
).When you’re done writing your message, click Save Changes and then click Next: Configure Settings.
Configure your message settings. In general, we recommend that you use our defaults and that you Set a trigger name so that it’s easier to send your message later.
Send to unsubscribed people? Unsubscribed people probably still want to receive your important transactional messages like order confirmations and password resets.
Enable link tracking? By default, we’ll track clicks on links in your transactional SMS messages. Disable this setting if you don’t use our link shortening feature or tracked links (which are longer than normal links) will likely exceed the 160 character limit for SMS messages.
Protect sensitive data by disabling message retention? This setting prevents Customer.io from retaining your message content. You might want to do this to conceal sensitive messages, like password reset codes or verification tokens.
Queue messages as drafts? This setting generates a draft for every message you trigger rather than sending them automatically. You can review these messages under the Drafts tab and decide whether to send or delete them.
Set a Trigger Name: This is a friendly name for your message that you can use instead of the
transactional_message_id
when you send your message. It may help make your integration more human-readable if you use triggers that represent the kinds of messages you send—likepassword_reset
ororder_confirmation
.
Now you’re ready to send your message. You can adapt the code sample on the Send Message screen to your code—wherever you intend to trigger transactional messages—or use our API directly.
(Optional) Even if you don’t want to wire up your integration completely, we recommend that you call our API and send a test message to make sure that your message works the way you expect. You can even use an HTTP client like Postman or send a cURL request from your terminal to test your message and complete the setup process.
Try our Postman collection!
You can use our Postman collection and associated environment to get started with the Customer.io API. Our environment is based on our US endpoints; if you’re in our EU region, you’ll need to add -eu
to track_api_url
and app_api_url
variables.
The to
parameter: sending your message
When you send a transactional SMS or WhatsApp message, you must pass the to
parameter in your request so we know who to send the message to.
This value can be either a phone number in E.164 format (e.g., +15551234567) or a customer attributeA key-value pair that you associate with a person or an object—like a person’s name, the date they were created in your workspace, or a company’s billing date etc. Use attributes to target people and personalize messages. Attributes are analogous to traits in Data Pipelines. in liquidA syntax that supports variables, letting you personalize messages for your audience. For example, if you want to reference a person’s first name, you might use the variable {{customer.first_name}}
. syntax, like {{customer.phone}}
.
Examples and API parameters
Below are examples of transactional SMS messages. We’ve provided a basic payload and examples for cURL, our Node.JS SDK, and our Python SDK.
We’ve also provided a list of parameters for transactional SMS payloads. Your payload changes based on whether you reference a transactional_message_id
(a template) or not. See our REST API documentation for more information.
Basic Payload
{
"transactional_message_id": "confirmation_code",
"identifiers": {
"id": "123456"
},
"message_data": {
"confirmation_code": "123456",
"account_name": "Jane Doe"
}
}
Node.js
const { APIClient, SendSMSRequest } = require("customerio-node");
const api = new APIClient('app-key');
const request = new SendSMSRequest({
transactional_message_id: "confirmation_code",
identifiers: {
id: "123456"
},
message_data: {
confirmation_code: "123456",
account_name: "Jane Doe"
},
});
api.sendSMS(request)
.then(res => console.log(res))
.catch(err => console.log(err.statusCode, err.message))
Python
from customerio import APIClient, SendSMSRequest, CustomerIOException
client = APIClient("your API key")
request = SendSMSRequest(
transactional_message_id="confirmation_code",
identifiers={
"id": "123456"
},
message_data={
"confirmation_code": "123456",
"account_name": "Jane Doe"
}
)
try:
api.send_sms(request)
except CustomerIOException as e:
print("error: ", e)
Go
import "github.com/customerio/go-customerio"
client := customerio.NewAPIClient("");
request := customerio.SendSmsRequest{
TransactionalMessageID: "sms_test",
Identifiers: map[string]string{
"id": "123456",
},
}
body, err := client.SendSms(context.Background(), &request)
if err != nil {
fmt.Println(err)
}
fmt.Println(body)
Ruby
require "customerio"
client = Customerio::APIClient.new("")
request = Customerio::SendSmsRequest.new(
transactional_message_id: "sms_test",
identifiers: {
id: "123456",
},
)
begin
response = client.send_sms(request)
puts response
rescue Customerio::InvalidResponse => e
puts e.message, e.code, e.response
end
cURL
curl --request POST \
--url https://api.customer.io/v1/send/sms \
--header 'Authorization: Bearer <YOUR-APP-API-KEY>' \
--header 'content-type: application/json' \
--data '{
"transactional_message_id": "confirmation_code",
"identifiers": {
"id": "123456"
},
"message_data": {
"confirmation_code": "123456",
"account_name": "Jane Doe"
}
}'
- transactional_message_idRequired The transactional message template that you want to use for your message. You can call the template by its numerical ID or by the Trigger Name that you assigned the template (case insensitive).integerThe ID of the transactional message you want to send.
- from stringThe phone number or sender ID that your SMS is from. This must be a verified phone number in your Twilio account. This overrides the from address set within the transactional template (referenced by
transactional_message_id
). Phone numbers must be in E.164 format (e.g., +15551234567). - language stringOverrides language preferences for the person you want to send your transactional message to. Use one of our supported two- or four-letter language codes.
- to stringRequired The phone number you want to send your SMS to. Phone numbers must be in E.164 format (e.g., +15551234567), but you can also use liquid syntax if you store users phone numbers as attributes; you don’t have to pass an E.164 formatted phone number in the call.
- disable_message_retention booleanIf true, the message body is not retained in delivery history. Setting this value overrides the value set in the settings of your
transactional_message_id
. - identifiersRequired Identifies the person represented by your transactional message by one of, and only one of,
id
,email
, orcio_id
.- id stringRequired The identifier for the person represented by the transactional message. NOTE: If your workspace identifies people by email, use the
email
identifier instead.
-
- Liquid Data* any typeInsert key-values that you want to reference in your message here.
- queue_draft booleanIf true, your transactional message is held as a draft in Customer.io and not sent directly to your audience. You must go to the Deliveries and Drafts page to send your message.
- send_at integerA unix timestamp (seconds since epoch) determining when the message will be sent. The timestamp can be up to 90 days in the future. If this value is in the past, your message is sent immediately.
- send_to_unsubscribed boolean
Default:
If false, your message is not sent to unsubscribed recipients. Setting this value overrides the value set in the settings of yourtrue
transactional_message_id
.