WaForgeDevelopers

OTP and website

OTP API guide

The WaForge WhatsApp verification code API checks a phone number in two calls, using your own WhatsApp number. Your server asks WaForge to send a 6-digit code over WhatsApp from your connected number, then checks the code the person typed. Authentication is your secret API key.

Before you start #

  • Connect your WhatsApp number in the dashboard. Codes are sent from it; without a connected number /otp/send answers 409 instance_not_connected.
  • Create a secret key in Dashboard, API keys. Keep it on your server: WAFORGE_API_KEY=wf_sk_...
  • Base URL: https://waforge.online/api/v1. Every call is a POST with a JSON body and Authorization: Bearer wf_sk_....

The flow #

  1. The user enters their phone number on your site. Your server calls POST /otp/send and stores the returned request_id in the user's session.
  2. WaForge sends "Your verification code is 123456. Valid for 5 minutes." on WhatsApp.
  3. The user types the code. Your server calls POST /otp/verify with the request_id from the session and the code.
  4. On {"verified": true} you mark the phone as verified and remove the request_id from the session.

Send a code #

POST /api/v1/otp/send with {"phone": "+97455551234"}. Use the full international number with the country code. Maximum 32 characters.

cURL
curl -X POST https://waforge.online/api/v1/otp/send \
  -H "Authorization: Bearer $WAFORGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{"phone": "+97455551234"}'
PHP
<?php
function waforge(string $path, array $body): array
{
    $ch = curl_init('https://waforge.online/api/v1' . $path);
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer ' . getenv('WAFORGE_API_KEY'),
            'Content-Type: application/json',
            'Accept: application/json',
        ],
        CURLOPT_POSTFIELDS => json_encode($body),
    ]);
    $json = json_decode((string) curl_exec($ch), true) ?? [];
    $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
    curl_close($ch);

    return ['status' => $status, 'body' => $json];
}

$r = waforge('/otp/send', ['phone' => '+97455551234']);
if ($r['status'] === 200) {
    $_SESSION['otp_request_id'] = $r['body']['request_id'];
}
Laravel
use Illuminate\Support\Facades\Http;

$r = Http::withToken(config('services.waforge.key'))   // WAFORGE_API_KEY
    ->acceptJson()
    ->timeout(30)
    ->post('https://waforge.online/api/v1/otp/send', ['phone' => '+97455551234']);

