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/sendanswers409 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 aPOSTwith a JSON body andAuthorization: Bearer wf_sk_....
The flow #
- The user enters their phone number on your site. Your server calls
POST /otp/sendand stores the returnedrequest_idin the user's session. - WaForge sends "Your verification code is 123456. Valid for 5 minutes." on WhatsApp.
- The user types the code. Your server calls
POST /otp/verifywith therequest_idfrom the session and the code. - On
{"verified": true}you mark the phone as verified and remove therequest_idfrom 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 -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
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'];
}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"
}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;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"]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 -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"}'$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
}$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.']);
}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
}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_foundHTTP/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 therequest_idto 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.
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.
| HTTP | error | Meaning and fix |
|---|---|---|
| 401 | missing_api_key | No Authorization: Bearer header. |
| 401 | invalid_api_key | Unknown or revoked key. Create a new one in API keys. |
| 403 | account_suspended | The account is suspended. Contact support. |
| 403 | origin_not_allowed | Widget key used from a domain that is not in its allowed list (see OTP widget). |
| 409 | instance_not_connected | No connected WhatsApp number. Scan the QR code again in Dashboard, WhatsApp number. |
| 409 | send_failed | WhatsApp did not accept the message. The number is marked disconnected; reconnect it, then retry. |
| 422 | invalid_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. |
| 422 | invalid_code, expired, not_found | Verify only, with "verified": false. not_found: the request id does not exist for your account. |
| 429 | rate_limited | Over your plan's sends per minute. Wait a minute. |
| 429 | quota_exceeded | Monthly OTP quota used. Upgrade or wait for next month. |
| 429 | daily_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.
| Plan | OTP codes per month | Sends per minute | WhatsApp numbers |
|---|---|---|---|
| Free | 100 | 10 | 1 |
| Starter | 1,000 | 20 | 1 |
| Pro | 5,000 | 30 | 3 |
| Business | 50,000 | 60 | 10 |
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/verifyanswers{"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.