Skip to content

⚡ OTPless Authentication

WhatsApp Magic Link

This is Emacron's separate OTPless message-link flow, not Meta One-Tap or Zero-Tap. The user opens WhatsApp from your app, reviews and sends a pre-filled message, then Emacron verifies the session when the inbound webhook is received. The user does not type OTP digits, but must still send the message.

No OTP digits

Typed by the user

Send required

User action in WhatsApp

Webhook

Confirms the session

WhatsApp billing: The user's message to your number is inbound. Emacron sends an outbound service reply to confirm verification. Since October 1, 2026, Meta includes 1,000 delivered service messages per business phone number each month, then may charge for additional replies. Standard OTP uses a billable AUTHENTICATION template and is not covered by this allowance. Meta bills the connected business account; Emacron does not deduct Lead Finder credits for these flows.
StepCopy Code OTPOTPless message link
User seesAn OTP entry prompt in the appA "Continue with WhatsApp" action
User doesReceives and enters the codeOpens WhatsApp and sends the pre-filled message
OTP digitsEntered by the userNot entered by the user
VerificationThe app submits the codeThe inbound WhatsApp webhook confirms the session
Meta One-Tap / Zero-Tap?NoNo — this is a separate OTPless flow

How it works

For project-specific authentication, create a WhatsApp OTPless or combined key in Settings → API Keys. Assign a sender, prefilled message, and success reply. Tap and QR links use the same settings. Use the key from your server to create and check sessions, and register approved HTTPS origins for any return URLs.

The session token is encoded as invisible Unicode zero-width characters (ZWJ/ZWNJ) inside the visible message. WhatsApp includes them when the user taps Send. Treat the generated login links as sensitive until the session expires.

01

Your backend calls /magic-link/init

Returns session_id, wa_link (mobile button), scan_url (desktop QR), and stores your redirect_url.

02

Frontend shows button (mobile) or QR (desktop)

Detect mobile with navigator.userAgent. Mobile: <a href={wa_link}>. Desktop: <QRCodeSVG value={scan_url} />.

03

User taps or scans

WhatsApp opens with the pre-filled message that has an invisible verification token embedded in it.

04

User hits Send

The message with the hidden token arrives in your workspace WhatsApp inbox.

05

Webhook decodes token

Token is extracted, matched to session, session marked verified. Zero code entered or seen.

06

Poll returns verified: true

Your backend checks the verified phone, completes its own application login, and can send the user to the approved return URL.

Authentication

All init and status requests require an API key. Only the /scan redirect is public.

Header

Authorization: Bearer oa_live_xxx

Base URL

https://api.crm.emacronai.com/api/v1

Get keys

Settings → API Keys

🚫 CAUTION — Never call /magic-link/init from the browser

Your oa_live_xxx API key would be visible in the browser Network tab and could be stolen.

Browser → Your Backend → EmacronAI CRM API (API key lives here only)
Browser ← { wa_link, scan_url, expires_at } ←──

Correct pattern: Frontend calls your own backend (e.g. POST /api/auth/whatsapp/init) → your backend calls EmacronAI CRM with the API key, stores the session ID against the current login attempt, and returns wa_link, scan_url, expires_at to the frontend.

If the API returns 401, check the server’s API key. A 403 indicates an access or scope issue.

POST/api/v1/whatsapp/magic-link/init

Creates a new OTPless session. Returns wa_link for mobile and scan_url for desktop QR.

Request body

FieldTypeRequiredDescription
contextstringNoTag for the session, e.g. 'login', 'signup', 'payment'. Max 64 chars. Returned in status.
redirect_urlstring (URL)NoYour app’s return URL. Project keys require an approved HTTPS origin. Legacy keys accept HTTP or HTTPS. Maximum 2,048 characters.
phone_number_idstringNoProject keys use the assigned number. If supplied, this ID must match. Legacy requests default to the workspace sender.

Response — 200 OK

FieldTypeDescription
session_idstring (uuid)Use to poll /status. Never expose to end-users.
wa_linkstring (URL)wa.me deep-link. href for the "Continue with WhatsApp" button on mobile.
scan_urlstring (URL)✅ Use this for QR codes. Short ~70-char URL, scans cleanly on all devices. Redirects to wa_link server-side.
qr_linkstring (URL)⚠️ Deprecated. Compatibility link — always use scan_url instead.
message_textstringVisible message text (invisible token is embedded inside). Informational.
redirect_urlstring | nullReturn URL echoed from the request.
expires_innumberSession TTL in seconds (300 = 5 minutes).
expires_atstring (ISO)UTC timestamp of expiry. Show a countdown on your frontend.

🚫 Call /init from your backend — not from React/Vue/mobile

Exposing your API key in frontend code lets anyone read it from the browser Network tab. See the Authentication section above for the correct architecture.

