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 at twilio.com/console5// Provision API Keys at twilio.com/console/runtime/api-keys6// and set the environment variables. See http://twil.io/secure7// For local testing, you can use your Account SID and Auth token8const accountSid = process.env.TWILIO_ACCOUNT_SID;9const apiKey = process.env.TWILIO_API_KEY;10const apiSecret = process.env.TWILIO_API_SECRET;11const client = twilio(apiKey, apiSecret, { accountSid: accountSid });1213async function createContent() {14const content = await client.content.v1.contents.create({15friendly_name: "whatsapp_otp",16language: "en",17types: {18"whatsapp/authentication": {19add_security_recommendation: true,20code_expiration_minutes: 30,21actions: [22{23type: "COPY_CODE",24copy_code_text: "Copy verification code",25},26],27},28},29});3031console.log(content.dateCreated);32}3334createContent();
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 at twilio.com/console5// Provision API Keys at twilio.com/console/runtime/api-keys6// and set the environment variables. See http://twil.io/secure7// For local testing, you can use your Account SID and Auth token8const accountSid = process.env.TWILIO_ACCOUNT_SID;9const apiKey = process.env.TWILIO_API_KEY;10const apiSecret = process.env.TWILIO_API_SECRET;11const client = twilio(apiKey, apiSecret, { accountSid: accountSid });1213async function createMessage() {14const message = await client.messages.create({15contentSid: "HXXXXXXXXXX",16contentVariables: JSON.stringify({ 1: "123456" }),17from: "whatsapp:+18551234568",18messagingServiceSid: "MGXXXXXXXXXXX",19to: "whatsapp:+18551234567",20});2122console.log(message.body);23}2425createMessage();
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}