API v1.0 Live Reseller

Tài liệu Reseller REST API

RESTful API dành cho đại lý (Reseller): tự động hóa thuê số nhận OTP, kiểm tra số dư ví và tra cứu lịch sử giao dịch theo thời gian thực.

Base URL: https://kotp.tech/api/v1

1. Xác thực

Mọi request đều phải kèm API Key hợp lệ trong header X-API-Key hoặc Authorization: Bearer <token>.

1

Nhận API Key

Mở Telegram Bot @Kotp247_bot → chọn API & Tích hợp → bấm Tạo API Key.

2

Gửi qua HTTP Header

Đính kèm key vào mọi request:
X-API-Key: sk_rs_...

Ví dụ HTTP Header
GET /api/v1/products HTTP/1.1
Host: kotp.tech
X-API-Key: sk_rs_YOUR_API_KEY
Accept: application/json

2. Cấu trúc Response

Toàn bộ API dùng chung một envelope. Dựa vào HTTP status code và trường success để xử lý kết quả. Khi lỗi, request_id luôn được trả về, hãy gửi kèm khi cần hỗ trợ.

Thành công

200 / 201
{
  "success": true,
  "data": {}
}

Thất bại

4xx / 5xx
{
  "success": false,
  "error": {
    "code": "INSUFFICIENT_BALANCE",
    "message": "Số dư không đủ để tạo đơn hàng"
  },
  "request_id": "req_01K75YH2T8..."
}

3. Mã lỗi

Mã lỗi theo định dạng UPPER_SNAKE_CASE, đi kèm HTTP status chuẩn REST.

HTTP Status Error Code Mô tả / Nguyên nhân
401 Unauthorized UNAUTHORIZED API Key không hợp lệ hoặc thiếu trong header.
403 Forbidden FORBIDDEN API Key không có quyền (scope) truy cập Reseller API.
404 Not Found PRODUCT_NOT_FOUND Không tìm thấy dịch vụ ứng với product_id.
404 Not Found ORDER_NOT_FOUND Không tìm thấy đơn hàng hoặc đơn không thuộc tài khoản của bạn.
422 Unprocessable IDEMPOTENCY_KEY_REQUIRED Thiếu header Idempotency-Key khi tạo đơn.
422 Unprocessable IDEMPOTENCY_KEY_INVALID Header Idempotency-Key vượt quá 128 ký tự.
422 Unprocessable VALIDATION_ERROR Thiếu tham số hoặc tham số sai định dạng (ví dụ product_id không đúng chuẩn KOTP_XXXXXXXX).
422 Unprocessable INSUFFICIENT_BALANCE Số dư ví không đủ để thanh toán đơn hàng.
500 Internal Error INTERNAL_ERROR Lỗi xử lý nội bộ phía máy chủ.
503 Unavailable SERVICE_UNAVAILABLE Dịch vụ đang bận hoặc tạm hết số, vui lòng thử lại sau giây lát.

4. Vòng đời đơn & Polling

Đơn hàng không thành công sẽ được hoàn tiền tự động 100% vào ví.

Trạng thái Ý nghĩa Số dư ví Hành động tiếp theo
waiting_sms Đã cấp số, đang chờ SMS OTP. Đã trừ (tạm giữ) Tiếp tục polling mỗi 5 giây
otp_received SMS đã về, trả về otp_code và sms_content. Đã thanh toán Dừng polling, dùng mã OTP
used Mã OTP đã được xác nhận sử dụng. Đã thanh toán Dừng polling, đơn hoàn tất
expired Hết thời gian chờ (theo expires_at) không nhận được SMS. Hoàn tiền 100% Dừng polling, có thể tạo đơn mới
failed / cancelled Đơn bị hủy do lỗi kỹ thuật hoặc số không hợp lệ. Hoàn tiền 100% Dừng polling, có thể tạo đơn mới
Khuyến nghị polling:

Gọi GET /api/v1/orders/{id} mỗi 5 giây cho đến khi trạng thái là một trong các trạng thái kết thúc: otp_received, used, expired, failed, cancelled. Không polling nhanh hơn 5 giây để tránh bị giới hạn tần suất.

5. Danh sách Endpoints

