# KDA API > Enterprise Virtual Top-Up (VTU) and bill-payment infrastructure for Nigeria: Data, Airtime, TV/Cable, Electricity, Exam PINs, Data Cards, Recharge Cards, plus Balance, Transactions, and Withdrawals. Same host for sandbox and production; the API-key prefix selects the environment. Full human docs: /docs — Full machine spec: /llms-full.txt ## Base URLs ```text https:///api/services https:///api/profile ``` - HTTPS only. JSON request/response. `Authorization: Bearer ` on every call. - No separate sandbox host. Key prefix routes the environment. ## Authentication ```http Authorization: Bearer kds_test_YOUR_API_KEY Content-Type: application/json ``` - Test key `kds_test_*` → sandbox simulator, no real debit. Live key `kds_live_*` → real networks, real wallet debit. - Scopes are per-key, one scope per key. Create two keys if you need both. - `services` → `/api/services/*` only (plans, purchases, verify, test). - `profile` → `/api/profile/*` only (balance, transactions, withdraw, test). - Wrong scope → `403 FORBIDDEN` with `keyStatus: "FORBIDDEN"`. - `GET /api/services/test` and `GET /api/profile/test` accept either scope. - Missing/invalid/disabled key → `401 UNAUTHORIZED` with `keyStatus`: `INVALID` | `NOT_FOUND` | `DISABLED`. No header at all → `401` without `keyStatus`. - Rate limits per key: LIVE 10,000 req/hour, SANDBOX 500 req/hour. Exhausted → `429 RATE_LIMITED` with `retryAfterMs` + `Retry-After` / `X-Retry-After` headers. Wait before retrying. - Never expose live keys client-side. Store in env/secrets manager. Rotate periodically. ## Standard shapes Success: ```json { "success": true, "message": "Human readable message", "transactionId": "KDS-...", "data": {} } ``` Error: ```json { "success": false, "error": { "code": "ERROR_CODE", "message": "...", "keyStatus": "INVALID", "transactionId": "KDS-...", "details": [] } } ``` - `details[]` only on `VALIDATION_ERROR` (`{ field, message }`). - `transactionId` present on `TRANSACTION_FAILED` and `CONFLICT` for tracing. - `keyStatus` present on `401`/`403` when a key was supplied. ## Quickstart 1. `GET /api/services/test` → expect `"environment": "TEST"`, check `key.scope`. 2. `GET /api/services/data/plans` → pick a `kds-*` plan id (the `-v1-`/`-v2-` segment selects the provider route). 3. `POST /api/services/data` with `planId`, `number`, `idempotencyKey` (UUID v4). 4. Test key returns simulated success. Subscribe to webhooks before going live; never retry `PENDING` with a new key. 5. Going live: create `kds_live_*`, fund wallet, re-call `/test` (expect `"LIVE"`), then one low-value live purchase and reconcile balance + transactions + webhook. ## Verify key (either scope) - `GET /api/services/test` - `GET /api/profile/test` - Response: `{ success, message, environment: "TEST"|"LIVE", user: { id, email }, key: { name, prefix, type, scope, enabled, remaining, createdAt } }` ## Service endpoints (services scope) Plans are `GET`, purchases and verifications are `POST`. Every purchase requires `idempotencyKey` (UUID v4). ```text GET /api/services/data/plans?type=SME&id=kds-data-... POST /api/services/data GET /api/services/airtime/plans?id=kds-airtime-... POST /api/services/airtime GET /api/services/tv/plans?type=Padi&id=kds-tv-... POST /api/services/tv POST /api/services/verify/tv GET /api/services/electricity/plans?id=kds-elec-... POST /api/services/electricity POST /api/services/verify/meter (alias: /api/services/verify/bill) GET /api/services/exam/plans?id=kds-exam-... POST /api/services/exam GET /api/services/data-card/plans?id=kds-data-card-... POST /api/services/data-card GET /api/services/recharge-card/plans?id=kds-pin-... POST /api/services/recharge-card ``` Plans filters: `?id=` fetches one plan (all services). `?type=` filters by category (data + tv only). No filter returns everything; data/tv group by `{ type, plans[] }`. ## Purchase payloads Data — `POST /api/services/data`: ```json { "planId": "kds-data-mtn-sme-v1-003", "number": "08012345678", "idempotencyKey": "uuid", "isPorted": false } ``` - `number` min 10 chars. `isPorted` optional (default false); set true for ported numbers (MNP routing). `amount` optional, provider-ignored. Airtime — `POST /api/services/airtime`: ```json { "planId": "kds-airtime-mtn-vtu-v2", "number": "08012345678", "amount": 100, "idempotencyKey": "uuid", "isPorted": false } ``` - `planId` is a channel id (`kds-airtime-{network}-{VTU|Share and Sell}-v{1|2|3}`). `amount` required. - Route limits: v1 min 50 max 500; v2 min 100 max 10,000; v3 ungated. Outside v1/v2 limits → rejected before any wallet debit. v3 upstream rejections still auto-refund. TV — `POST /api/services/tv` (verify first): ```json { "planId": "kds-tv-gotv-v1-001", "iucNumber": "2021234567", "idempotencyKey": "uuid" } ``` - Verify: `POST /api/services/verify/tv` with `{ "smartCardNumber": "2021234567", "providerId": "kds-tv-gotv" }` → `{ success, data: { valid, name } }`. Electricity — `POST /api/services/electricity` (verify first): ```json { "providerId": "kds-elec-kedco-v1", "meterNumber": "04123456789", "amount": 5000, "meterType": "PREPAID", "idempotencyKey": "uuid" } ``` - Purchase `meterType` is UPPERCASE `PREPAID`|`POSTPAID`. `amount` min 100. Response includes `electricityToken` (prepaid) and conditional `electricityUnits`. - Verify: `POST /api/services/verify/meter` (or `/verify/bill`) with lowercase type: `{ "discoSlug": "KEDCO", "meterNumber": "04123456789", "meterType": "prepaid" }` → `{ success, data: { valid, name, address? } }`. `address` is conditional. Exam — `POST /api/services/exam`: ```json { "providerId": "kds-exam-waec-v1", "quantity": 1, "cardName": "Customer", "idempotencyKey": "uuid" } ``` - `quantity` min 1 max 3. `cardName` optional (default `"Customer"`). Response `pin` may contain `<=>`-joined PIN+serial. Data card / Recharge card — `POST /api/services/data-card`, `POST /api/services/recharge-card`: ```json { "planId": "kds-data-card-mtn-750mb-v1", "quantity": 2, "cardName": "My Shop", "idempotencyKey": "uuid" } ``` - `quantity` min 1 max 10. `pin`/`serial` are comma-separated lists matching `quantity`. ## Account endpoints (profile scope) - `GET /api/profile/balance` → `{ success, data: { mode: "sandbox"|"live", balance } }`. Check before large purchases; shortfall fails with `402 INSUFFICIENT_BALANCE`. - `GET /api/profile/transactions?page=1&limit=10&type=DATA` → `{ success, pagination: { total, page, limit, totalPages }, transactions: [] }`. `limit` max 100. `type`: `DATA`|`AIRTIME`|`TV`|`ELECTRICITY`|`EXAM_PIN`|`DATA_PRINT`|`PIN_PRINT`. Omit for all. - `POST /api/profile/withdraw` → `{ amount>=1000, bankCode, accountNumber(10-digit), pin(4-digit), narration? }`. Requires **Allow Withdrawals** enabled on the key (else `412`). Response is `PENDING`; settle via withdrawal webhooks. Destination name must match key owner; unknown `bankCode` → `400`. ## Pricing model - Data/TV/Exam/Data-cards: `salePrice` (₦ final debit). - Airtime/Recharge-cards: `salePercentage` discount off face value (`"3"` → ₦100 costs ₦97). - Electricity: `saleFee` (₦ flat fee added; v1 usually cheaper than v2). - Plan ids embed the route: `-v1-` primary, `-v2-` secondary. v2 usually cheaper for Data/Airtime; v1 cheaper for Electricity/NECO/StarTimes Smart and wider for DStv combos/PROMO/NABTEB. Re-fetch plans; never cache prices long-term. ## Reliability - `idempotencyKey` is REQUIRED on every purchase. New UUID per intent; reuse only for retries. Duplicate → `409 CONFLICT` with original `transactionId`; no double charge. - Most purchases settle <3s but can return `PENDING`. Never retry `PENDING` with a new key — wait for the webhook or query transactions. - Webhooks: subscribe per category (Purchase → `PURCHASE_SUCCESS`/`PURCHASE_FAILED`; Withdrawal → `WITHDRAWAL_SUCCESS`/`WITHDRAWAL_FAILED`). Verify `X-Webhook-Signature` (HMAC-SHA256 of raw body) before parsing, reject `timestamp` skew >5min, respond `200` <10s. No automatic retries today. Sandbox never fires withdrawal settlement events — use the dashboard Test button. - Errors: `400 VALIDATION_ERROR` (see `details`), `401 UNAUTHORIZED`, `402 INSUFFICIENT_BALANCE`, `403 FORBIDDEN`, `404 NOT_FOUND`, `405 METHOD_NOT_ALLOWED`, `409 CONFLICT`, `412 PRECONDITION_FAILED` (KYC limit / withdrawals disabled), `422 TRANSACTION_FAILED` (refunded), `429 RATE_LIMITED`, `500 INTERNAL_ERROR`. ## Guide index - Docs home: /docs - Authentication + keyStatus: /docs/getting-started/authentication - Errors + handling snippets: /docs/getting-started/errors - Idempotency: /docs/getting-started/idempotency - Webhooks + signature snippets: /docs/getting-started/webhooks - Going live checklist: /docs/getting-started/going-live - Plan versions (v1 vs v2): /docs/reference/plan-versions - Network prefixes + ported numbers: /docs/reference/network-prefixes - Verify key: /docs/reference/verify - Supported banks: /docs/reference/supported-banks - Live pricing: /docs/pricing - Services: /docs/services/data, /docs/services/airtime, /docs/services/tv, /docs/services/electricity, /docs/services/exam-pins, /docs/services/data-cards, /docs/services/recharge-cards - Account: /docs/account/balance, /docs/account/transactions, /docs/account/withdraw