Send a Limited Time Offer (LTO) Code Template Message
Using a WhatsApp LTO code template, you can send a WhatsApp LTO code message.
Following are the steps to send a WhatsApp LTO code message.
- Pre-requisites:
- 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.. - An active WhatsApp for Business API plan that includes:
A WhatsApp business number.
An associated profile with the business number.
A WhatsApp verified and approved profile.
- 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.
- Create a WhatsApp LTO code template. See, Create an LTO template.
- Use the LTO code template in a WhatsApp message to send a LTO code message.
The following API request format is for sending a WhatsApp message with an LTO template.
curl --location 'https://api.kaleyra.io/v1/<sid>/messages' \
--header 'api-key: <api-key>' \
--form 'to="<to-number>"' \
--form 'type="mediatemplate"' \
--form 'template_name="<template_name>"' \
--form 'channel="whatsapp"' \
--form 'from="<from-no>"' \
--form 'coupon_code="\"<coupon_code>\""' \
--form 'limited_time_offer="[
{
\"type\": \"limited_time_offer\",
\"limited_time_offer\": {
\"expiration_time_ms\": <expiration_time>
}
}
]"' \
--form 'media=@"/path/to/file"' \
--form 'callback_profile_id="<callback_profile_id>"' \
--form 'param_url="login"' \
--form 'media_url="<media_url>"'
WhatsApp message API request with LTO template
The following API request sends a WhatsApp message with an LTO template.
curl --location 'https://api.kaleyra.io/v1/HXIN1784509XXXXX/messages' \
--header 'api-key: Abf2e77c4d1cfa6854a7423a68e7XXXXX' \
--form 'to="1202XXXXXXX"' \
--form 'type="mediatemplate"' \
--form 'template_name="lto_true_vid_dyan_test"' \
--form 'channel="whatsapp"' \
--form 'from="1202XXXXXXX"' \
--form 'coupon_code="\"happy76\""' \
--form 'limited_time_offer="[
{
\"type\": \"limited_time_offer\",
\"limited_time_offer\": {
\"expiration_time_ms\":1209600000}
}
]"' \
--form 'media=@"/path/to/file"' \
--form 'callback_profile_id="IN_XXXXXXXX-046b-4565-892c-XXXXXXXXXXXX"' \
--form 'param_url="login"' \
--form 'media_url="https://d38vr2u95vsr9f.cloudfront.net/docs/1684759885mp4_file.mp4"'
Parameter Description Table
Following table shows the list of parameters and data types supported:
Parameter | Data Type | Description | Example | Mandatory? |
---|---|---|---|---|
SID | String | Security Identifier of your kaleyra.io account | HXXXXXXX071US | Yes |
api_key | String | Your API Key generated by Kaleyra.io. | Ac4XXXXX21f | Yes |
to | String | A valid WhatsApp number of the recipient. Ensure that the country code is prefixed to the number. (E164 format). Note: You can add multiple recipients, separate each number using the comma (,) delimiter. | +1202XXXXXXX | Yes |
type | String | The message type. | mediatemplate | Yes |
template_name | String | The template name. | LTO_template | Yes |
channel | String | Channel on which message must be sent. For the WhatsApp channel, the only allowed value is WhatsApp. | Yes | |
from | 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 |
callback_profile_id | String | The callback ID created for WhatsApp channel to receive updates about the message delivery status. Note: You can also use callback_url to get updates about the message delivery status to the specified URL. | In_XXXXXXXX-04XX-XXXX-XXXX-deac8de3c83d | No |
media_url | String | The 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 media and mediaurl are passed in API request, then only "media_url" will be considered. If a header is used, then only image/ video type is supported in the sample media field or sample _ media_url. Otherwise, this is not a mandatory field. | https://www.kaleyra.com/wp-content/uploads/kaleyra.png | No |
coupon_code | String | This field will hold the text that needs to be copied when the COPY CODE button is clicked. | coupon_code: “happy76”. | Yes |
limited_time_offer | object | This field holds the offer expiration time as UNIX TIMESTAMP which indicates the date on which the offer ends. Note: This object parameter is mandatory for an LTO template. | limited_time_offer: [ { "type": "limited_time_offer", "limited_time_offer": { "expiration_time_ms": 1209600000 }}] Note: This parameter is mandatory when the LTO template has ‘has_expiration’ parameter set to true. | No |
Limited_time_offer object parameters description table
The following table describes the object parameters in WhatsApp Message request that uses an LTO template.
Parameter | Data Type | Description | Example | Mandatory? |
---|---|---|---|---|
type | String | Type of the limited time offer object | limited_time_offer | Yes |
limited_time_offer | Object | This is an object parameter within the limited time offer object that has a time parameter to define the validity period of the offer. The ‘limited_time_offer’ parameter is an offer code expiration time in UNIX timestamp measured in milliseconds. | “limited_time_offer": { "expiration_time_ms": 1209600000} Note: This expiration time equals to 14 days when converted to days from milliseconds. | Yes |
expiration_time_ms | Numeric | This is a unix timestamp that represents the expiration time in milliseconds. | 1209600000 | Yes |
Sample success response
The following is a sample success response.
{
"id": "08a72b9e-9e0e-46af-a41b-2d87bf30e036",
"type": "mediatemplate",
"body": null,
"createdDateTime": "2024-01-12 07:08:43+00:00",
"totalCount": 1,
"data": [
{
"message_id": "08a72b9e-9e0e-46af-a41b-2d87bf30e036:0",
"recipient": "xx9986xx70xx"
}
],
"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."
}
}
Updated 3 months ago