Skip to main content

WhatsApp One-Time Codes

An authentication template sends a one-time code (OTP) - for a login, a sign-up or a payment - over WhatsApp. Your backend makes the code and sends it through the API; Joryio sends the message and charges it at the authentication rate, which is lower than marketing in most countries.

How it works​

  1. You create an authentication template once and Meta approves it.
  2. When a customer needs a code, your backend generates it, keeps it to check later, and calls POST /whatsapp/send/template with the code.
  3. The customer gets "123456 is your verification code." with a button to copy the code, or - on Android - to fill it into your app.

Joryio never makes, stores or checks the code: it passes it to WhatsApp and does not log it.

Create the template​

In WhatsApp → Templates, click Create Template, choose Authentication and One-time passcode, and click Continue. Meta writes the message text itself, so there is no body to type:

  • Code button - Copy code (every device), One-tap autofill (Android: the code fills into your app) or Zero-tap (Android: the code reaches your app with no tap at all).
  • Add the security note - adds "For your security, do not share this code."
  • Code expires after - 1 to 90 minutes. The message shows it, and the button stops working after it.
  • Button label and Autofill label - optional, up to 25 characters; leave them empty for WhatsApp's own label in the customer's language.
  • Delivery attempts for - how long WhatsApp keeps trying to deliver, 30 to 900 seconds (WhatsApp's default is 10 minutes). After that the code is likely expired anyway, so a short time stops a late code arriving.

No header, media, URL or emoji is allowed on an authentication template.

One-tap and zero-tap​

One-tap and zero-tap need your Android app:

  • Package name - for example com.example.shop (up to 5 apps).
  • App signature hash - the 11-character hash of your app's signing key, as Android's SMS Retriever computes it.
  • Zero-tap also needs Meta's zero-tap terms accepted.

Your app must start the WhatsApp handshake before you send the code. On a phone where the handshake did not happen - an iPhone, WhatsApp Web, another app - WhatsApp shows a Copy code button instead, so the customer always gets the code.

Send a code​

POST /whatsapp/send/template
{
"to": "+306912345678",
"templateId": "6f1c2d3e-0000-4000-8000-000000000002",
"otpCode": "482913",
"idempotencyKey": "login-482913-u1029"
}
  • otpCode - the code, up to 15 characters. Joryio puts it both in the text and in the button, as WhatsApp requires. Leave out bodyVariables.
  • idempotencyKey - recommended: a retry with the same key returns the first answer instead of sending a second code.

A template that is not an authentication template answers 400 when otpCode is set, and an authentication template answers 400 without it.

Response:

{ "success": true, "messageId": "wamid.HBgM…" }

Good practice​

  • Make the code expire on your side at the same time as Code expires after.
  • Limit how many codes one number can request - the API allows 10 sends a minute per account.
  • A contact who uses WhatsApp with a username and no phone number cannot receive an authentication template; a journey or campaign send to one is skipped (authentication_template_needs_phone).

Meta reference​