Bỏ qua để đến nội dung

Ví dụ cURL / SDK

Mọi ví dụ đều dùng base URL công khai:

https://api.zelnum.com/api/v1

Thay YOUR_KEY_HERE bằng key từ Xác thực, và lấy ID sản phẩm từ Sản phẩm thời gian thực — các ID dưới đây chỉ là ví dụ và có thể thay đổi khi sản phẩm mới được thêm vào.

Terminal window
curl -X POST "https://api.zelnum.com/api/v1/realtime/check/phone" \
-H "X-API-Key: YOUR_KEY_HERE" \
-H "Idempotency-Key: 8f14e45f-ceea-467a-9f3f-1b2c3d4e5f60" \
-H "Content-Type: application/json" \
-d '{"identifier":"+8613800138000","country":"CN","product_ids":[47]}'

country là tuỳ chọn khi số đã ở dạng E.164 đầy đủ. Hãy thêm vào khi bạn gửi số nội địa.

Terminal window
curl -X POST "https://api.zelnum.com/api/v1/realtime/check/phone" \
-H "X-API-Key: YOUR_KEY_HERE" \
-H "Idempotency-Key: 5c2f1a90-6b7d-4e8f-9a01-2b3c4d5e6f70" \
-H "Content-Type: application/json" \
-d '{"identifier":"+8613800138000","country":"CN","product_ids":[47,50,51]}'

Ba sản phẩm, một request_id, ba mục trong results, ba khoản thu. Xem Sản phẩm thời gian thực để biết giới hạn mười ID.

Terminal window
curl -X POST "https://api.zelnum.com/api/v1/realtime/check/email" \
-H "X-API-Key: YOUR_KEY_HERE" \
-H "Idempotency-Key: 0d9c8b7a-6543-4321-fedc-ba9876543210" \
-H "Content-Type: application/json" \
-d '{"identifier":"user@example.com","product_ids":[49]}'

Lưu ý rằng không có country — sản phẩm email từ chối trường này.

Terminal window
curl -s -X POST "https://api.zelnum.com/api/v1/realtime/check/phone" \
-H "X-API-Key: YOUR_KEY_HERE" \
-H "Idempotency-Key: 3a1b2c3d-4e5f-6071-8293-a4b5c6d7e8f9" \
-H "Content-Type: application/json" \
-d '{"identifier":"+8613800138000","product_ids":[47,50]}' \
| jq '{status, charged: .total_charged, items: [.results[] | {product: .product, result: .result, billed: .billing_status}]}'

Kiểm tra billing_status của từng mục, không chỉ HTTP status — một 200 vẫn có thể chứa các mục đã hoàn tiền. Xem Thanh toán & hoàn tiền.

Ý nghĩa của Idempotency-Key là script này có thể chạy hai lần một cách an toàn:

Terminal window
KEY=$(uuidgen)
BODY='{"identifier":"+8613800138000","country":"CN","product_ids":[47]}'
for attempt in 1 2 3; do
response=$(curl -s -w '\n%{http_code}' -X POST \
"https://api.zelnum.com/api/v1/realtime/check/phone" \
-H "X-API-Key: YOUR_KEY_HERE" \
-H "Idempotency-Key: $KEY" \
-H "Content-Type: application/json" \
-d "$BODY")
code=$(printf '%s' "$response" | tail -n1)
printf '%s' "$response" | sed '$d'
case "$code" in
200) exit 0 ;;
# Kết quả chưa chắc chắn: key chính là điểm mấu chốt. Gửi lại cùng body.
500|000) sleep 2 ;;
# Vẫn đang chạy, hoặc bị giới hạn: tuân thủ Retry-After và giữ nguyên key.
409|429) sleep "$(printf '%s' "$response" | sed '$d' | jq -r '.retry_after // 2')" ;;
*) exit 1 ;;
esac
done

Đừng bao giờ tạo key mới để thử lại một request mà bạn chưa quan sát được kết quả — đó chính xác là cách một lần kiểm tra bị trả tiền hai lần. Xem Idempotency & thử lại.

{
"request_id": "8c1e4f91-7bd8-4d7e-a3ae-3d7e5b0c6c11",
"identifier": "+8613800138000",
"status": "succeeded",
"request_status": "completed",
"replayed": false,
"total_reserved": 0.004000,
"total_charged": 0.004000,
"total_refunded": 0.000000,
"results": [
{
"product_id": 47,
"product": "wavalid-realtime",
"result": "valid",
"cached": false,
"billing_status": "charged",
"charged_amount": 0.002000,
"refunded_amount": 0.000000,
"checked_at": "2026-09-13T10:00:00Z",
"error_code": null
}
]
}

Để có tài liệu đầy đủ về các trường, xem Định dạng phản hồi.