cURL — init session (run from your backend)
# 1. Init a session (call from YOUR backend — never from the browser)
curl -X POST https://api.crm.emacronai.com/api/v1/whatsapp/magic-link/init \\
  -H "Authorization: Bearer oa_live_xxx" \\
  -H "Content-Type: application/json" \\
  -d '{
    "context": "login",
    "redirect_url": "https://yourapp.com/auth/callback"
  }'

# Response:
{
  "session_id":   "550e8400-e29b-41d4-a716-446655440000",
  "wa_link":      "https://wa.me/919272117887?text=Verify%E2%80%8D...",
  "scan_url":     "https://api.crm.emacronai.com/api/v1/whatsapp/magic-link/UUID/scan",
  "qr_link":      "https://wa.me/919272117887?text=login+3f9a8b2c",
  "message_text": "Verify my login to Acme",
  "redirect_url": "https://yourapp.com/auth/callback",
  "expires_in":   300,
  "expires_at":   "2026-09-04T07:00:00Z"
}

GET/api/v1/whatsapp/magic-link/:session_id/status

Poll every 2–3 seconds. Returns verified: true with phone and redirect_url once the user sends the WhatsApp message.

FieldWhen presentDescription
verifiedAlwaystrue once the user has sent the WhatsApp message.
phoneverified = trueStrict E.164 — no spaces or dashes. Always +[country][number] e.g. '+917840985216' (not '+91 784...'). Normalize before DB lookup.
verified_atverified = trueISO timestamp of when the token was decoded.
contextverified = trueContext string you passed to init().
redirect_urlverified = trueReturn URL supplied to init. Complete login on your backend before navigating.
expires_atverified = falseWhen session expires. After this, returns 400 with error: "expired".

📞 Phone number format — important

The phone field is always returned in strict E.164 format with no spaces, dashes, or parentheses — e.g. +917840985216. If your database stores numbers with spaces or formatting, a direct string comparison will silently return 0 rows. Always normalize both sides before comparing:

// ✅ Safe — strip all spaces before DB lookup const phone = data.phone.replace(/\s+/g, ''); const user = await db.users.findOne({ phone }); // ✅ Even better — store in strict E.164 at write time // so comparisons always work without normalization
cURL — poll status
# 2. Poll status every 2-3 seconds
curl https://api.crm.emacronai.com/api/v1/whatsapp/magic-link/UUID/status \\
  -H "Authorization: Bearer oa_live_xxx"

# Before verification:
{ "verified": false, "expires_at": "2026-09-04T07:00:00Z" }

# After user sends the WhatsApp message:
{
  "verified":     true,
  "phone":        "+919876543210",
  "verified_at":  "2026-09-04T06:58:23Z",
  "context":      "login",
  "redirect_url": "https://yourapp.com/auth/callback"
}

redirect_url — return users to your app

Supply redirect_url in the init request to give users a return destination. Project keys require an approved HTTPS origin. The WhatsApp reply includes this link when the project’s return-link option is enabled. The verified status response also returns it.

Your backend completes login after checking the status of its own pending session. Keep credentials and login tokens out of URLs.

Desktop QR code + Mobile button

On desktop, users cannot tap a wa.me link. Show a QR code using scan_url (a short ~70-char URL — produces a clean, easy-to-scan code). On mobile, show a <a href={wa_link}> button that opens WhatsApp directly. Detect device with navigator.userAgent.

📱 Mobile

Show wa_link as an anchor tag. Tapping opens WhatsApp with the pre-filled message.

🖥️ Desktop

Show QR code with scan_url as value. User scans with phone, WhatsApp opens, they send the message.

React — isMobile detection + conditional QR / button
import { QRCodeSVG } from 'qrcode.react';
import { useState, useEffect } from 'react';

function WhatsAppLoginWidget({ wa_link, scan_url }) {
  const [isMobile, setIsMobile] = useState(false);

  useEffect(() => {
    setIsMobile(/Android|iPhone|iPad|Mobile/i.test(navigator.userAgent));
  }, []);

  return (
    <div>
      {isMobile ? (
        // Mobile: tap button opens WhatsApp directly
        <a href={wa_link} target="_blank" rel="noopener noreferrer">
          Continue with WhatsApp
        </a>
      ) : (
        // Desktop: QR code (use scan_url — it's short and scans cleanly)
        <div>
          <QRCodeSVG value={scan_url} size={200} />
          <p>Scan with your phone camera to verify</p>
        </div>
      )}
    </div>
  );
}

⚠️ React gotcha — countdown initialization causes instant false expiry

When state transitions to "pending", there is a render cycle where your countdown hasn't initialized yet and still reads 0. If you use secondsLeft === 0 as the expiry trigger, the handler fires instantly on the first render — showing “session expired” before the user even sees the QR code.

