Replace API

Add a Replace button to your website. Your customer enters the email of an account, and gets a working replacement account back, the same way the Telegram bot does it.

ملخص بالعربية

1. How it works

  1. The customer types an email on your page and presses Replace.
  2. Your page sends it to your own server (not to us).
  3. Your server calls POST https://api.chat-techno.com/v1/replace with your secret key. You get back a request id.
  4. Your server checks GET https://api.chat-techno.com/v1/replace/{id} every 3 seconds until the status is done or failed. Most replacements take 10 to 30 seconds; when it's busy the request waits in a queue.
  5. Your page shows the new email and password to the customer.
Keeping your key safe

2. Authentication

Send your key in the Authorization header on every request:

Authorization: Bearer rk_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Base URL: https://api.chat-techno.com. All responses are JSON. Every response has ok (true/false). Customer-facing responses also have message.en and message.ar, ready to show on your page as they are.

3. Endpoints

POST /v1/replace — start a replacement

POST https://api.chat-techno.com/v1/replace
Content-Type: application/json

{ "email": "customer@example.com", "ref": "optional-your-own-reference" }

Accepted (HTTP 202):

{ "ok": true, "id": "rq_8kD2...", "status": "queued", "position": 1, "eta_seconds": 15,
  "message": { "en": "Your request is in the queue (position 1)", "ar": "طلبك في قائمة الانتظار (رقم 1)" } }

Pressing twice is safe: if the same email is already in the queue, you get the same id back.

Already replaced before (HTTP 200) — no new replacement is made, you get the current account:

{ "ok": true, "status": "already_replaced", "email": "customer@example.com",
  "account": { "email": "current@...", "password": "...", "expires": "2026-12-21" }, "message": {...} }

GET /v1/replace/{id} — check the result

{ "ok": true, "id": "rq_8kD2...", "status": "running", "message": {...} }

{ "ok": true, "id": "rq_8kD2...", "status": "done",
  "account": { "email": "new@...", "password": "...", "expires": "2026-12-21" },
  "message": { "en": "Your new account is ready", "ar": "حسابك الجديد جاهز" } }

{ "ok": true, "id": "rq_8kD2...", "status": "failed", "error": "busy", "message": {...} }

Status is one of queued, running, done, failed. Stop checking when it's done or failed.

GET /v1/check?email=… — check an email without replacing

Optional. Tells you if an email can be replaced (status: ok, already_replaced, expired, not_found, not_replaceable). Doesn't count toward your daily limit.

GET /v1/me — your usage

{ "ok": true, "daily_limit": 200, "used_today": 37, "remaining_today": 163, "done_this_month": 512, "your_ip": "185.22.10.4" }

Tip: call this once after setup. your_ip shows the address we see for your server.

4. Errors

Messages for your customer (you can show message as it is):

error / statusHTTPMeaning
invalid_email400Not a valid email
not_found404The account wasn't found among your accounts
expired409The subscription has expired, it can't be replaced
not_replaceable409This account can't be replaced
busy503 / in resultTemporarily busy, try again in a few minutes
failedin resultThe replacement didn't succeed, the customer can try again
daily_limit429Your daily limit is reached (message is neutral for the customer)

Setup messages (for you; best not shown to customers):

errorHTTPFix
invalid_key401The key is incorrect or has been replaced by a newer one
ip_not_allowed403The request came from an address that isn't registered. The message shows the address we received, so you can send it to us
paused403The key is paused for now; please contact us
rate_limited429More than 60 requests per minute; please space them out
blocked429Several incorrect keys were sent from your address; access resumes automatically within an hour

5. Ready-made code

Give this section to your developer or to an AI assistant with: "Add this Replace page to my website. The API key must stay on the server."

Node.js (no packages, Node 18+)

// server.js — run: API_URL=https://api.chat-techno.com API_KEY=rk_xxx node server.js
const http = require('http');
const API_URL = process.env.API_URL, API_KEY = process.env.API_KEY;

async function api(method, path, body) {
  const r = await fetch(API_URL + path, {
    method,
    headers: { authorization: 'Bearer ' + API_KEY, 'content-type': 'application/json' },
    body: body ? JSON.stringify(body) : undefined,
    signal: AbortSignal.timeout(20000),
  });
  return r.json();
}

http.createServer(async (req, res) => {
  const send = (o) => { res.writeHead(200, { 'content-type': 'application/json' }); res.end(JSON.stringify(o)); };
  try {
    if (req.method === 'POST' && req.url === '/api/replace') {
      let s = ''; for await (const c of req) s += c;
      const { email } = JSON.parse(s || '{}');
      return send(await api('POST', '/v1/replace', { email }));
    }
    const m = /^\/api\/status\/(rq_[A-Za-z0-9]{16})$/.exec(req.url);
    if (req.method === 'GET' && m) return send(await api('GET', '/v1/replace/' + m[1]));
    // ... serve your page here
  } catch (e) { send({ ok: false, status: 'failed' }); }
}).listen(3000);

PHP

<?php // replace.php — put the key in an environment variable or a config file outside public_html
$API_URL = 'https://api.chat-techno.com';
$API_KEY = getenv('REPLACE_API_KEY');

function api($method, $path, $body = null) {
  global $API_URL, $API_KEY;
  $ch = curl_init($API_URL . $path);
  curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => $method,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 20,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $API_KEY, 'Content-Type: application/json'],
  ]);
  if ($body !== null) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
  $out = curl_exec($ch);
  curl_close($ch);
  return $out ?: json_encode(['ok' => false, 'status' => 'failed']);
}

header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $in = json_decode(file_get_contents('php://input'), true);
  echo api('POST', '/v1/replace', ['email' => $in['email'] ?? '']);
} elseif (isset($_GET['id']) && preg_match('/^rq_[A-Za-z0-9]{16}$/', $_GET['id'])) {
  echo api('GET', '/v1/replace/' . $_GET['id']);
}

The page (browser side) — talks only to your server

<input id="email" type="email" placeholder="name@example.com">
<button id="go">Replace</button>
<div id="msg"></div>
<script>
const msg = (d) => document.getElementById('msg').textContent =
  (d.message && d.message.en) || d.status;   // use d.message.ar for Arabic
document.getElementById('go').onclick = async () => {
  // PHP: '/replace.php' — Node: '/api/replace'
  let d = await fetch('/api/replace', { method: 'POST', headers: { 'content-type': 'application/json' },
    body: JSON.stringify({ email: document.getElementById('email').value.trim() }) }).then(r => r.json());
  msg(d);
  while (d.id && (d.status === 'queued' || d.status === 'running')) {
    await new Promise(r => setTimeout(r, 3000));
    d = await fetch('/api/status/' + d.id).then(r => r.json());   // PHP: '/replace.php?id=' + d.id
    msg(d);
  }
  if (d.account) document.getElementById('msg').textContent +=
    '\n' + d.account.email + '\n' + d.account.password;
};
</script>

6. Checklist before going live

  1. Send us your server's IP address. We register it and send you the key.
  2. Put the key on your server (an environment variable), outside your pages.
  3. Call GET /v1/me from your server: you should get ok: true.
  4. Replace one real account from your page and check the result.
  5. Optionally, view your page's source in the browser to confirm the key isn't included.