πŸ”Œ Nice Chat API v1

Doosri website / app se Nice Chat par message bhejein, OTP bhejein, account banayein aur chat padhein.

πŸ”‘ Your API Key

Base URL: https://wanice.xyz/api/v1

YOUR_API_KEY
Key admin panel se milti hai. Admin ke roop me login karke isi page par β€œNayi Key Banayein” dikhega.
Har key kisi ek account ke naam se chalti hai. Us key se bheja gaya message usi account ki taraf se jaata hai, aur chat bhi sirf usi ke dikhte hain β€” kisi doosre ka data kabhi nahi milta.

πŸ›‘οΈ API Key bhejne ke 3 tareeke

Teenon chalte hain. Header sabse behtar hai (URL/log me key nahi jaati).

1. Header me (Recommended)

Authorization: Bearer YOUR_API_KEY

2. X-API-Key header me

X-API-Key: YOUR_API_KEY

3. Body / URL me

{
    "api_key": "YOUR_API_KEY",
    "to": "9876543210",
    "message": "Namaste!"
}
Ye server-to-server API hai. Key kabhi browser/JavaScript me na rakhein β€” wahan wo har visitor ko dikh jaati hai. Isi wajah se CORS band rakha gaya hai.

Har jawab ka roop

{ "status": "success", "data": { ... }, "message": "..." }

{ "status": "error",   "message": "...", "error_code": "..." }

πŸ“‹ Endpoints

GET/status.phpKey chal rahi hai? (haq, limit, account)
POST/send.phpMessage bhejo (number par ya conversation me)
POST/otp_send.phpKisi number par OTP bhejo
POST/otp_verify.phpOTP jaancho
POST/register.phpNaya account banao
POST/login.phpPehchano + ek-baar-chalne wala login link lo
GET/chats.phpChat list (unread ke saath)
GET/messages.phpEk chat ke message padho

πŸ’¬ Message bhejna

POST https://wanice.xyz/api/v1/send.php Β· haq: message

ParameterZarooriMatlab
tohaan*10-digit mobile. Us number se 1:1 chat khud ban jaata hai.
conversation_idhaan*Pehle se maujood chat/group ka id (aap usme member hon).
messagehaanText, 4000 characters tak.

* to ya conversation_id β€” koi ek zaroori hai.

cURL

curl -X POST "https://wanice.xyz/api/v1/send.php" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"to":"9876543210","message":"Aapka order taiyar hai βœ…"}'

Jawab

{
    "status": "success",
    "data": {
        "message_id": 42,
        "conversation_id": 17,
        "from": "9199998860",
        "to": "9876543210",
        "sent_at": "2026-07-26 11:23:12"
    },
    "message": "Message bhej diya gaya"
}

πŸ” OTP bhejna aur jaanchna

Haq: otp. OTP isi server par banta hai β€” aapko kabhi nahi bheja jaata (warna OTP ka matlab hi khatam).

1. Bhejo β€” POST /otp_send.php

ParameterZarooriMatlab
mobilehaan10-digit number
purposenahiSirf log ke liye label (jaise signup)
curl -X POST "https://wanice.xyz/api/v1/otp_send.php" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"mobile":"9876543210","purpose":"signup"}'
{ "status":"success", "data":{ "mobile":"9876543210", "channel":"whatsapp", "expires_in":600, "otp_length":6 } }
channel batata hai OTP kis raaste gaya β€” sms ya whatsapp. Ye admin ki setting se apne aap tay hota hai (SMS na pahunche to WhatsApp).

2. Jaancho β€” POST /otp_verify.php

curl -X POST "https://wanice.xyz/api/v1/otp_verify.php" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"mobile":"9876543210","otp":"123456"}'
{ "status":"success", "data":{ "verified":true, "has_account":true, "user":{...} } }

Haddein: ek number par 45 second me ek OTP, ek ghante me 5, aur 5 galat koshish ke baad OTP band.

πŸ‘€ Account banana aur Login (SSO)

Haq: account

POST /register.php

