Create a Coupon Code Template

The coupon code templates are templates that can be used to send a ‘coupon code’ displayed as a button on the end user’s device. When this button is tapped, the code gets copied to the end user’s phone clipboard. Each Coupon Code template can contain only one coupon code. The coupon code templates have the ‘marketing’ category mandated by Meta.
Using Kaleyra’s API, you can create coupon code templates and send the coupon code template messages to your customers.

Following are the prerequisites to create a coupon code template:

  1. An active kaleyra.io account, if you do not have, you can contact a kaleyra representative to sign up for free to the platform.
    Before you get started,Create a Kaleyra Account and Create an API Key. To view the API Key and the SID, see View API Key and SID.

  2. An active WhatsApp for Business API plan.
    The following are the prerequisites for using Kaleyra WhatsApp APIs to create a coupon code template and send WhatsApp messages using coupon code template:

    • A WhatsApp business number.
    • An associated profile with the business number.
    • A WhatsApp verified and approved profile.

    You can use the coupon code template in a WhatsApp message to send a coupon code message through your WhatsApp account. The following is a sample screen for a WhatsApp coupon code message on the end customer’s phone:

WhatsApp API request format to create a coupon code template

The following API request creates a marketing template that has a coupon code.

curl --location 'https://api.kaleyra.io/v1/<sid>/whatsapp/template' \
--header 'api-key: <api-key>' \
--form 'name="<name>"' \
--form 'category="<category>"' \
--form 'language="<language>"' \
--form 'header="{\"type\": \"image\"}";type=application/json' \
--form 'body="<body>"' \
--form 'button_data="[
 {
	\"type\":\"<type>l\",
	\"website_url_type\":\"<website_url_type>",
	\"website_button_text\":\"<button_text>",
	\"website_url\":\"<website_url>\"
},


{
        \"type\": \"<type>",
        \"text\": \"<text>\"
 }
] ";type=application/json' \
--form 'sample_body="<body>"' \
--form 'example="{
        \"body_text\": [
          [
            \"<body_text>",
            \"<body_text>"
          ]
        ]
      }"' \
--form 'sample_media_file=@"<sample_media>"' \
--form 'sample_media_url="<sample_media_url>"'

Sample WhatsApp API request for coupon code template

The following API request creates a coupon code template.

curl --location 'https://api.kaleyra.io/v1/HXIN1784509XXXXX/whatsapp/template' \
--header 'api-key: XXXXX77c4d1cfa6854a7423a68e7XXXXX' \
--form 'name="cc_img_statics20"' \
--form 'category="marketing"' \
--form 'language="en"' \
--form 'header="{\"type\": \"image\"}";type=application/json' \
--form 'body="Hi {{$1}}, please avail {{$2}} off of all items!! grab now"' \
--form 'button_data="[
 {
				\"type\":\"url\",
				\"website_url_type\":\"static\",
				\"website_button_text\":\"button\",
				\"website_url\":\"https://www.favorite_shop.com\"
			},
	{
        \"type\": \"COPY_CODE\",
        \"text\": \"250OFF\"
        }
] ";type=application/json' \
--form 'sample_body="Hi {{$1}}, please avail {{$2}} off of all items!! grab now"' \
--form 'example="{
        \"body_text\": [
          [
            \"pablo\",
            \"25%\"
          ]
        ]
      }"' \
--form 'sample_media_file=@"https://www.kaleyra.com/wp-content/uploads/kaleyra.png"' \
--form 'sample_media_url="https://d38vr2u95vsr9f.cloudfront.net/docs/16879300632.jpg"'

Parameter Description Table

Following table shows the list of parameters and data types supported for Coupon Code template:

ParameterData TypeDescriptionExampleMandatory?
SIDStringSecurity Identifier of your Kaleyra.io account.HXXXXXXX071USYes
content_typeStringIndicates the format of the content the API will be processing.application/jsonYes
api_key String Your API Key generated by Kaleyra.io. Ac4XXXXX21f Yes
name String The template name.
The template name can be a maximum of 512 characters.
coupon_cd_template Yes
to_number String Valid WhatsApp number of the recipient. Ensure that the country code is prefixed to the number. (E164 format).
Note: You can add multiple numbers and separate each number using the comma (,) delimiter.
+1202XXXXXXX Yes
channel_name String Channel on which the message is sent.
For the WhatsApp channel, the only allowed value is WhatsApp.
WhatsApp Yes
from_no String The number registered with WhatsApp business from which the message is to be sent. Ensure that the country code is prefixed to the number. (E164 format). +1202XXXXXXX Yes
body String Body of the message. Hi User No
language String The language in which the message is sent. en Yes
category String The message category.
Note: Only ‘Marketing’ value is accepted for the Coupon Code template.
Marketing Yes
sample_media_file StringThe location of the media file that is embedded in the message.
Ensure that you only use the media files in the supported formats.
Refer to
Messaging on WhatsApp Business for more details.
@"https://www.kaleyra.com/wp-content/uploads/kaleyra.png" Yes
sample_media_url StringThe media URL should be public and have a file extension.

Note:

URL path is supported for image/video/media instead of uploading it.
If both sample_media and media_url are passed in API request, then only "media_url" will be considered.
If the template header has media then the sample media should have a media file or upload the path of the media file in the sample _media _URL field. Otherwise, it's not mandatory.
https://www.kaleyra.com/wp-content/uploads/kaleyra.png No
button_data ObjectThis is the button object that holds the details about the buttons that appear as part of the message. button_data=
"[
{
"type":"url",
"website_url_type":"static",
"website_button_text":"button",
"website_url":"https://www.favorite_shop.com/"
},
Yes
example ObjectExample object shows how to pass dynamic values in the dynamic variables in the message body.

Note: This parameter is required only, if the message body has dynamic variables.
example="{
"body_text": [
[
"pablo",
"25%"
]
]
}"
No

The following table describes the objects’ parameters in the Coupon Code template request.

Example object parameters description table

ParameterData TypeDescriptionExampleMandatory?
body_text StringThe values in this field are the dynamic values that you pass for each of the dynamic variables in the message body.body_text:Pablo
body_text:CARIBE25

In the message body:
Hi {{$1}}, please avail {{$2}} off of all items! grab now!!

{{$1}} and {{$2}} are the two dynamic variables.

For these two variables, you can pass the values:
"Pablo" and "CARIBE25" respectively.
Yes

Button_data object parameters description table

ParameterData TypeDescriptionExampleMandatory?
type String The type of the button based on its purpose. url Yes
website_url_type String The type of url the button contains
The values can be ‘static’ or ‘dynamic’.
static Yes
website_button_text StringThe text (caption) the button displays button Yes
website_url StringThe URL that the button takes you to, when clicked. https://www.favorite_shop.com Yes

Sample success response

The following is a sample success response.

{
    "status": 200,
    "message": "Template created successfully.",
    "data": [],
    "error": {} }

Samples error response

The following is a sample error response.

 "error": {  
        "code": "E413",  
        "type": "VALIDATION_ERROR",  
        "parameter": "category",  
        "message": "Invalid template category. Accepted categories are authentication, marketing, utility",  
        "reference": ""
        }

Sample error response

The following is a sample error response.

{  
    "error": {  
        "code": "E996",  
        "type": "VALIDATION_ERROR",  
        "parameter": "name",  
        "message": "Template name already taken!",  
        "reference": ""  
    }  
}