If your mobile app offers users the option to receive one-time passwords or verification codes via WhatsApp, you must use an authentication template.
Authentication templates consist of:
Fixed, non-customizable preset text: <VERIFICATION_CODE> is your verification code.
An optional security disclaimer: For your security, do not share this code.
An optional expiration warning: This code expires in <NUM_MINUTES> minutes.
Either a one-tap autofill button, a copy code button, or no button at all if using zero-tap.
One-tap autofill buttons are the preferred solution as they offer the best user experience. However, one-tap autofill buttons are currently only supported on Android and require additional changes to your app’s code.
Linked device security
Authentication templates now feature linked device security. This means that authentication messages are only delivered to a user’s primary WhatsApp device.
Authentication messages that are sent to a user’s linked devices are masked with a prompt instructing the user to view the message on their primary device.
This feature is enabled by default and does not require code changes. It cannot be configured or customized. Only available on Cloud API.
One-tap autofill authentication templates
Authentication templates include a one-tap autofill button.
When a WhatsApp user taps the autofill button, the WhatsApp client triggers an activity which opens your app and delivers it the password or code.
Copy code authentication templates allow you to send a one-time password or code along with a copy code button to your users.
When a WhatsApp user taps the copy code button, the WhatsApp client copies the password or code to the device’s clipboard. The user can then switch to your app and paste the password or code into your app.
Zero-tap authentication templates allow your users to receive one-time passwords or codes via WhatsApp without having to leave your app.
When a user in your app requests a password or code and you deliver it using a zero-tap authentication template, the WhatsApp client broadcasts the included password or code, which your app can then capture with a broadcast receiver.
Confirm the user’s WhatsApp phone number before sending the one-time password or code to that number.
Make it clear to your user that the password or code will be delivered to their WhatsApp phone number, especially if you offer multiple ways for the user to receive password or code delivery. See Getting Opt-In for additional tips.
When the user pastes the password or code into your app, or your app receives it as part of the one-tap autofill button flow, make it clear to the user that your app has captured it.
You can generate previews of authentication template text in various languages that include or exclude the security recommendation string and code expiration string using the GET /<WABA_ID>/message_template_previews endpoint.
{
"data": [
{
"body": "*{{1}}* is your verification code. For your security, do not share this code.",
"buttons": [
{
"autofill_text": "Autofill",
"text": "Copy code"
}
],
"footer": "This code expires in 10 minutes.",
"language": "en_US"
},
{
"body": "Tu código de verificación es *{{1}}*. Por tu seguridad, no lo compartas.",
"buttons": [
{
"autofill_text": "Autocompletar",
"text": "Copiar código"
}
],
"footer": "Este código caduca en 10 minutos.",
"language": "es_ES"
}
]
}
Bulk management
Use the POST /<WABA_ID>/upsert_message_templates endpoint to bulk update or create authentication templates in multiple languages that include or exclude the optional security and expiration warnings.
If a template already exists with a matching name and language, the template will be updated with the contents of the request, otherwise, a new template will be created.
Request syntax
POST /<WHATSAPP_BUSINESS_ACCOUNT_ID>/upsert_message_templates
All template creation properties are supported, with these exceptions:
The language property is not supported. Instead, use languages and set its value to an array of language and locale code strings. For example: ["en_US","es_ES","fr"].
The text property is not supported.
The autofill_text property is not supported.
Example copy code request
This example creates three authentication templates in English, Spanish, and French, with copy code buttons. Each template is named “authentication_code_copy_code_button” and includes the security recommendation and expiration time.
This example (1) updates an existing template with the name “authentication_code_autofill_button” and language “en_US”, and (2) creates two new authentication templates in Spanish and French with one-tap autofill buttons. Both newly created templates are named “authentication_code_autofill_button” and include the security recommendation and expiration time.
See our WhatsApp One-Time Password (OTP) Sample App for Android on Github. The sample app demonstrates how to send and receive OTP passwords and codes via the API, how to integrate the one-tap autofill and copy code buttons, how to create a template, and how to spin up a sample server.
Learn more
Official Business Account — You may wish to request Official Business Account status to build trust with your users, which will reduce the likelihood that they dismiss or ignore your messages.
Status messages webhooks — We recommend that you subscribe to the messages webhook field so you can be notified when a user receives and reads your authentication template with an OTP button.