ParameterZarooriMatlab
mobilehaan10-digit number (yahi username banta hai)
namehaanDikhne wala naam, 1-50 characters
passwordnahiDiya to user password se bhi login kar sakega (min 4)
curl -X POST "https://wanice.xyz/api/v1/register.php" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"mobile":"9876543210","name":"Ramesh Kumar","password":"secret123"}'

Number pehle se ho to 409 + ALREADY_EXISTS aata hai (uske saath wahi user bhi).

POST /login.php β€” ek-click login link

mobile + (password ya otp) bhejein. Jawab me login_url milta hai β€” user ko us link par bhej dein, wo seedha logged-in chat me pahunch jaata hai. Aapki website par password rakhne ki zarurat nahi.

curl -X POST "https://wanice.xyz/api/v1/login.php" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"mobile":"9876543210","password":"secret123"}'
{
    "status": "success",
    "data": {
        "user": { "id": 57, "mobile": "9876543210", "display_name": "Ramesh Kumar" },
        "login_url": "https://wanice.xyz/api/v1/sso.php?t=…",
        "expires_in": 300,
        "one_time": true
    }
}
login_url 5 minute chalta hai aur sirf ek baar. Isliye usay pehle se bana kar rakhna bekaar hai β€” jab user button dabaye tabhi banayein.

πŸ“± Mobile App ke liye (API key ke BINA)

In do endpoints par key nahi chahiye β€” user ka OTP hi uski pehchan hai.

App ke andar API key kabhi na rakhein. APK kholna aasan hai, key nikal jaati hai, aur phir koi bhi aapke naam se message bhej sakta hai. Isliye app ka apna raasta hai: OTP se login, aur uske badle ek per-user token jo sirf usi user ke chat padh/bhej sakta hai.

1. POST /app_otp.php

curl -X POST "https://wanice.xyz/api/v1/app_otp.php" \
  -H "Content-Type: application/json" \
  -d '{"mobile":"9876543210"}'
{ "status":"success", "data":{ "mobile":"9876543210", "channel":"whatsapp",
    "is_new":true, "otp_length":6, "expires_in":600 } }

is_new true ho to app naam bhi poochhta hai (naya account banega).

2. POST /app_login.php

ParameterZarooriMatlab
mobilehaanWahi number jispar OTP gaya
otphaanUser ne jo daala
namenaye user ke liyeNaam (is_new = true par)
devicenahiLabel β€” ek device ka ek token
curl -X POST "https://wanice.xyz/api/v1/app_login.php" \
  -H "Content-Type: application/json" \
  -d '{"mobile":"9876543210","otp":"123456","name":"Ramesh","device":"android"}'
{ "status":"success", "data":{
    "token":"nc_…",
    "user":{ "id":59, "mobile":"9876543210", "display_name":"Ramesh" }
} }
Us token ko phone me sambhal kar rakhein aur aage har call me Authorization: Bearer <token> bhejein. Token ke paas sirf message + read ka haq hota hai β€” us se naya account banana ya kisi aur ka OTP bhejna mumkin nahi. Token expire nahi hota; user "Logout" dabaye to app usay bhula deta hai, aur admin panel se key OFF bhi ki ja sakti hai.

Hamara apna WA NICE Chats Android app bilkul yahi raasta use karta hai β€” poora native app, koi WebView nahi.

πŸ“₯ Chat padhna

Haq: read. Sirf unhi chats ka data milta hai jinka key wala account member hai.

GET /chats.php

curl "https://wanice.xyz/api/v1/chats.php?limit=30" -H "Authorization: Bearer YOUR_API_KEY"
{ "status":"success", "data":{ "chats":[
    { "conversation_id":17, "type":"direct", "title":"Ramesh Kumar",
      "unread":1, "last_message":"Aapka order taiyar hai", "last_message_at":"2026-07-26 11:23:12" }
], "count":1 } }

GET /messages.php

ParameterZarooriMatlab
conversation_idhaanKis chat ke message
afternahiIs id ke BAAD wale β€” polling ke liye (default 0)
limitnahi1-200 (default 50)
curl "https://wanice.xyz/api/v1/messages.php?conversation_id=17&after=0" \
  -H "Authorization: Bearer YOUR_API_KEY"
Naye message ke liye baar-baar poora chat na maangein: jawab ka last_id yaad rakhein aur agli baar after=last_id bhejein.

