Chatilo
USDPrices shown in US dollars Sign in Start free trial
Guide

Verify a phone number with a one-time code

Use one-time codes on your own website or app: when someone signs up, signs in or checks out, send a code to their phone and check what they type. The code is made, sent, expired and checked for you, and it is never returned to your server.

Before you start #

  • An API key with read-and-write scope. See Getting started.
  • For WhatsApp: a connected WhatsApp number and an approved template that carries the code. An authentication template is the right kind: create it in WhatsApp Manager with a copy-code button, then use Sync on the Templates page so it appears here. Any other approved template works too, as long as its first body variable is the code.
  • For SMS: an SMS account connected under More channels.

Call these endpoints from your server, never from the browser: the API key must stay secret.

  1. Send the code #

    When the person enters their number, ask for a code to be sent. Six digits, good for ten minutes, unless you say otherwise with length and expires_in.

    Send a code on WhatsApp
    curl -X POST "https://chatilo.me/api/v1/otp" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "to": "+919876543210",
        "channel": "whatsapp",
        "template": "login_code"
    }'

    By SMS, leave the template out:

    Send a code by SMS
    curl -X POST "https://chatilo.me/api/v1/otp" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "to": "+919876543210",
        "channel": "sms"
    }'

    The answer tells you when the code expires. It does not contain the code.

  2. Check what they typed #

    Check a code
    curl -X POST "https://chatilo.me/api/v1/otp/verify" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "to": "+919876543210",
        "code": "482913"
    }'

    Read verified. It is true once, for the right code; after that the code is spent. When it is false, reason says why:

    • wrong_code: let them try again.
    • expired or not_found: send a new code.
    • too_many_attempts: five wrong tries lock the code. Send a new one.
  3. Offer “Send again” with a pause #

    One code can go to a number every 30 seconds, and five in an hour. Sooner than that answers 429 otp_throttled. Show a countdown on your “Send again” button so people do not hit it.

Good practice #

  • Treat a number as verified only after verified: true from your own server’s call.
  • Do not tell the visitor whether a number already has an account before the code is verified.
  • A new code replaces the earlier one for the same number, so only the latest message works.
  • Codes sent this way are not saved as contacts or conversations.

Cookies on this site

We use the cookies needed to run the site and keep you signed in. With your OK we also remember choices you make here, such as the currency for prices. We don’t use advertising or tracking cookies. Cookie policy