if ($r->successful()) {
    session(['otp_request_id' => $r->json('request_id')]);
} else {
    $error = $r->json('error');   // for example "rate_limited" or "invalid_number"
}
Node.js
async function waforge(path, body) {
  const res = await fetch('https://waforge.online/api/v1' + path, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.WAFORGE_API_KEY}`,
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: JSON.stringify(body),
  });
  return { status: res.status, body: await res.json() };
}

const r = await waforge('/otp/send', { phone: '+97455551234' });
if (r.status === 200) req.session.otpRequestId = r.body.request_id;
Python
import os, requests

def waforge(path, body):
    r = requests.post("https://waforge.online/api/v1" + path, json=body, timeout=30,
                      headers={"Authorization": f"Bearer {os.environ['WAFORGE_API_KEY']}", "Accept": "application/json"})
    return r.status_code, r.json()

status, body = waforge("/otp/send", {"phone": "+97455551234"})
if status == 200:
    session["otp_request_id"] = body["request_id"]
Response
HTTP/1.1 200 OK
{ "request_id": "9d5c2f1e-6a4b-4c8e-9f0a-2b3c4d5e6f70", "status": "sent", "expires_at": "2026-11-07T10:20:00+00:00" }

The code has 6 digits and expires after 5 minutes (expires_at). The call waits until WhatsApp has accepted the message, so allow up to about 20 seconds.

Verify the code #

POST /api/v1/otp/verify with {"request_id": "...", "code": "123456"}. The request_id must be one your account created.

cURL
curl -X POST https://waforge.online/api/v1/otp/verify \
  -H "Authorization: Bearer $WAFORGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{"request_id": "9d5c2f1e-6a4b-4c8e-9f0a-2b3c4d5e6f70", "code": "123456"}'
PHP
$r = waforge('/otp/verify', ['request_id' => $_SESSION['otp_request_id'] ?? '', 'code' => trim($_POST['code'] ?? '')]);
if ($r['status'] === 200 && ($r['body']['verified'] ?? false) === true) {
    unset($_SESSION['otp_request_id']);   // use each verification once
    // mark the phone as verified
} else {
    $error = $r['body']['error'] ?? 'unknown';   // invalid_code, expired, not_found
}
Laravel
$r = Http::withToken(config('services.waforge.key'))->acceptJson()
    ->post('https://waforge.online/api/v1/otp/verify', [
        'request_id' => session('otp_request_id'),
        'code' => $request->input('code'),
    ]);

if ($r->json('verified') === true) {
    session()->forget('otp_request_id');   // use each verification once
    $request->user()->forceFill(['phone_verified_at' => now()])->save();
} else {
    return back()->withErrors(['code' => $r->json('error') === 'expired' ? 'Code expired, request a new one.' : 'Wrong code.']);
}
Node.js
const r = await waforge('/otp/verify', { request_id: req.session.otpRequestId, code: String(req.body.code || '').trim() });
if (r.body.verified === true) {
  delete req.session.otpRequestId;   // use each verification once
  // mark the phone as verified
} else {
  // r.body.error: invalid_code, expired or not_found
}
Python
status, body = waforge("/otp/verify", {"request_id": session.get("otp_request_id"), "code": code.strip()})
if body.get("verified") is True:
    session.pop("otp_request_id", None)   # use each verification once
    # mark the phone as verified
else:
    error = body.get("error")             # invalid_code, expired or not_found
Responses
HTTP/1.1 200 OK
{ "verified": true }

HTTP/1.1 422 Unprocessable Content
{ "verified": false, "error": "invalid_code" }
  • Each request allows 5 attempts. After that every attempt answers invalid_code, even with the right code: send a new code.
  • After 5 minutes the answer is expired.
  • A request that is already verified keeps answering {"verified": true}. Bind the request_id to the user's session and use it once, as in the examples.

Test your key #

POST /api/v1/ping with your key answers {"ok": true} without sending anything or using your quota.

Terminal
curl -X POST https://waforge.online/api/v1/ping -H "Authorization: Bearer $WAFORGE_API_KEY" -H "Accept: application/json"

Error codes #

Errors are JSON with an error field, and sometimes a human-readable message.

HTTPerrorMeaning and fix
401missing_api_keyNo Authorization: Bearer header.
401invalid_api_keyUnknown or revoked key. Create a new one in API keys.
403account_suspendedThe account is suspended. Contact support.
403origin_not_allowedWidget key used from a domain that is not in its allowed list (see OTP widget).
409instance_not_connectedNo connected WhatsApp number. Scan the QR code again in Dashboard, WhatsApp number.
409send_failedWhatsApp did not accept the message. The number is marked disconnected; reconnect it, then retry.
422invalid_number"This number is not registered on WhatsApp." Ask the user to check the number.
422(none) {"message", "errors"}Validation: phone missing or longer than 32 characters; on verify, request_id not a UUID or code missing.
422invalid_code, expired, not_foundVerify only, with "verified": false. not_found: the request id does not exist for your account.
429rate_limitedOver your plan's sends per minute. Wait a minute.
429quota_exceededMonthly OTP quota used. Upgrade or wait for next month.
429daily_cap"This number has reached its daily warm-up limit. Try again tomorrow."

A failed send (any error above) does not count against your monthly quota.

Rate limits and quotas #

Three limits apply to /otp/send. /otp/verify and /ping are not counted.

  • Monthly quota per account, reset on the first day of each calendar month.
  • Sends per minute per account.
  • Daily warm-up cap per WhatsApp number, counted from the day the number was connected, because new numbers that send many messages get restricted by WhatsApp: 6 a day for days 1 to 3, 12 until day 7, 25 until day 14, 50 until day 21, 90 until day 28, then 150 a day.
PlanOTP codes per monthSends per minuteWhatsApp numbers
Free100101
Starter1,000201
Pro5,000303
Business50,0006010

Live values from the current plans. See pricing for prices.

Good practice #

  • Call WaForge from your server, never from browser code with a secret key. For a browser-only page use the widget.
  • Add your own limit per phone and per IP (for example 3 sends per phone per 10 minutes) so nobody can drain your quota through your sign-up form.
  • For a WhatsApp OTP login (passwordless sign-in), use the same two calls: look up the account by phone number, send the code, and start the session only after /otp/verify answers {"verified": true}.
  • Show the user which number the code went to and offer "use a different number".
  • Once the phone is verified, the WhatsApp notification API sends booking and order updates from the same connected number.
  • New to the idea? Read how WhatsApp OTP verification works and how it compares to SMS codes.
  • Every send and verification appears in Dashboard, OTP logs. The code itself is never stored or logged in clear text.