Utility template with variables in BODY
In this case, you create a template for order confirmation notifications:
- Contains text with 3 variables in the body.
- No header.
- No footer.
- No buttons.
Note:
- A template consists of
HEADER
,BODY
,FOOTER
, andBUTTONS
components. TheBODY
component is required, while the others are optional. - The template variables are placeholders (numbers wrapped with curly braces) used to send messages, such as
{{1}}
. You can replace these placeholders with actual values when you send messages. For an example of how to use variables when sendingtemplate
messages, see also WhatsApp Messaging Examples . - Variable parameters must be sequential in each template component. For example, it’s invalid that
{{1}}
,{{2}}
,{{4}}
,{{5}}
are defined but{{3}}
does not exist.
Code sample:
curl --location --request POST 'https://api.ycloud.com/v2/whatsapp/templates' \
--header 'X-API-Key: YOUR-API-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"wabaId": "WABA-ID",
"name": "order_confirmation",
"language": "en",
"category": "UTILITY",
"components": [
{
"type": "BODY",
"text": "Your order {{1}} for a total of {{2}} is confirmed. The expected delivery is {{3}}.",
"example": {
"body_text": [
[
"order9876",
"$99.99",
"February 25, 2023"
]
]
}
}
]
}'
Marketing template with image and Quick Reply buttons
In this case, you create a template for a specific campaign:
- Contains an image in the header.
- Contains text with 1 variable in the body.
- Contains text in the footer.
- Contains 2 Quick Reply buttons. The maximum number of Quick Reply buttons is 3.
Note:
- The
HEADER
component format can be one ofTEXT
,IMAGE
,VIDEO
, orDOCUMENT
. ForTEXT
, you need to provide a sample text inexample.header_text
. For the other media formats, that isIMAGE
,VIDEO
, orDOCUMENT
, you need to provide a sample URL inexample.header_url
. - The
FOOTER
component can only be text, and variables are not supported. - The
BUTTONS
component has two types of buttons: Quick Reply, and Call To Action. These button types are exclusive, which means you cannot use both of them in one template. Quick Reply buttons are limited to 3. Call To Actions buttons have at most 1PHONE_NUMBER
button, and at most 1URL
button. - For image media in the header, the
example.header_url
of the messaging request must end with one of.jpg
,.jpeg
, or.png
. Image size limit is 5MB. - For video media in the header, the
example.header_url
of the request payload must end with.mp4
. Video size limit is 16MB. - For document media in the header, the
example.header_url
of the request payload must end with.pdf
. Document size limit is 100MB.
Code sample:
curl --location --request POST 'https://api.ycloud.com/v2/whatsapp/templates' \
--header 'X-API-Key: YOUR-API-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"wabaId": "WABA-ID",
"name": "marketing_friday",
"language": "en",
"category": "MARKETING",
"components": [
{
"type:": "HEADER",
"format": "IMAGE",
"example": {
"header_url": "https://oss-ycloud-publicread.oss-ap-southeast-1.aliyuncs.com/sample/tmp/sample.jpg"
}
},
{
"type": "BODY",
"text": "Hi {{1}}, The Black Friday is coming!",
"example": {
"body_text": [
[
"Joe"
]
]
}
},
{
"type": "FOOTER",
"text": "FOOTER-TEXT"
},
{
"type": "BUTTONS",
"buttons": [
{
"type": "QUICK_REPLY",
"text": "Learn more"
},
{
"type": "QUICK_REPLY",
"text": "Unsubscribe"
}
]
}
]
}'
Marketing template with video and Call To Action buttons
In this case, you create a template for a specific campaign:
- Contains a video in the header.
- Contains text with 1 variable in the body.
- Contains text in the footer.
- Contains 2 Call To Action buttons: 1
PHONE_NUMBER
button, and 1URL
button. TheURL
button can have at most 1 variable at the end of the URL.
Note:
- When you set a dynamic
URL
button, which contains a variable at the end of the URL, you should provide a full URL inexample
other than a sample value for the variable.
Code sample:
curl --location --request POST 'https://api.ycloud.com/v2/whatsapp/templates' \
--header 'X-API-Key: YOUR-API-KEY' \
--header 'User-Agent: Apifox/1.0.0 (https://www.apifox.cn)' \
--header 'Content-Type: application/json' \
--data-raw '{
"wabaId": "WABA-ID",
"name": "marketing_friday_more",
"language": "en",
"category": "MARKETING",
"components": [
{
"type:": "HEADER",
"format": "VIDEO",
"example": {
"header_url": "https://oss-ycloud-publicread.oss-ap-southeast-1.aliyuncs.com/sample/tmp/sample.mp4"
}
},
{
"type": "BODY",
"text": "Click the URL bellow to see more about {{1}} campaign.",
"example": {
"body_text": [
[
"The Friday"
]
]
}
},
{
"type": "FOOTER",
"text": "FOOTER-TEXT"
},
{
"type": "BUTTONS",
"buttons": [
{
"type": "URL",
"text": "Visit website",
"url": "https://www.youtube.com/watch?v={{1}}",
"example": [
"https://www.youtube.com/watch?v=zvI4cVGWJhM"
]
},
{
"type": "PHONE_NUMBER",
"text": "Call us",
"phone_number": "+447901614024"
}
]
}
]
}'