Cardbyan Cardbyan
REST API v1 & Webhooks · OpenAPI 3.1

Developer Portal & Full API Reference

Programmatically issue Apple Wallet and Google Wallet passes, live-edit customer fields, SAR balances, and order stages in real time, and integrate ERPs, storefronts, and POS systems via scoped API keys and HMAC-SHA256 webhooks.

Auth & Scopes Passes API (/passes) Live Edit (PATCH) Campaigns, Branches & KPIs Webhooks & Signing Errors & Limits

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.

GET /api/v1/me · Bearer Authentication
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.

GET /api/v1/passes passes:read Search and paginate passes across campaigns by phone, serial, order_ref, custom_field, state, or wallet installation status.
POST /api/v1/passes passes:write Direct server-to-server pass issuance (bypasses interactive customer OTP) returning instant install links for Apple Wallet, Google Wallet, and QR PNG.
GET /api/v1/passes/{pass_ref} passes:read Retrieve live pass state, stamp progress, SAR store credit, active order stage, and wallet installation telemetry.
PATCH /api/v1/passes/{pass_ref} passes:write Live-edit customer fields, balances, expiry, or order stage and push updates straight to the customer's phone wallet.
POST /api/v1/passes/{pass_ref}/actions passes:write Execute atomic transactions (add_stamp, deduct_stamp, set_stamps, topup_credit, deduct_credit, use_unit, set_stage, send_message).
DELETE /api/v1/passes/{pass_ref} passes:write Void/revoke a pass (pass_state = voided) with live wallet sync and full audit retention; reactivate anytime via /restore.
GET /api/v1/passes/{pass_ref}/events passes:read Inspect the chronological scan and API mutation ledger for a specific pass.
POST /api/v1/passes · Direct Server-to-Server Issuance + Idempotency-Key
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).

PATCH /api/v1/passes/{serial_or_id} · Live Field & Balance Edit + Lock-Screen Alert
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.

GET /api/v1/campaigns campaigns:read Create, update, archive, and restore campaigns across all 10 pass scenarios, upload PNG assets, and configure automated reminders.
POST /api/v1/branches branches:write Manage up to 10 GPS branch locations per merchant so passes surface automatically on customer lock screens within 100 meters.
POST /api/v1/campaigns/{id}/broadcast broadcasts:write Queue campaign-wide push broadcasts or 1-to-1 direct customer notifications and poll real iOS/Android delivery counters.
GET /api/v1/analytics/summary?days=30 analytics:read Query rolling KPI summaries (visits, redemptions, wallet installs) and the paginated tenant-wide event ledger.
GET /api/v1/events?limit=50 analytics:read Query rolling KPI summaries (visits, redemptions, wallet installs) and the paginated tenant-wide event ledger.

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.

Python · Verify Outbound X-Cardbyan-Signature (HMAC-SHA256)
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.

401 invalid_api_key / api_key_expiredMissing, revoked, or expired cb_live_ token.
403 insufficient_api_scopeKey lacks the required resource scope for this endpoint.
403 console_session_requiredOwner-only route (/api/v1/api-keys, password, PIN).
404 not_foundResource does not exist or belongs to another merchant.
409 idempotency_key_payload_mismatchIdempotency-Key reused within 24h with a different JSON body.
429 rate_limit_exceededBurst protection triggered; honor Retry-After header.