Create an Authentication Template Message
POST Method
The Create an Authentication Template Message API allows you to create an authentication template with the Copy Code button option.
- Sign up for free
Before you get started, Create 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.
- Pre-requisites
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: https://developers.kaleyra.io/docs/manual-signup
And https://developers.kaleyra.io/docs/embedded-signup
The following are the prerequisites for creating authentication templates:
- You must use the copy_code button type so that no URLs, media, and emojis are passed.
- You must use WhatsApp’s preset authentication message templates, which include optional add-ons such as security disclaimers and expiry warnings.
- Create an Authentication Template Message API request.
You can use this API to create an authentication template message through your WhatsApp account.
Base URL:
<https://api.kaleyra.io/v1/<SID>
API request to create an Authentication Template message with the Copy Code button type
To create an authentication template message, use the /whatsapp/template
endpoint with the following request method:
Request Format
The following is the request format for the Copy Code button type:
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 'body="{\"add_security_recommendation\": \"true\"}"' \
--form 'button_data="[
{
\"type\": \"<type>\",
\"otp_type\": \"<otp_type>\",
\"text\": \"<text>\"
}
]";type: <type>' \
--form 'footer:"{\<footer>}"' \
--form 'waba_id: <waba_id>'
Sample Request Format:
The following is the sample request format for the Copy Code button type:
curl --location 'https://api.kaleyra.io/v1/HXAP16XXXXXX97IN/whatsapp/template' \
--header 'api-key: Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxbf2' \
--form 'name: "auth1"' \
--form 'category: "authentication"' \
--form 'language: "en"' \
--form 'body:"{\"add_security_recommendation\": \"true\"}"' \
--form 'button_data="[
{
\"type\": \"OTP\",
\"otp_type\": \"COPY_CODE\",
\"text\": \"Copy_OTP\"
}
]";type: "application/json"' \
--form 'footer:"{\"code_expiration_minutes\": 2}"' \
--form 'waba_id: "20900XXXXXXX9743"'
Parameters and Data Types
The following table describes the parameters used in the Authentication Template message for the Copy Code button type.
Parameter | Variable | Description | Example | Mandatory? |
---|---|---|---|---|
sid | String | Account SID (Security Identifier). | HXXXXXXX071US | Yes |
api_key | String | Your API Key generated by Kaleyra.io. | A1cc97a573f1aXXXXXXXXXXX3b986e039 | Yes |
name | String or Integer | Template name. | auth1 | Yes |
category | String | Enter the template category. Only Authentication is supported. | authentication | Yes |
language | String | The language in which, you want to create the template. | en_us | Yes |
body | String | Body of the message. | {"add_security_recommendation": "true"} | Yes |
button_data | String | The button_data object in the API request defines the fields that will be shown to the end-user. It can be one of the following: - Copy Code - OTP | The type is OTP and the otp_type is Copy Code | Yes |
footer | String | Footer preset text. Note: The code_expiration_minutes value can be a maximum of 90 minutes and a minimum of 1 minute. | {"code_expiration_minutes": "2"} | Yes |
waba_id | Integer | WhatsApp Business Account ID. | xxxxxxxxxxxxxx74443 | Optional |
The following table describes the different attributes used for the button_data object.
Parameter | Variable | Description | Example | Mandatory? |
---|---|---|---|---|
type | String | Specifies the button data type. | OTP | Yes |
otp_type | String | Specifies the type of OTP. | COPY_CODE | Yes |
text | String | Text to be displayed on the button with 25 characters. | Copy Code | Yes |
Sample Success Response for Code Code
The following success message appears with the status 200 Accepted:
{
"status": 200,
"message": "Template created successfully.",
"data": [],
"error": {}
}
Sample Failure Response for Copy Code
The following are some of the failure responses for the Copy Code button type.
{
"error": {
"code": "WAE0019",
"type": "VALIDATION_ERROR",
"parameter": "Footer",
"message": "Footer should be set in Authentication templates",
"reference": ""
}
}
{
"error": {
"code": "WAE0018",
"type": "VALIDATION_ERROR",
"parameter": "button_data",
"message": "Specify a button type under button_data",
"reference": ""
}
}
{
"error": {
"code": "WAE0020",
"type": "VALIDATION_ERROR",
"parameter": "Body",
"message": "Body should be set in Authentication templates",
"reference": ""
}
}
Error Codes
For information related to the WhatsApp error code, see WhatsApp Error Codes.
Updated 8 months ago