Contoh Kode
Kasus penggunaan API umum dengan contoh kode.
Operasi QR Code
Buat Document QR Code
QR code aman dengan verifikasi dokumen:
curl -X POST https://api.govalid.org/api/v1/qr/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Sertifikat #2025-001",
"qr_type": "document",
"security_level": "verified",
"metadata": {
"document_number": "CERT-2025-001",
"issued_date": "2025-01-29",
"issuer": "GoValid Inc."
}
}'
Buat QR dengan Kedaluwarsa
curl -X POST https://api.govalid.org/api/v1/qr/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Penawaran Terbatas",
"qr_type": "url",
"content": "https://example.com/promo",
"expires_at": "2025-12-31T23:59:59Z"
}'
Buat QR Terproteksi Password
curl -X POST https://api.govalid.org/api/v1/qr/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Dokumen Rahasia",
"qr_type": "document",
"password": "secure123",
"content": "Informasi sensitif di sini"
}'
Dapatkan Analitik QR Code
curl https://api.govalid.org/api/v1/qr/abc123/analytics/ \
-H "Authorization: Bearer YOUR_API_KEY"
Respons:
{
"total_scans": 150,
"unique_scans": 89,
"scans_today": 12,
"scans_this_week": 45,
"top_locations": [
{"country": "US", "count": 50},
{"country": "ID", "count": 35},
{"country": "GB", "count": 20}
],
"scan_timeline": [
{"date": "2025-01-28", "count": 15},
{"date": "2025-01-29", "count": 12}
]
}
Operasi Batch
Buat Beberapa QR Code
curl -X POST https://api.govalid.org/api/v1/qr/bulk/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"qr_codes": [
{"title": "Produk 1", "qr_type": "product", "sku": "SKU001"},
{"title": "Produk 2", "qr_type": "product", "sku": "SKU002"},
{"title": "Produk 3", "qr_type": "product", "sku": "SKU003"}
]
}'
Verifikasi
Verifikasi QR Code
curl -X POST https://api.govalid.org/api/v1/scan/verify/ \
-H "Content-Type: application/json" \
-d '{
"code": "abc123"
}'
Respons:
{
"valid": true,
"qr_type": "document",
"title": "Sertifikat #2025-001",
"issuer": {
"name": "GoValid Inc.",
"verified": true
},
"created_at": "2025-01-29T12:00:00Z",
"scan_count": 15
}
Manajemen Akun
Dapatkan Info Akun
curl https://api.govalid.org/api/v1/account/ \
-H "Authorization: Bearer YOUR_API_KEY"
Dapatkan Statistik Penggunaan
curl https://api.govalid.org/api/v1/account/usage/ \
-H "Authorization: Bearer YOUR_API_KEY"
Respons:
{
"plan": "business",
"qr_codes": {
"used": 150,
"limit": 1000
},
"storage": {
"used_mb": 256,
"limit_mb": 5000
},
"api_calls": {
"used": 4521,
"limit": 10000,
"reset_at": "2025-02-01T00:00:00Z"
}
}
Webhooks
Daftarkan Webhook
curl -X POST https://api.govalid.org/api/v1/webhooks/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://your-server.com/webhook",
"events": ["qr.scanned", "qr.created", "qr.expired"],
"secret": "your_webhook_secret"
}'
Contoh Payload Webhook
{
"event": "qr.scanned",
"timestamp": "2025-01-29T12:00:00Z",
"data": {
"qr_id": "abc123",
"scan_location": {
"country": "US",
"city": "New York"
},
"device": "mobile"
},
"signature": "sha256=..."
}
Penanganan Error
Contoh Python
import requests
def create_qr(api_key, data):
try:
response = requests.post(
"https://api.govalid.org/api/v1/qr/",
headers={"Authorization": f"Bearer {api_key}"},
json=data
)
response.raise_for_status()
return response.json()
except requests.exceptions.HTTPError as e:
if e.response.status_code == 401:
print("API key tidak valid")
elif e.response.status_code == 429:
print("Batas rate terlampaui")
retry_after = e.response.headers.get('Retry-After', 60)
print(f"Coba lagi setelah {retry_after} detik")
else:
print(f"Error: {e.response.json()}")
return None
Library SDK
SDK resmi akan segera hadir:
| Bahasa | Status |
|---|---|
| Python | Segera hadir |
| JavaScript/Node.js | Segera hadir |
| PHP | Segera hadir |
| Java | Segera hadir |
Untuk saat ini, gunakan REST API langsung dengan HTTP client pilihan Anda.
Butuh Bantuan?
- Referensi API - Dokumentasi interaktif
- Dukungan - Hubungi tim kami