Skip to main content

Code Examples

Common API use cases with code samples.

QR Code Operations

Create a Document QR Code

Secure QR code with document verification:

curl -X POST https://api.govalid.org/api/v1/qr/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Certificate #2025-001",
"qr_type": "document",
"security_level": "verified",
"metadata": {
"document_number": "CERT-2025-001",
"issued_date": "2025-01-29",
"issuer": "GoValid Inc."
}
}'

Create QR with Expiration

curl -X POST https://api.govalid.org/api/v1/qr/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Limited Time Offer",
"qr_type": "url",
"content": "https://example.com/promo",
"expires_at": "2025-12-31T23:59:59Z"
}'

Create Password-Protected QR

curl -X POST https://api.govalid.org/api/v1/qr/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Confidential Document",
"qr_type": "document",
"password": "secure123",
"content": "Sensitive information here"
}'

Get QR Code Analytics

curl https://api.govalid.org/api/v1/qr/abc123/analytics/ \
-H "Authorization: Bearer YOUR_API_KEY"

Response:

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

Batch Operations

Create Multiple QR Codes

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": "Product 1", "qr_type": "product", "sku": "SKU001"},
{"title": "Product 2", "qr_type": "product", "sku": "SKU002"},
{"title": "Product 3", "qr_type": "product", "sku": "SKU003"}
]
}'

Verification

Verify a QR Code

curl -X POST https://api.govalid.org/api/v1/scan/verify/ \
-H "Content-Type: application/json" \
-d '{
"code": "abc123"
}'

Response:

{
"valid": true,
"qr_type": "document",
"title": "Certificate #2025-001",
"issuer": {
"name": "GoValid Inc.",
"verified": true
},
"created_at": "2025-01-29T12:00:00Z",
"scan_count": 15
}

Account Management

Get Account Info

curl https://api.govalid.org/api/v1/account/ \
-H "Authorization: Bearer YOUR_API_KEY"

Get Usage Statistics

curl https://api.govalid.org/api/v1/account/usage/ \
-H "Authorization: Bearer YOUR_API_KEY"

Response:

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

Register a 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"
}'

Webhook Payload Example

{
"event": "qr.scanned",
"timestamp": "2025-01-29T12:00:00Z",
"data": {
"qr_id": "abc123",
"scan_location": {
"country": "US",
"city": "New York"
},
"device": "mobile"
},
"signature": "sha256=..."
}

Error Handling

Python Example

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("Invalid API key")
elif e.response.status_code == 429:
print("Rate limit exceeded")
retry_after = e.response.headers.get('Retry-After', 60)
print(f"Retry after {retry_after} seconds")
else:
print(f"Error: {e.response.json()}")
return None

SDK Libraries

Official SDKs coming soon:

LanguageStatus
PythonComing soon
JavaScript/Node.jsComing soon
PHPComing soon
JavaComing soon

For now, use the REST API directly with your preferred HTTP client.


Need Help?