Page cover

copyMessage Templates

Learn how to use Message Templates when calling the Mobile Text Alerts API

Pre-set message templates allow you to create a message once and then have it on hand to send 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 unique subscriberId.

    • 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 - Flag to indicate send message to all subscribers if true. When allSubscribers is set to true, no other recipient fields should be specified. Default value is false.

    • groups: number[] - List of group IDs of recipients. Messages can be sent to specific groups, with each group assigned a unique groupId.

    • threadId: number - Messages can be sent in reply to a thread, with each thread assigned a unique threadId.

  • Content:

    • templateId: number - Messages can be saved as pre-set message templates for reuse with saved controlled templates on your account assigned a templateId.

  • Other fields:

    • linkId: number - If a message contains a linkId, then this field is required. Links can be created with the /shortlinks endpoint.

Send a message template with the API

1

Indicate the recipient(s)

You can send a message to a phone number as a test. Here you would set the subscribers field to the recipient phone number.

"subscribers": [1112223333]
2

Indicate the template to be sent

Use the templateId field to indicate which template will be used.

"templateId": 101
3

Form API request

Create the API request to the /send endpoint. Remember to include the Authorizationarrow-up-right header.

curl --location 'https://api.mobile-text-alerts.com/v3/send' \
--header 'Authorization: Bearer 89fa747a-e01b-5940-99c2-4e96fa996258' \
--data '{"subscribers": [1112223333],
        "templateId": 101
        }'
4

Receive response

The API will return a message about the status of your request.

{
  "data": {
    "messageId": "uuid",
    "totalSent": 1,
    "totalFailedInternationalRecipients": 0
  },
chevron-rightSend Message POST /sendhashtag

When sending or scheduling a message, the /send endpoint will compose the message body using the provided templateId for a controlled template and, if required by the template, a provided linkId. Links can be created with the /shortlinks endpoint.

chevron-rightCreate Short Link POST /shortlinkshashtag

Include personalization in a template

Mobile Text Alerts supports Liquid templates for message personalization. A template can include custom variables like {{firstName}}, which are replaced using per-recipient properties. This requires you to provide 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:

chevron-rightList Templates GET /templateshashtag

View a specific template

To see the details on a specific template, you will need the {id} of the template. Then call GET /templates/{id} :

chevron-rightGet Template GET /templates/{id}hashtag

Update a specific template

To make changes to a specific template, you will need the {id} of the template. Then call PATCH /templates/{id} with the body containing the new template data, message is required.

circle-exclamation

Example request:

chevron-rightUpdate Template PATCH /templates/{id}hashtag

Delete a Template

To remove a specific template, you will need the {id} of the template, then call DELETE /templates/{id}

chevron-rightDelete Template DELETE /templates/{id}hashtag

Create a new template

When creating a new template, the message field is required to hold the content of the message.

circle-exclamation

Example request:

chevron-rightCreate Template POST /templateshashtag

Template-Only Sending

If your account is configured for template-only message sending, please use the Controlled Template endpoints below to view available templates:

chevron-rightList Controlled Templates GET /controlled-templateshashtag

chevron-rightGet Controlled Template Endpoint GET /controlled-templates/{controlledTemplateId}hashtag

Template Examples

Last updated

Was this helpful?