GET /api/v1/products
Lấy danh sách dịch vụ và bảng giá hiện hành

Query Parameters

Tham số Kiểu Bắt buộc Mô tả
country string Tùy chọn Mã quốc gia ISO (mặc định VN; hỗ trợ thêm US, PH, ...).
service string Tùy chọn Lọc theo tên dịch vụ (ví dụ tiktok, telegram; hỗ trợ alias search, q).
server integer Tùy chọn Lọc theo nhóm tuyến cấp số (ví dụ 1, 2, 3).
page integer Tùy chọn Trang hiện tại (mặc định 1).
limit integer Tùy chọn Số dịch vụ mỗi trang (mặc định 50).

Các trường trong response

Trường Kiểu Mô tả
product_id string Mã sản phẩm, dùng khi tạo đơn.
server integer Nhóm tuyến cấp số (1, 2, 3).
price integer Giá thuê một lần, đơn vị theo currency.
available boolean false nghĩa là tạm hết số.
networks string[] Nhà mạng hỗ trợ (ANY = không giới hạn).

Response Example

200 OK
{
  "success": true,
  "data": [
    {
      "product_id": "KOTP_A1B2C3D4",
      "service_code": "KOTP_A1B2C3D4",
      "service_name": "Telegram",
      "server": 1,
      "server_id": 1,
      "country_code": "VN",
      "price": 4500,
      "currency": "VND",
      "available": true,
      "networks": ["ANY"]
    },
    {
      "product_id": "KOTP_E5F60718",
      "service_code": "KOTP_E5F60718",
      "service_name": "WhatsApp (US)",
      "server": 2,
      "server_id": 2,
      "country_code": "US",
      "price": 6000,
      "currency": "VND",
      "available": true,
      "networks": ["ANY"]
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 50,
    "total": 2
  }
}
POST /api/v1/orders
Tạo đơn thuê số điện thoại nhận OTP

HTTP Headers

Header Bắt buộc Mô tả
X-API-Key Bắt buộc API Key đại lý (sk_rs_...) hoặc dùng Authorization: Bearer sk_rs_....
Idempotency-Key Bắt buộc Khóa chống trùng đơn (tối đa 128 ký tự, ví dụ UUID) cho mỗi đơn mới. Khi retry cùng một đơn, dùng lại đúng khóa đó.

Request Body (JSON)

Trường Kiểu Bắt buộc Mô tả
product_id string Bắt buộc Mã sản phẩm chuẩn KOTP_XXXXXXXX lấy từ GET /api/v1/products.
network string Tùy chọn Nhà mạng mong muốn: VIETTEL, VINAPHONE, MOBIFONE.
country string Tùy chọn Mã quốc gia ISO nếu cần ghi đè mặc định của sản phẩm.

Request Example

POST Body
{
  "product_id": "KOTP_A1B2C3D4"
}

Response Example

201 Created
{
  "success": true,
  "data": {
    "order_id": "ORD-ZXPH84U9",
    "public_code": "ORD-ZXPH84U9",
    "service_name": "Tiktok Shop",
    "server": 3,
    "server_id": 3,
    "phone_number": "0388112233",
    "price": 3800,
    "currency": "VND",
    "status": "waiting_sms",
    "created_at": "2026-10-07T16:50:00+07:00",
    "expires_at": "2026-10-07T16:55:00+07:00"
  }
}
GET /api/v1/orders/{id}
Chi tiết đơn hàng & polling mã OTP

Truyền public_code vào {id} (ví dụ ORD-ZXPH84U9). Polling mỗi 5 giây cho đến khi đơn đạt trạng thái kết thúc (xem mục 4).

1. Đang chờ SMS

waiting_sms
{
  "success": true,
  "data": {
    "order_id": "ORD-ZXPH84U9",
    "public_code": "ORD-ZXPH84U9",
    "service_name": "Tiktok Shop",
    "server": 3,
    "server_id": 3,
    "phone_number": "0388112233",
    "status": "waiting_sms",
    "price": 3800,
    "currency": "VND",
    "otp_code": null,
    "sms_content": null,
    "created_at": "2026-10-07T16:50:00+07:00",
    "otp_received_at": null,
    "expires_at": "2026-10-07T16:55:00+07:00"
  }
}

2. Đã nhận OTP

otp_received
{
  "success": true,
  "data": {
    "order_id": "ORD-ZXPH84U9",
    "public_code": "ORD-ZXPH84U9",
    "service_name": "Tiktok Shop",
    "server": 3,
    "server_id": 3,
    "phone_number": "0388112233",
    "status": "otp_received",
    "price": 3800,
    "currency": "VND",
    "otp_code": "489201",
    "sms_content": "Mã OTP TikTok của bạn là: 489201",
    "created_at": "2026-10-07T16:50:00+07:00",
    "otp_received_at": "2026-10-07T16:51:18+07:00",
    "expires_at": "2026-10-07T16:55:00+07:00"
  }
}
GET /api/v1/wallet
Tra cứu số dư ví hiện tại

Response Example

200 OK
{
  "success": true,
  "data": {
    "balance": 250000,
    "available_balance": 246200,
    "held_balance": 3800,
    "currency": "VND",
    "updated_at": "2026-10-07T16:50:00+07:00"
  }
}
GET /api/v1/wallet/transactions
Lịch sử biến động số dư ví (keyset cursor pagination)

Query Parameters

Tham số Kiểu Mặc định Mô tả
cursor string null Con trỏ trang kế tiếp lấy từ pagination.next_cursor của response trước.
limit integer 20 Số bản ghi mỗi lần tải (tối đa 100).

Response Example

200 OK
{
  "success": true,
  "data": [
    {
      "id": 5012,
      "type": "purchase",
      "amount": -3800,
      "balance_before": 253800,
      "balance_after": 250000,
      "reference_type": "order",
      "reference_id": "ORD-ZXPH84U9",
      "created_at": "2026-10-07T16:50:00+07:00"
    },
    {
      "id": 5011,
      "type": "deposit",
      "amount": 100000,
      "balance_before": 153800,
      "balance_after": 253800,
      "reference_type": "deposit",
      "reference_id": "DEP-781920",
      "created_at": "2026-10-07T15:20:00+07:00"
    }
  ],
  "pagination": {
    "limit": 20,
    "next_cursor": "NTAxMQ==",
    "has_more": true
  }
}

6. Code mẫu

Quy trình đầy đủ: tạo đơn kèm Idempotency-Key, polling mỗi 5 giây đến khi đơn kết thúc.

cURL
# 1. Tạo đơn (kèm Idempotency-Key)
curl -X POST "https://kotp.tech/api/v1/orders" \
     -H "X-API-Key: sk_rs_YOUR_API_KEY" \
     -H "Idempotency-Key: $(uuidgen)" \
     -H "Content-Type: application/json" \
     -d '{"product_id": "KOTP_A1B2C3D4"}'

# 2. Polling mỗi 5 giây đến khi đơn kết thúc
curl -X GET "https://kotp.tech/api/v1/orders/ORD-ZXPH84U9" \
     -H "X-API-Key: sk_rs_YOUR_API_KEY" \
     -H "Accept: application/json"
Python 3
import sys
import time
import uuid

import requests

API_KEY = "sk_rs_YOUR_API_KEY"
BASE_URL = "https://kotp.tech/api/v1"
TERMINAL = {"otp_received", "used", "expired", "failed", "cancelled"}

# 1. Tạo đơn
res = requests.post(
    f"{BASE_URL}/orders",
    json={"product_id": "KOTP_A1B2C3D4"},
    headers={
        "X-API-Key": API_KEY,
        "Idempotency-Key": str(uuid.uuid4()),
        "Content-Type": "application/json",
    },
    timeout=15,
).json()

if not res.get("success"):
    sys.exit(f"Tạo đơn thất bại: {res.get('error', {}).get('message')}")

order = res["data"]
code = order["public_code"]
print(f"Thuê số thành công: {order['phone_number']} (Mã đơn: {code})")

# 2. Polling mỗi 5 giây (tối đa 5 phút)
poll_headers = {"X-API-Key": API_KEY, "Accept": "application/json"}
for _ in range(60):
    time.sleep(5)
    poll = requests.get(f"{BASE_URL}/orders/{code}", headers=poll_headers, timeout=15).json()
    if not poll.get("success"):
        continue

    data = poll["data"]
    status = data["status"]
    if status in TERMINAL:
        if status == "otp_received":
            print("OTP:", data["otp_code"])
            print("SMS:", data["sms_content"])
        else:
            print(f"Đơn kết thúc ({status}).")
        break
    print("Đang chờ tin nhắn OTP...")
PHP 8.x (cURL)
<?php

$apiKey  = 'sk_rs_YOUR_API_KEY';
$baseUrl = 'https://kotp.tech/api/v1';
$terminal = ['otp_received', 'used', 'expired', 'failed', 'cancelled'];

function request(string $url, array $headers, ?array $body = null): array
{
    $ch = curl_init($url);
    $opts = [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT        => 15,
        CURLOPT_HTTPHEADER     => $headers,
    ];
    if ($body !== null) {
        $opts[CURLOPT_POST] = true;
        $opts[CURLOPT_POSTFIELDS] = json_encode($body);
    }
    curl_setopt_array($ch, $opts);
    $raw = curl_exec($ch);
    curl_close($ch);

    return json_decode((string) $raw, true) ?: [];
}

// 1. Tạo đơn (kèm Idempotency-Key)
$res = request("$baseUrl/orders", [
    "X-API-Key: $apiKey",
    'Idempotency-Key: ' . bin2hex(random_bytes(16)),
    'Content-Type: application/json',
], ['product_id' => 'KOTP_A1B2C3D4']);

if (!($res['success'] ?? false)) {
    exit('Lỗi tạo đơn: ' . ($res['error']['message'] ?? 'Unknown error') . "\n");
}

$code = $res['data']['public_code'];
echo "Đã thuê số: {$res['data']['phone_number']} (Mã: $code)\n";

// 2. Polling mỗi 5 giây (tối đa 5 phút)
for ($i = 0; $i < 60; $i++) {
    sleep(5);
    $poll = request("$baseUrl/orders/$code", ["X-API-Key: $apiKey", 'Accept: application/json']);
    $status = $poll['data']['status'] ?? '';

    if (in_array($status, $terminal, true)) {
        if ($status === 'otp_received') {
            echo 'OTP: ' . $poll['data']['otp_code'] . "\n";
            echo 'SMS: ' . $poll['data']['sms_content'] . "\n";
        } else {
            echo "Đơn kết thúc ($status).\n";
        }
        break;
    }
}
Node.js 18+ (fetch)
import { randomUUID } from 'node:crypto';
import { setTimeout as sleep } from 'node:timers/promises';

const API_KEY = 'sk_rs_YOUR_API_KEY';
const BASE_URL = 'https://kotp.tech/api/v1';
const TERMINAL = ['otp_received', 'used', 'expired', 'failed', 'cancelled'];

async function buyAndGetOtp() {
  // 1. Tạo đơn
  const res = await fetch(`${BASE_URL}/orders`, {
    method: 'POST',
    headers: {
      'X-API-Key': API_KEY,
      'Idempotency-Key': randomUUID(),
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ product_id: 'KOTP_A1B2C3D4' }),
  });
  const json = await res.json();
  if (!json.success) throw new Error(json.error?.message ?? 'Tạo đơn thất bại');

  const { public_code, phone_number } = json.data;
  console.log(`Thuê số thành công: ${phone_number} (Mã đơn: ${public_code})`);

  // 2. Polling mỗi 5 giây (tối đa 5 phút), mỗi lượt chờ xong mới gọi tiếp
  for (let i = 0; i < 60; i++) {
    await sleep(5000);
    const poll = await fetch(`${BASE_URL}/orders/${public_code}`, {
      headers: { 'X-API-Key': API_KEY, Accept: 'application/json' },
    }).then((r) => r.json());

    const status = poll?.data?.status;
    if (TERMINAL.includes(status)) {
      if (status === 'otp_received') {
        console.log(`OTP: ${poll.data.otp_code}`);
        console.log(`SMS: ${poll.data.sms_content}`);
      } else {
        console.log(`Đơn kết thúc: ${status}`);
      }
      return;
    }
  }
}

buyAndGetOtp().catch(console.error);