1. Authentication, Scopes & Idempotency
All /api/v1/* management endpoints accept stateless merchant API keys in request headers with zero cookie or CSRF overhead.
Bearer API Keys (cb_live_...)
Generate keys in the Merchant Console under Integrations and send Authorization: Bearer cb_live_... or X-API-Key. Only SHA-256 hashes are stored at rest, with optional expiration and instant revocation.
Least-Privilege Resource Scopes
Grant each integration only the scopes it requires: passes:read, passes:write, campaigns:read, campaigns:write, broadcasts:write, branches:write, webhooks:read, webhooks:write, or analytics:read. Account credentials and API key minting remain strictly console-session-only.
24-Hour Idempotency Protection
Pass an Idempotency-Key header on pass issuance, balance/stamp actions, and broadcasts. Network retries replay the original response safely, while reusing a key with a mutated body returns HTTP 409.
curl -sS "https://cardbyan.com/api/v1/me" \ -H "Authorization: Bearer cb_live_YOUR_SECRET_API_KEY"
2. Customer Passes API (/api/v1/passes)
First-class lifecycle management for every issued pass, addressable by either UUID (id) or serial_number.
curl -X POST "https://cardbyan.com/api/v1/passes" \
-H "Authorization: Bearer cb_live_YOUR_SECRET_API_KEY" \
-H "Idempotency-Key: erp-invoice-90421" \
-H "Content-Type: application/json" \
-d '{
"campaign_slug": "vip",
"customer_name": "سارة العتيبي",
"customer_phone": "+966551234567",
"custom_field_value": "INV-90421",
"initial_balance_sar": "150.00"
}'
3. Live Pass Editing (PATCH & Inbound update_pass)
Modify any mutable pass attribute via PATCH /api/v1/passes/:ref or the universal inbound webhook action update_pass—changes propagate automatically to Apple Wallet and Google Wallet.
Editable Pass Attributes
Update customer_name, customer_phone, current_offer_text, custom_field_value (e.g. plate or serial), active_order_ref, active_status_code, current_stamps, balance_units, balance_sar, expires_at, relevant_at, and pass_state, plus optional instant lock-screen alert fields (notify_title + notify_body).
Automatic Post-Edit Pipeline
1) Row-locked ACID commit, 2) Background Apple APNs push + Google Wallet object sync, 3) Append-only ScanEvent audit entry, and 4) Outbound webhook dispatch (pass.updated, pass.balance_changed, or pass.revoked).
curl -X PATCH "https://cardbyan.com/api/v1/passes/DEMO-8F2A91C4" \
-H "Authorization: Bearer cb_live_YOUR_SECRET_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"customer_name": "سارة العتيبي — VIP",
"current_offer_text": "خصم 25% خاص لحاملي الفئة الذهبية",
"custom_field_value": "PLATE-ABC-1234",
"expires_at": "2027-12-31T23:59:59+03:00",
"notify_title": "تمت ترقية عضويتك",
"notify_body": "أصبحت بطاقتك الآن ضمن الفئة الذهبية بخصم 25%."
}'
4. Campaigns, Multi-Branch Geofences, Broadcasts & Analytics
Manage pass templates, 100m GPS proximity branches, lock-screen campaigns, and store KPIs programmatically.
5. Bidirectional Webhooks & Signature Verification
Real-time event streaming and inbound POS/e-commerce adapters protected by HMAC-SHA256 signatures and DNS-resolved SSRF guards.
11 Subscribable Outbound Events
Subscribe to specific events or wildcard (*): pass.issued, pass.updated, pass.revoked, pass.wallet_installed, pass.wallet_removed, scan.stamp_added, scan.reward_redeemed, pass.balance_changed, order.stage_changed, pass.morphed, and broadcast.completed.
Inbound Actions & Refund Reversal
Universal JSON endpoints accept issue_or_get, update_pass, add_stamp, deduct_stamp, set_stamps, topup_credit, deduct_credit, set_balance, set_stage, send_message, and revoke_pass—plus opt-in automatic reversal on Salla, Zid, and Foodics order cancellations/refunds.
Verifying X-Cardbyan-Signature
Compute HMAC-SHA256 over <timestamp>.<raw_body> using your endpoint signing secret and compare in constant time against v1.
import hashlib, hmac, time
def verify_cardbyan_webhook(raw_body: bytes, timestamp_hdr: str, sig_hdr: str, secret: str) -> bool:
if abs(time.time() - int(timestamp_hdr)) > 300:
return False
expected = "v1=" + hmac.new(
secret.encode("utf-8"),
f"{timestamp_hdr}.".encode("utf-8") + raw_body,
hashlib.sha256,
).hexdigest()
return hmac.compare_digest(expected, sig_hdr)
6. Standard HTTP Statuses & Error Codes
Every error returns a deterministic JSON object with a machine-readable detail code.