Create a WhatsApp Template with Quick-Reply Button
POST Method
Kaleyra allows you to create WhatsApp templates with dynamic payloads with quick reply messages. This template type API allows you to add a payload to your WhatsApp messages in the form of Quick Reply buttons. Once the end-customer clicks the Quick Reply button in WhatsApp messages, they get redirected based on the configured payload tasks in the WhatsApp messages.
For example, if you have configured an automated message for items available for checkout in your cart, after the defined waiting time, an automated WhatsApp message gets triggered where you can provide options to check out the items in the cart by paying the bills, delete the items, or moving them to the wishlist.
Limitation:You can only add a maximum of three dynamic payloads in any given template to the Quick Reply buttons.
Pre-requisites
The following are the prerequisites:
- Before you get started, sign up for a Kaleyra.io account for free and Create an API Key. To view the API Key and the SID, see View API Key and SID.
- A prerequisite for using Kaleyra WhatsApp APIs is to have an active WhatsApp plan on kaleyra.io.
- To set up a WhatsApp account on kaleyra.io, see Manual Signup and Embedded Signup.
Base URL
https://api.kaleyra.io/v1/<SID>
API request to Create a WhatsApp Template with Dynamic Payload in Quick Reply Buttons
To create a WhatsApp template with a dynamic payload, use the /whatsapp/template
endpoint.
Request Format
The following is the request format to create a WhatsApp Template with a Dynamic Payload in Quick Reply buttons:
curl --location --request POST 'https://api.kaleyra.io/v1/<SID>/whatsapp/template' \
--header 'api-key: {{api-key}}' \
--header 'Content-Type: {{content_type}}' \
--data-raw '{
"name":"{{template_name}}",
"language":"{{template_language}}",
"category":{{template_category}},
"header":{{header_content_type}},
"header_content":"{{header_content}}",
"body": "{{message_body}}",
"footer_content": "{{footer_content}}",
"waba_id": {{whatsapp_business_id}},
"type": "{{type}}",
"sub_type": "{{sub_type}}",
"index": "{{index}}",
"parameters": [
{
"type": "{{parameter_type}}",
"payload": "{{payload}}"
}
]
}'
Sample Request
The following is the sample request to create a WhatsApp Template with a Dynamic Payload in Quick Reply buttons:
curl --location --request POST 'https://api.kaleyra.io/v1/HXXXXXXX071US/whatsapp/template' \
--header 'api-key: Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3' \
--header 'Content-Type: application/json' \
--data-raw '{
"name":"new_template_1",
"language":"en",
"category":"marketing",
"header": {
"type": "none"
},
"body": "Hi {{$1}},This is WhatsApp test message.",
"footer_content": "footer",
"waba_id": xxxxxxxxxxxxxx74443,
"type": "button",
"sub_type": "quick_reply",
"index": "0",
"parameters": [
{
"type": "payload",
"payload": "Text to send to customer"
}
]
}'
Parameters and Data Types
Following is the list of parameters and data types supported:
Parameter | Data Type | Description | Example | Mandatory |
---|---|---|---|---|
| String | Account SID (Security Identifier). | HXXXXXXX071US | Yes |
| String | The format in which the data is sent. | application/x-www-form-urlencoded | Yes |
| String | API key generated from Kaleyra.io account. | Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3 | Yes |
| String | Template name. | new_template_1 | Yes |
| String | The language in which you want to create the template. | en_us | Yes |
| String | Select one of the following:
| Marketing | Yes |
| String | Select one of the following: | Text | Yes |
| String | Header text | Text | Yes |
| String | Body of the message. | Hi, this is a WhatsApp test message. | Yes |
| String | Footer text | Text | No |
| String | WhatsApp Business Account ID | xxxxxxxxxxxxxx74443 | Yes |
| String | It can be one of the following:
| button | Yes |
| String | It can be one of the following:
| quick-reply | Yes |
| String | Set the index value as 0 to get the payload when the first Quick Reply button is clicked in the incoming callback. | 0 | Yes |
| String | Define the parameter type for payload in the quick-reply button. | payload | No |
| String | The payload data you want to send when the customer clicks the quick-reply button. | Text to send to customer. | No |
Sample Success Response
The following success message appears with status 200:
{
"status": 200,
"message": "Template created successfully.",
"data": [],
"error": {}
}
Sample error response
The following is a sample error response.
{
"code": "RBC201",
"message": "Incorrect SID or API key.",
"data": [],
"error": {
"error": "Incorrect SID or API key."
}
}
Error Codes
For information related to the WhatsApp error code, see WhatsApp Error Codes.
Note:For more information about, how to send a message with dynamic payload in the quick-reply button, see Send a Message with Dynamic Payload in Quick-reply Button.
Updated about 15 hours ago