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:

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

sid

String

Account SID (Security Identifier).

HXXXXXXX071US

Yes

content-type

String

The format in which the data is sent.

application/x-www-form-urlencoded

Yes

api-key

String

API key generated from Kaleyra.io account.

Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3

Yes

name

String

Template name.

new_template_1

Yes

language

String

The language in which you want to create the template.

en_us

Yes

category

String

Select one of the following:

  • Marketing -Authentication
  • Utility

Marketing

Yes

header_content_type

String

Select one of the following:
Text
Image
Video Document
None

Text

Yes

header_content

String

Header text

Text

Yes

body

String

Body of the message.

Hi, this is a WhatsApp test message.

Yes

footer_content

String

Footer text

Text

No

waba_id

String

WhatsApp Business Account ID

xxxxxxxxxxxxxx74443

Yes

type

String

It can be one of the following:

  • text
  • template
  • mediatemplate
  • location
  • contacts
  • list
  • reply
  • singleproduct
  • multiproduct
  • button
  • *Note**: In case of quick-reply use "button".

button

Yes

sub_type

String

It can be one of the following:

  • QUICK_REPLY
  • PHONE_NUMBER
  • URL
    For a template with dynamic payload in Quick Reply, use “Quick Reply”.

quick-reply

Yes

index

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

parameter_type

String

Define the parameter type for payload in the quick-reply button.

payload

No

payload

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.