whatsapp/authentication
The whatsapp/authentication content type allows companies to deliver a WhatsApp-approved one-time password button. Unlike other templates, the body is preset by WhatsApp. Some modifications can be made by specifying certain parameters. However, custom authentication templates aren't allowed.
Info
- When sending
whatsapp/authenticationcontent templates, a single variable must be defined at send time and set to the one-time passcode. whatsapp/authenticationcontent templates must be approved by WhatsApp before they can be sent to customers.

| Parameter | Type | Required | Variable support | Description |
|---|---|---|---|---|
add_security_recommendation | Boolean | No | No | Optional field to add the message "For your security, do not share this code" or the translated language's equivalent. This field defaults to TRUE. |
code_expiration_minutes | integer | No | No | The amount of time you want to inform the customer that the one-time passcode is available for. Adds a footer message stating "This code expires in x minutes," where x is the number specified. Only whole numbers from 1–90 are allowed. |
actions | array | Yes | No | Buttons that recipients can tap on to act on the message. |
To learn more about the actions parameter, see common components.
| Property | Parameters |
|---|---|
COPY_CODE |
|
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createContent() {11const content = await client.content.v1.contents.create({12friendly_name: "whatsapp_otp",13language: "en",14types: {15"whatsapp/authentication": {16add_security_recommendation: true,17code_expiration_minutes: 30,18actions: [19{20type: "COPY_CODE",21copy_code_text: "Copy verification code",22},23],24},25},26});2728console.log(content.dateCreated);29}3031createContent();
Response
1{2"sid": "HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"friendly_name": "whatsapp_otp",5"language": "en",6"variables": {7"name": "foo"8},9"types": {10"whatsapp/authentication": {11"add_security_recommendation": true,12"code_expiration_minutes": 30,13"actions": [14{15"type": "COPY_CODE",16"copy_code_text": "Copy verification code"17}18]19}20},21"url": "https://content.twilio.com/v1/Content/HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",22"date_created": "2015-07-30T19:00:00Z",23"date_updated": "2015-07-30T19:00:00Z",24"links": {25"approval_create": "https://content.twilio.com/v1/Content/HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ApprovalRequests/whatsapp",26"approval_fetch": "https://content.twilio.com/v1/Content/HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ApprovalRequests"27}28}
Copy code is the default authentication template. Copy code templates include a button that copies an OTP code to the user's clipboard.
- Create the
whatsapp/authenticationtemplate. - Follow the steps to send the template.
To send a whatsapp/authentication template, send it like any other content template, but include a content variable containing the one-time password (OTP) you want to send. The body field is preset and the template includes a pre-existing content variable for the OTP.
The OTP that you send must be fewer than 15 characters long.
--data-urlencode "ContentVariables={"1": "12345"}" \
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createMessage() {11const message = await client.messages.create({12contentSid: "HXXXXXXXXXX",13contentVariables: JSON.stringify({ 1: "123456" }),14from: "whatsapp:+18551234568",15messagingServiceSid: "MGXXXXXXXXXXX",16to: "whatsapp:+18551234567",17});1819console.log(message.body);20}2122createMessage();
Response
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"api_version": "2010-04-01",4"body": "Hello! 👍",5"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",6"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",7"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",8"direction": "outbound-api",9"error_code": null,10"error_message": null,11"from": "whatsapp:+18551234568",12"num_media": "0",13"num_segments": "1",14"price": null,15"price_unit": null,16"messaging_service_sid": "MGXXXXXXXXXXX",17"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",18"status": "queued",19"subresource_uris": {20"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"21},22"to": "whatsapp:+18551234567",23"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"24}