Menu

Expand
Rate this page:

Send Templates Created with the Content Template Builder

To send messages from templates created using the Content Template Builder, you will need two new fields in your API request. You will also need a Messaging Service.

New Content Fields Used to Send Messages

You will utilize the existing messaging endpoint with an additional field, ContentSid. You may also include the ContentVariables field to substitute any placeholder values in your templates.

POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages

New Field Required

Description

ContentSid Yes String field used to identify the preconfigured content. Required to send templates created using the Content Template Builder.
ContentVariables No JSON string used to define the values of any placeholder variables found in the preconfigured content. Key-value pairs of placeholder variable names and substitution values.

If you are sending a WhatsApp message outside of the 24-hour free-form session, you need use a template approved by WhatsApp. Learn more.

Use Messaging Services to Send Content Templates

To send content templates, you'll need a Messaging Service. Messaging Services are also a great tool to organize your account and reduce complexity as your messaging application grows. Learn more about Messaging Services features here.

To create a messaging service, head to the Messaging > Services section of the Twilio Console. Check out the Quick Start for a detailed guide.

MSGSER1

Now grab your Messaging Service's Sid by going to the Twilio Console > Services and finding the "Sid".

find-messaging-service-sid

Next, we will review the two ways to send a template created with the Content Template Builder:

  • Include a MessagingServiceSid field, or
  • Use the From field to specify the Messaging Service Sid

Send Messages with a Messaging Service in the "From" Field

Body and MediaUrl should be excluded. They are both not required. They are both superseded by the ContentSid.

The body in the response will be empty. Since this is a templated message, the body is in the template. If you would like to see the body that was delivered they can view it in the Twilio logs in console.

Loading Code Sample...
        
        

        Send Messages with a Messaging Service in the "From" field

        This method requires adding a Sender to a Messaging Service. This approach is recommended if you plan to scale your traffic with multiple senders.

        How to Add Senders to a Your Sender Pool

        Each Messaging Service has a "Sender Pool" that contains all the senders that can access that service's configurations. To add a sender to a Messaging Service, you need to add it to its Sender Pool. Go to the Messaging Service, find the "Sender Pool" Section on the left and click "Add Sender".

        add-sender-to-sender-pool

        Messaging Services support Phone Numbers, Short Codes, Alphasenders, WhatsApp Senders and Facebook Messenger Senders. If you do not see an option for FB Messenger, file a support ticket asking to enable the "FBM with messaging services feature". Read our Facebook Messenger with Twilio documentation for more information.

        Here is a summary of all the fields used in the API request:

        Field Required Description
        From Yes The Messaging Service sid, MGXXXXXXXX.
        To Yes

        The identifier of the recipient you are sending the message to. Use e.164 format for phone numbers, "whatsapp:e.164" for WhatsApp, and "messenger:{messenger_id}" for FB Messenger.

        ContentSid new - String field used to identify the preconfigured content. Required to send templates created using Content Template Builder.
        ContentVariables new No JSON string used to define the values of any placeholder variables found in the preconfigured content. Key-value pairs of placeholder variable names and substitution values.

        Send Messages with a MessagingServiceSid Field

        Body and MediaUrl should be excluded. They are both not required. They are both superseded by the ContentSid

        Loading Code Sample...
              
              

              Send Messages with a MessagingServiceSid Field

              This method lets you keep using the From field to specify the Sender ID. You need to reference a Messaging Service by including a new MessagingServiceSid field. Note that while a Messaging Service is required, you do not have to add the sender to its Sender Pool (more on this later). This may be an easier way to get started if you are new to Messaging Services. Here are all the fields used in the API request:

              Field Required Description
              From Yes The sender that is initiating the message. Use e.164 format for phone numbers, "whatsapp:e.164" for WhatsApp, and "messenger:{messenger_id}" for FB Messenger.
              To Yes

              The identifier of the recipient you are sending the message to. Use e.164 format for phone numbers, whatsapp:e.164 for WhatsApp, and messenger:{messenger_id} for FB Messenger.

              MessagingServiceSid new Yes The Messaging Service Sid, MGXXXXXXXX
              ContentSid new Yes String field used to identify the preconfigured content. Required to send templates created using the Content Template Builder.
              ContentVariables new No JSON string used to define the values of any placeholder variables found in the preconfigured content. Key-value pairs of placeholder variable names and substitution values.
              Rate this page:

              Need some help?

              We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

              Loading Code Sample...
                    
                    
                    

                    Thank you for your feedback!

                    Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

                    Sending your feedback...
                    🎉 Thank you for your feedback!
                    Something went wrong. Please try again.

                    Thanks for your feedback!

                    thanks-feedback-gif