cURL / SDK の例
すべての例は公開ベース URL を使用します。
https://api.zelnum.com/api/v1YOUR_KEY_HERE を 認証 のキーに置き換え、プロダクトのスラッグは バルクプロダクト から取得してください。
配列を送信する
Section titled “配列を送信する”curl -X POST "https://api.zelnum.com/api/v1/detect" \ -H "X-API-Key: YOUR_KEY_HERE" \ -H "Content-Type: application/json" \ -d '{ "product": "YOUR_PRODUCT_SLUG", "country": "CN", "phones": ["+8613800138000", "+8613800138001"] }'レスポンスはタスクトークンと事前に差し引かれた金額を返します。
{ "mode": "async", "task_id": "xKj9aP3qLm7v", "message": "Task queued. Poll GET /api/v1/tasks/xKj9aP3qLm7v for progress.", "summary": { "total": 5000, "cost_deducted": 0.500000 }}ファイルをアップロードする
Section titled “ファイルをアップロードする”curl -X POST "https://api.zelnum.com/api/v1/detect/file" \ -H "X-API-Key: YOUR_KEY_HERE" \ -F "product=YOUR_PRODUCT_SLUG" \ -F "country=CN" \ -F "file=@numbers.txt"numbers.txt には1行につき1つの番号を、最大 50 MB まで格納します。-d ではなく -F であることに注意してください。このエンドポイントは multipart/form-data を受け取ります。
完了するまでポーリングする
Section titled “完了するまでポーリングする”TOKEN=xKj9aP3qLm7v
while true; do status=$(curl -s "https://api.zelnum.com/api/v1/tasks/$TOKEN" \ -H "X-API-Key: YOUR_KEY_HERE")
printf '%s\n' "$status" | jq '{status, progress, valid, invalid, unknown}'
case "$(printf '%s' "$status" | jq -r .status)" in completed|failed) break ;; esac
sleep 4doneポーリング間隔は、どのサイズのタスクでも4秒が妥当です。タスクページは progress をパーセンテージで報告します。
結果をダウンロードする
Section titled “結果をダウンロードする”curl -s "https://api.zelnum.com/api/v1/tasks/$TOKEN/result" \ -H "X-API-Key: YOUR_KEY_HERE" | jq -r .download_urldownload_url には有効期限があります。expires_at より前に取得しないとファイルは失われます。その後:
curl -L -H "X-API-Key: YOUR_KEY_HERE" \ "https://api.zelnum.com/api/v1/tasks/$TOKEN/download" -o results.csv1つのスクリプトで最初から最後まで
Section titled “1つのスクリプトで最初から最後まで”#!/usr/bin/env bashset -euo pipefail
API="https://api.zelnum.com/api/v1"KEY="YOUR_KEY_HERE"SLUG="YOUR_PRODUCT_SLUG"
task=$(curl -s -X POST "$API/detect" \ -H "X-API-Key: $KEY" -H "Content-Type: application/json" \ -d "{\"product\":\"$SLUG\",\"country\":\"CN\",\"phones\":[\"+8613800138000\"]}" \ | jq -r .task_id)
echo "task $task submitted"
until [ "$(curl -s "$API/tasks/$task" -H "X-API-Key: $KEY" | jq -r .status)" = "completed" ]; do sleep 4done
url=$(curl -s "$API/tasks/$task/result" -H "X-API-Key: $KEY" | jq -r .download_url)curl -L "$url" -o results.csv
echo "wrote results.csv"