// ❌ Dangerous — triggers instantly on first render

const [secondsLeft, setSecondsLeft] = useState(0); useEffect(() => { if (state === "pending" && secondsLeft === 0) expire(); // fires immediately! }, [secondsLeft]);

// ✅ Safe — initialize to expires_in (e.g. 300)

const [secondsLeft, setSecondsLeft] = useState(300); // not 0 // Let polling handle real expiry — server returns 400 when expired. // Use the countdown only as a UX display indicator, not for control flow.

OTPless message settings

Edit project wording and return-link settings in Settings → API Keys. For legacy integrations, manage the workspace defaults in Settings → WhatsApp OTP → OTPless.

SettingDefaultDescription
verify_message"Verify my login to [AppName]"The visible pre-filled WhatsApp message text. Max 80 chars.
success_reply"✅ You're verified!..."Reply sent after successful verification. Max 300 chars.
include_fallback_linktrueAppend a tap-to-return link in the WA reply. Set false for server-side polling flows where you redirect programmatically.

Backend and browser example

Node.js / Express — session-bound polling
// BACKEND FILE (Node/Express). Mount after your application's session/CSRF middleware.
// Set EMACRON_API_KEY to a project key with whatsapp:otpless, or a legacy key with whatsapp:send. Never expose it to browser code.

const otplessApiKey = process.env.EMACRON_API_KEY;
const otplessBase = 'https://api.crm.emacronai.com';
async function callWhatsAppOtpless(path, body) {
  const response = await fetch(otplessBase + '/api/v1/whatsapp/' + path, {
    method: body ? 'POST' : 'GET',
    headers: { Authorization: 'Bearer ' + otplessApiKey, 'Content-Type': 'application/json' },
    ...(body ? { body: JSON.stringify(body) } : {}), signal: AbortSignal.timeout(45000)
  });
  const data = await response.json();
  if (!response.ok) throw Object.assign(new Error(data.error || 'Request failed'), {status:response.status,data,retryAfter:response.headers.get('Retry-After')});
  return data;
}
app.post('/auth/whatsapp/otpless/start', async (req, res, next) => {
  try {
    const data = await callWhatsAppOtpless('magic-link/init', {context:'login'});
    req.session.pendingWhatsAppSession = data.session_id;
    res.json({wa_link:data.wa_link,scan_url:data.scan_url,expires_in:data.expires_in});
  } catch(error) { next(error); }
});
app.get('/auth/whatsapp/otpless/status', async (req, res, next) => {
  try {
    const id = req.session.pendingWhatsAppSession;
    if (!id) return res.status(400).json({error:'Start verification first'});
    const data = await callWhatsAppOtpless('magic-link/' + encodeURIComponent(id) + '/status');
    if (data.verified) {
      delete req.session.pendingWhatsAppSession;
      // Resolve your own application user and rotate the application session here.
    }
    res.json({verified:data.verified});
  } catch(error) {
    if (error.status === 400 && error.data?.error === 'expired') {
      delete req.session.pendingWhatsAppSession;
      return res.json({verified:false,expired:true});
    }
    next(error);
  }
});

// SEPARATE BROWSER FILE. No API key or Authorization header here.
const otplessResponse = await fetch('/auth/whatsapp/otpless/start', {
  method:'POST',headers:{'Content-Type':'application/json'},
  body:JSON.stringify({})
});
const otplessData = await otplessResponse.json();
// Display otplessData.scan_url as a QR or otplessData.wa_link as a link. Poll /auth/whatsapp/otpless/status every 2s until verified/expired, for at most otplessData.expires_in seconds.

Error codes

HTTPcodeMeaning
400expiredSession expired (5 min TTL). Create a new session.
400invalid_redirect_urlUse an approved HTTPS origin for a project key.
400otpless_sender_overrideOmit phone_number_id or use the project’s assigned number.
409otpless_sender_unavailableCheck the assigned WhatsApp number in Settings → API Keys.
400no_wa_numberNo WhatsApp number connected. Go to Settings → WhatsApp.
401—API key is missing or wrong. Check Authorization: Bearer oa_live_xxx header and verify the key in Settings → API Keys.
403module_inactiveWhatsApp module not activated.
403—API key lacks permission for this workspace.
404—Session not found or belongs to a different workspace or project.
429magic_session_limit or —Session creation or polling limit reached. Respect Retry-After when supplied.
503—The service could not start the session. Retry after checking availability.

Rate limits

EndpointLimit
POST /magic-link/initProject keys: 250 sessions per project and 1,000 project sessions per workspace per hour
GET /magic-link/:id/statusProject keys: 1,200 polls per minute per key per server instance. Poll every 2–3 seconds until verified or expired.
GET /magic-link/:id/scanPublic QR redirect for an unused, unexpired session