Lewati ke konten

Contoh cURL / SDK

Semua contoh menggunakan base URL publik:

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

Ganti YOUR_KEY_HERE dengan key dari Autentikasi, dan ambil ID produk dari Produk realtime — ID di bawah ini hanyalah contoh dan memang berubah saat produk ditambahkan.

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 opsional jika nomornya sudah dalam bentuk E.164 lengkap. Sertakan jika Anda mengirim nomor nasional.

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]}'

Tiga produk, satu request_id, tiga entri di results, tiga tagihan. Lihat Produk realtime untuk batas sepuluh 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]}'

Perhatikan tidak adanya country — produk email menolaknya.

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}]}'

Periksa billing_status per entri, bukan hanya status HTTP — 200 masih bisa memuat entri yang dikembalikan dananya. Lihat Penagihan & pengembalian dana.

Loop percobaan ulang yang tidak mungkin menagih dua kali

Section titled “Loop percobaan ulang yang tidak mungkin menagih dua kali”

Inti dari Idempotency-Key adalah skrip ini aman dijalankan dua kali:

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 ;;
# Hasil tidak pasti: di sinilah gunanya key. Kirim ulang body yang sama.
500|000) sleep 2 ;;
# Masih berjalan, atau dibatasi: patuhi Retry-After dan pertahankan key yang sama.
409|429) sleep "$(printf '%s' "$response" | sed '$d' | jq -r '.retry_after // 2')" ;;
*) exit 1 ;;
esac
done

Jangan pernah membuat key baru untuk mencoba ulang permintaan yang hasilnya tidak Anda amati — itulah tepatnya cara satu pemeriksaan dibayar dua kali. Lihat Idempotensi & percobaan ulang.

{
"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
}
]
}

Untuk referensi field lengkap, lihat Format respons.