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.

  1. 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.

  1. 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.
  1. 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_domain>/v1/<SID>

API Domain and Value

api_domainValue
IN podapi.in.kaleyra.io
SG Podapi.kaleyra.io
EU Podapi.eu.kaleyra.io
NA podapi.na.kaleyra.ai

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_domain>/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.in.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).

HXXXXXXX071IN

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.

ParameterVariableDescriptionExampleMandatory?
typeStringSpecifies the button data type.OTPYes
otp_typeStringSpecifies the type of OTP.COPY_CODEYes
textStringText to be displayed on the button with 25 characters.Copy CodeYes

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.





© 2025 Kaleyra Inc. All rights reserved.
Trademarks, logos and service marks displayed on this site are registered and unregistered trademarks of Kaleyra Inc.