Message Templates
Learn how to use Message Templates when calling the Mobile Text Alerts API
Saved message templates allow you to create a message once and then send it at any time. You can create and send message templates in the platform, mobile app, and the API.
Use a template to send a message with the API
Templates can be sent by making a POST request to the /send endpoint. All requests to this endpoint must contain both recipient and content information. When using a message template, the templateId is used as the content.
Required request fields:
Choose recipient(s): (Must be one of the following.)
subscriberIds: number[]- List of subscriber IDs of recipients. Messages can be sent to specific subscribers, with each subscriber assigned a uniquesubscriberId.subscribers: (number | string)[]- List of recipient phone numbers or email addresses. A new subscriber will be created for new recipients that are not already subscribers on your account.allSubscribers: boolean- Indicates whether to send a message to all subscribers. WhenallSubscribersis set totrue, no other recipient fields should be specified. The default value isfalse.groups: number[]- List of group IDs of recipients. Messages can be sent to specific groups, with each group assigned a uniquegroupId.threadId: number- Messages can be sent in reply to a thread, with each thread assigned a uniquethreadId.
Content:
templateId: number- The ID of a saved template on your account.
Other fields:
linkId: number- Include this field when the template requires a shortlink. Links can be created with the /links/shortlinks endpoint.
Send a message template with the API
Form API request
Create the API request to the /send endpoint. Remember to include the Authorization header.
curl --location 'https://api.mobile-text-alerts.com/v3/send' \
--header 'Authorization: Bearer <APIKey>' \
--header 'Content-Type: application/json' \
--data '{"subscribers": ["+13175551111"],
"templateId": 101 }'Using Shortlinks with Controlled Templates
When sending or scheduling a message, the /send endpoint composes the message body using the provided templateId for a controlled template. If required, it also uses the provided linkId. Links can be created with the /links/shortlinks endpoint:
Include personalization in a template
Mobile Text Alerts supports Liquid templates for message personalization. A template can include custom variables such as {{firstName}}, which are replaced using per-recipient properties. This requires a properties object that maps each phone number to its corresponding data.
See Properties field for custom variables in messages to learn more.
Templates API endpoints
View all templates
You can call GET /templates to see all the available templates on your account:
View a specific template
To see the details of a specific template, you need the template's {id}. Then call GET /templates/{id}:
Update a specific template
To make changes to a specific template, you need the template's {id}. Then call PATCH /templates/{id} with a body containing the new template data. The message field is required.
Example request:
Delete a template
To remove a specific template, you need the template's {id}. Then call POST /templates/{id}.
Create a new template
When creating a new template, the message field is required to hold the content of the message.
Example request:
Template-Only Sending
If your account is configured for template-only message sending, please use the Controlled Template endpoints to view available templates:
Template Examples
Last updated
Was this helpful?