Tạo Key 1 lần

API tạo key kích hoạt duy nhất một lần.

Tạo key kích hoạt một lần (Single-use)

API này cho phép tạo hàng loạt key có thể kích hoạt duy nhất một lần (dành cho 1 thiết bị). Thường dùng cho các gói dùng thử hoặc bán lẻ.

POST /public/v1/key/single-activate
Content-Type: application/json
X-API-Key: YOUR_API_KEY

Tham số (Request Body)

TrườngKiểuBắt buộcMô tả
quantityIntSố lượng key cần tạo (1 - 100).
packageIdsArrayMảng ID các package (ví dụ: [1, 2]).
durationIntThời hạn sử dụng.
unitStringĐơn vị: hour, day, week, month, year.
aliasStringPrefix cho key (Tùy chọn, mặc định là username).

Ví dụ Response

201 Created - Thành công

json
{
  "message": "Create key successfully",
  "data": [
    "DEMO-ONCE-30D-ABCD123...",
    "DEMO-ONCE-30D-EFGH456..."
  ]
}

422 Unprocessable Entity - Lỗi Validation

json
{
  "message": "quantity must be greater than 0"
}

Ví dụ PHP (cURL)

php
<?php
$apiKey = 'YOUR_API_KEY';
$url = 'http://' . $_SERVER['HTTP_HOST'] . '/public/v1/key/single-activate';
$data = [
    'quantity' => 5,
    'packageIds' => [1, 2],
    'duration' => 30,
    'unit' => 'day',
    'alias' => 'premium-key'
];

$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => json_encode($data),
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'X-API-Key: ' . $apiKey
    ],
]);

$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

echo "HTTP Code: " . $httpCode . "\n";
echo "Response: " . $response . "\n";
?>

© 2026 CTDOAPIKEY Documentation