WhatsApp OTP Example

Request WhatsApp OTP from React

A safe React example that calls your own backend instead of calling DNZ directly.

Setup

  • Create a backend route such as /api/request-otp.
  • React sends only the phone number to your backend.

Code

async function requestOtp(phone) {
  const res = await fetch("/api/request-otp", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ phone }),
  });

  if (!res.ok) throw new Error("Unable to request OTP");
  return res.json();
}

Production notes

  • The browser never receives the DNZ API key.
  • Your backend should validate phone numbers and rate-limit requests.

Related links