curl -X POST "https://api.otpvn.com/v1/rentals" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"serviceId":1}'
curl "https://api.otpvn.com/v1/rentals/1234122" -H "Authorization: Bearer YOUR_API_TOKEN"const BASE = 'https://api.otpvn.com';
const TOKEN = 'YOUR_API_TOKEN';
async function call(method, path, body) {
const res = await fetch(BASE + path, {
method,
headers: { Authorization: 'Bearer ' + TOKEN, 'Content-Type': 'application/json' },
body: body ? JSON.stringify(body) : undefined,
});
const data = await res.json();
if (!res.ok) throw new Error(data.code + ': ' + data.detail);
return data;
}
const rent = await call('POST', '/v1/rentals', { serviceId: 1 });
console.log('Number:', rent.phoneLocal);
for (;;) {
await new Promise((r) => setTimeout(r, 5000));
const s = await call('GET', '/v1/rentals/' + rent.id);
if (s.status === 1) { console.log('Code:', s.code); break; }
if (s.status === 2) { console.log('Expired, refunded'); break; }
}import time
import requests
BASE = "https://api.otpvn.com"
HEADERS = {"Authorization": "Bearer YOUR_API_TOKEN"}
def call(method, path, body=None):
res = requests.request(method, BASE + path, headers=HEADERS, json=body, timeout=30)
data = res.json()
if not res.ok:
raise RuntimeError(f'{data["code"]}: {data["detail"]}')
return data
rent = call("POST", "/v1/rentals", {"serviceId": 1})
print("Number:", rent["phoneLocal"])
while True:
time.sleep(5)
s = call("GET", f"/v1/rentals/{rent['id']}")
if s["status"] == 1:
print("Code:", s["code"])
break
if s["status"] == 2:
print("Expired, refunded")
break<?php
const BASE = 'https://api.otpvn.com';
const TOKEN = 'YOUR_API_TOKEN';
function call(string $method, string $path, ?array $body = null): array {
$ch = curl_init(BASE . $path);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . TOKEN, 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => $body === null ? null : json_encode($body),
]);
$data = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status >= 400) throw new Exception($data['code'] . ': ' . $data['detail']);
return $data;
}
$rent = call('POST', '/v1/rentals', ['serviceId' => 1]);
echo 'Number: ' . $rent['phoneLocal'] . PHP_EOL;
while (true) {
sleep(5);
$s = call('GET', '/v1/rentals/' . $rent['id']);
if ($s['status'] === 1) { echo 'Code: ' . $s['code'] . PHP_EOL; break; }
if ($s['status'] === 2) { echo 'Expired, refunded' . PHP_EOL; break; }
}