⚠️ Error Codes

error_codeHTTPMatlab
MISSING_API_KEY401Key bheji nahi gayi
INVALID_API_KEY401Key galat hai
INACTIVE_KEY403Key band kar di gayi
SCOPE_DENIED403Is key ko is kaam ka haq nahi
INACTIVE_USER / USER_BLOCKED403Account block hai
FORBIDDEN403Us conversation ka member nahi
USER_NOT_FOUND404Is number ka account nahi hai
ALREADY_EXISTS409Account pehle se hai
INVALID_PARAMETERS422Koi parameter galat/khali
INVALID_CREDENTIALS401Galat mobile/password/OTP
OTP_NOT_FOUND / OTP_EXPIRED / OTP_INVALID410 / 401OTP ka masla
COOLDOWN / RATE_LIMITED / TOO_MANY_ATTEMPTS429Bahut zyada koshish β€” ruk kar try karein
GATEWAY_ERROR503SMS/WhatsApp gateway ne mana kar diya
METHOD_NOT_ALLOWED405GET ki jagah POST chahiye
SERVER_ERROR500Hamari taraf se dikkat

πŸš€ Ready Script β€” apni website me 2 minute me lagayein

Ye poori file apni PHP website par rakh dein. Key upar badal lein, bas.

<?php
// nicechat.php β€” Nice Chat API v1 ka ready helper
// Kisi bhi PHP website par chalega. Sirf API_KEY apni rakhein.

define('NICECHAT_KEY', 'YOUR_API_KEY');
define('NICECHAT_API', 'https://wanice.xyz/api/v1');

/**
 * Ek call, saare endpoints ke liye.
 * @return array  ['ok'=>bool, 'data'=>array, 'message'=>string, 'code'=>string]
 */
function nicechat(string $endpoint, array $params = [], string $method = 'POST'): array
{
    $url = rtrim(NICECHAT_API, '/') . '/' . ltrim($endpoint, '/');
    $ch  = curl_init();

    $opts = [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT        => 45,
        CURLOPT_HTTPHEADER     => [
            'Authorization: Bearer ' . NICECHAT_KEY,
            'Content-Type: application/json',
            'Accept: application/json',
        ],
    ];

    if (strtoupper($method) === 'POST') {
        $opts[CURLOPT_POST]       = true;
        $opts[CURLOPT_POSTFIELDS] = json_encode($params);
    } else {
        $url .= (str_contains($url, '?') ? '&' : '?') . http_build_query($params);
    }

    curl_setopt_array($ch, $opts + [CURLOPT_URL => $url]);
    $raw = curl_exec($ch);
    curl_close($ch);

    $j = json_decode((string) $raw, true) ?: [];

    return [
        'ok'      => ($j['status'] ?? '') === 'success',
        'data'    => $j['data'] ?? [],
        'message' => $j['message'] ?? 'Koi jawab nahi mila',
        'code'    => $j['error_code'] ?? '',
    ];
}

/* ---------------- istemal ke udaharan ---------------- */

// 1) Message bhejo
$r = nicechat('send.php', ['to' => '9876543210', 'message' => 'Aapka order taiyar hai']);
echo $r['ok'] ? "bheja gaya\n" : "fail: {$r['message']}\n";

// 2) OTP bhejo aur jaancho
nicechat('otp_send.php', ['mobile' => '9876543210', 'purpose' => 'signup']);
$v = nicechat('otp_verify.php', ['mobile' => '9876543210', 'otp' => $_POST['otp'] ?? '']);
if ($v['ok']) { /* number verify ho gaya */ }

// 3) Account banao, phir user ko seedha chat me bhejo
nicechat('register.php', ['mobile' => '9876543210', 'name' => 'Ramesh Kumar', 'password' => 'secret123']);
$l = nicechat('login.php', ['mobile' => '9876543210', 'password' => 'secret123']);
if ($l['ok']) { header('Location: ' . $l['data']['login_url']); exit; }

// 4) Chat padho
$c = nicechat('chats.php', ['limit' => 20], 'GET');
$m = nicechat('messages.php', ['conversation_id' => 17, 'after' => 0], 'GET');

Nice Chat API v1 · Home