Tax Poa Fiscalization API
Issue KRA-compliant invoices, credit notes, and debit notes through a single REST surface. Register PINs and branches, publish products, fund a prepaid wallet, and track every request.
Overview
All endpoints return JSON. Successful responses use HTTP 2xx; errors use the standard envelope described below. All timestamps are ISO 8601 in UTC.
pending → processing → success | failed | stuck. Stuck documents can be reconciled back to success or failed. Use GET /v1/invoices/{id} to poll.
development mode are billed at KES 0.00. PINs in live mode are billed KES 0.30 per successful KRA operation — debited from your wallet.
POST /invoices, /credit-notes, /debit-notes) accept an Idempotency-Key header. Same key + same body returns the cached response for 24 h. Same key + different body returns 409 IDEMPOTENCY_CONFLICT.
Authentication
Two authentication methods are supported. You must use exactly one — sending both returns 400 AMBIGUOUS_AUTH.
JWT bearer (console / user sessions)
Obtained from POST /v1/auth/verify-otp. Sessions expire after 24 hours. Revoke via server-side session invalidation.
Authorization: Bearer <jwt>
API key (server-to-server)
Create a key at POST /v1/tenants/{tenantID}/api-keys. Keys are prefixed tpk_<live|test>_… and secrets are tps_…. Store both — they are encrypted at rest and can only be retrieved via the reveal endpoint.
X-API-Key: tpk_live_... X-API-Secret: tps_...
/v1/auth/* route and /v1/wallet/lipabiz-callback and /healthz require no authentication.Errors
Every non-2xx response uses this envelope. Inspect code for programmatic handling; details is human-readable.
{
"error": "Bad Request",
"code": "VALIDATION",
"details": "Key: 'SignupRequest.Email' Error:Field validation for 'Email' failed on the 'email' tag"
}| Code | HTTP | Meaning |
|---|---|---|
VALIDATION | 400 | Body or query failed validation. details explains which field. |
INVALID_ID | 400 | A UUID path or query parameter could not be parsed. |
INVALID_TENANT_ID | 400 | Malformed tenantID path parameter. |
INVALID_PIN_ID | 400 | Malformed pinID path parameter. |
AMBIGUOUS_AUTH | 400 | Both Authorization and API key headers supplied. |
UNAUTHENTICATED | 401 | No auth headers supplied. |
INVALID_TOKEN | 401 | JWT signature or claims invalid. |
SESSION_EXPIRED | 401 | JWT valid but backing session revoked/expired. |
INVALID_API_KEY | 401 | API key or secret mismatch / revoked. |
INVALID_OTP | 401 | OTP wrong, used, or expired. |
FORBIDDEN | 403 | Caller lacks ownership or scope. |
NOT_FOUND | 404 | Resource not found (or not yours). |
EMAIL_EXISTS | 409 | Signup with an existing email. |
PHONE_EXISTS | 409 | Signup with an existing phone. |
RATE_LIMITED | 429 | Exceeded the per-IP or per-identity limit. |
DB | 500 | Unexpected database error. Safe to retry. |
CREATE_FAILED | 500 | Insert failed for a domain reason. |
ADD_PIN_FAILED / ADD_BRANCH_FAILED | 500 | PIN/branch creation failed (often duplicate). |
OTP_FAILED | 500 | All three OTP channels (email/SMS/WhatsApp) failed. |
Rate Limits
Enforced per-identity using a Redis sliding window. On 429, back off with jitter.
| Endpoint | Identity | Limit | Window |
|---|---|---|---|
POST /v1/auth/lookup | IP | 10 | 60s |
POST /v1/auth/signup | IP | 5 | 300s |
POST /v1/auth/request-otp | 5 | 300s |
All other endpoints share a generous platform-wide ceiling.
Authentication Endpoints
Public. No auth headers required.
POST /v1/auth/lookup Look up account
Determine whether a user exists for an email or phone. Used before signup to route returning users to the OTP flow.
Request body
| Field | Type | Req | Description |
|---|---|---|---|
identifier | string | REQ | Email address or phone (E.164, +254…, or local 07…). |
Example
curl -X POST https://api.taxpoa.com/v1/auth/lookup \ -H "Content-Type: application/json" \ -d '{"identifier":"[email protected]"}'
Responses
{
"exists": true,
"email": "[email protected]",
"phone": "+254700000000",
"masked_email": "y**@company.com",
"masked_phone": "+254***000",
"full_name": "Jane Doe"
}{ "exists": false }POST /v1/auth/signup Create account
Creates a new user and dispatches a 6-digit verification code via email, SMS, and WhatsApp in parallel.
Request body
| Field | Type | Req | Description |
|---|---|---|---|
full_name | string | REQ | 1–200 chars. |
phone | string | REQ | 7–20 chars; normalised to E.164. |
email | string | REQ | Valid email; lowercased on save. |
Example
curl -X POST https://api.taxpoa.com/v1/auth/signup \ -H "Content-Type: application/json" \ -d '{ "full_name":"Jane Doe", "phone":"+254700000000", "email":"[email protected]" }'
Responses
{
"user": {
"id": "a1b2c3d4-...",
"email": "[email protected]",
"phone": "+254700000000",
"full_name": "Jane Doe",
"role": "tenant_admin",
"status": "active",
"created_at": "2025-01-01T00:00:00Z"
},
"otp_sent": true
}{
"user": { ... },
"otp_sent": false,
"warning": "account created but OTP delivery failed — retry from /v1/auth/request-otp"
}409 EMAIL_EXISTS or 409 PHONE_EXISTS if either is already registered.POST /v1/auth/request-otp Request OTP
Resend a login code to an existing account. Codes expire after 5 minutes.
Request body
| Field | Type | Req | Description |
|---|---|---|---|
email | string | REQ | Registered email address. |
phone | string | REQ | Registered phone (must match account). |
curl -X POST https://api.taxpoa.com/v1/auth/request-otp \ -H "Content-Type: application/json" \ -d '{"email":"[email protected]","phone":"+254700000000"}'
Response 200
{
"status": "sent",
"channels": ["email", "sms", "whatsapp"]
}POST /v1/auth/verify-otp Verify OTP · get JWT
Consumes the OTP and returns a 24-hour JWT plus the user profile. This JWT authorises all tenant endpoints until expiry or session revocation.
Request body
| Field | Type | Req | Description |
|---|---|---|---|
email | string | REQ | Registered email address. |
code | string | REQ | 6-digit code from the OTP message. |
curl -X POST https://api.taxpoa.com/v1/auth/verify-otp \ -H "Content-Type: application/json" \ -d '{"email":"[email protected]","code":"123456"}'
Response 200
{
"token": "eyJhbGciOiJIUzI1NiIs...",
"user": {
"id": "a1b2c3d4-...",
"email": "[email protected]",
"phone": "+254700000000",
"full_name": "Jane Doe",
"role": "tenant_admin",
"status": "active",
"created_at": "2025-01-01T00:00:00Z"
}
}Tenants
A tenant is a workspace that owns PINs, products, documents, and a wallet. Requires JWT or API key.
GET /v1/tenants List my tenants
Returns tenants owned by the authenticated user. With API key auth, returns the single tenant bound to the key.
curl https://api.taxpoa.com/v1/tenants \
-H "Authorization: Bearer $JWT"Response 200
{
"data": [
{
"id": "11111111-...",
"owner_id": "a1b2c3d4-...",
"name": "Acme Ltd",
"email": "[email protected]",
"phone": "+254700000000",
"status": "active",
"created_at": "2025-01-01T00:00:00Z"
}
]
}POST /v1/tenants Create tenant
Creates a tenant owned by the authenticated user and provisions a zero-balance wallet.
Request body
| Field | Type | Req | Description |
|---|---|---|---|
name | string | REQ | Business name. |
email | string | REQ | Billing contact email. |
phone | string | REQ | Billing contact phone. |
curl -X POST https://api.taxpoa.com/v1/tenants \ -H "Authorization: Bearer $JWT" \ -H "Content-Type: application/json" \ -d '{"name":"Acme Ltd","email":"[email protected]","phone":"+254700000000"}'
Response 201
{
"id": "11111111-...",
"owner_id": "a1b2c3d4-...",
"name": "Acme Ltd",
"email": "[email protected]",
"phone": "+254700000000",
"status": "active",
"created_at": "2025-01-01T00:00:00Z"
}PINs & Branches
KRA PINs are the fiscal identity used for documents. Each PIN has one or more branches. All /{tenantID} routes require that you own the tenant.
GET /v1/tenants/{tenantID}/pins List PINs
Response 200
{
"data": [
{
"id": "22222222-...",
"tenant_id": "11111111-...",
"pin": "P051234567X",
"name": "Head Office",
"mode": "development",
"kra_verified_at": "2025-01-01T00:00:00Z",
"created_at": "2025-01-01T00:00:00Z"
}
]
}POST /v1/tenants/{tenantID}/pins Add PIN
Registers a KRA PIN for the tenant. Newly added PINs default to development mode (no billing).
Request body
| Field | Type | Req | Description |
|---|---|---|---|
pin | string | REQ | KRA PIN, e.g. P051234567X. |
name | string | REQ | Display name, e.g. Head Office. |
curl -X POST https://api.taxpoa.com/v1/tenants/11111111-.../pins \ -H "Authorization: Bearer $JWT" \ -H "Content-Type: application/json" \ -d '{"pin":"P051234567X","name":"Head Office"}'
Response 201
{
"id": "22222222-...",
"tenant_id": "11111111-...",
"pin": "P051234567X",
"name": "Head Office",
"mode": "development",
"kra_verified_at": "2025-01-01T00:00:00Z",
"created_at": "2025-01-01T00:00:00Z"
}PUT /v1/tenants/{tenantID}/pins/{pinID}/mode Set PIN mode
Toggle between development (free) and live (billed KES 0.30 per operation).
Request body
| Field | Type | Req | Values |
|---|---|---|---|
mode | string | REQ | development · live |
curl -X PUT https://api.taxpoa.com/v1/tenants/11111111-.../pins/22222222-.../mode \ -H "Authorization: Bearer $JWT" \ -H "Content-Type: application/json" \ -d '{"mode":"live"}'
Response 200
{ "mode": "live" }GET /v1/tenants/{tenantID}/branches List branches
Response 200
{
"data": [
{
"id": "33333333-...",
"pin_id": "22222222-...",
"branch_id": "00",
"name": "Main",
"kra_verified_at": "2025-01-01T00:00:00Z",
"created_at": "2025-01-01T00:00:00Z"
}
]
}POST /v1/tenants/{tenantID}/pins/{pinID}/branches Add branch
Request body
| Field | Type | Req | Description |
|---|---|---|---|
branch_id | string | REQ | Two-digit code, e.g. 00 or 01. |
name | string | REQ | Branch display name. |
curl -X POST https://api.taxpoa.com/v1/tenants/11111111-.../pins/22222222-.../branches \ -H "Authorization: Bearer $JWT" \ -H "Content-Type: application/json" \ -d '{"branch_id":"00","name":"Main"}'
Response 201
{
"id": "33333333-...",
"pin_id": "22222222-...",
"branch_id": "00",
"name": "Main",
"kra_verified_at": "2025-01-01T00:00:00Z",
"created_at": "2025-01-01T00:00:00Z"
}Products
Product catalogue registered against a PIN. Each product is asynchronously submitted to KRA; track its kra_status field.
GET /v1/tenants/{tenantID}/products List products
Response 200
{
"data": [
{
"id": "44444444-...",
"tenant_id": "11111111-...",
"pin_id": "22222222-...",
"item_name": "Blue T-shirt",
"item_class_code": "5059690800",
"item_type_code": "1",
"tax_type_code": "VAT_16",
"unit_price": 1500.00,
"kra_status": "success",
"created_at": "2025-01-01T00:00:00Z"
}
]
}POST /v1/tenants/{tenantID}/products Create product
Creates the product locally and enqueues a KRA SaveItem job. Returns 201 immediately with kra_status = pending.
Request body
| Field | Type | Req | Description |
|---|---|---|---|
pin_id | uuid | REQ | The PIN the product belongs to. |
item_name | string | REQ | Product display name. |
item_class_code | string | REQ | KRA item classification code. |
item_type_code | string | REQ | KRA item type code. |
tax_type_code | string | REQ | VAT_16 · VAT_0 · EXEMPT |
unit_price | number | REQ | Non-negative decimal. |
curl -X POST https://api.taxpoa.com/v1/tenants/11111111-.../products \ -H "Authorization: Bearer $JWT" \ -H "Content-Type: application/json" \ -d '{ "pin_id":"22222222-...", "item_name":"Blue T-shirt", "item_class_code":"5059690800", "item_type_code":"1", "tax_type_code":"VAT_16", "unit_price":1500.00 }'
Response 201
{
"id": "44444444-...",
"tenant_id": "11111111-...",
"pin_id": "22222222-...",
"item_name": "Blue T-shirt",
"item_class_code": "5059690800",
"item_type_code": "1",
"tax_type_code": "VAT_16",
"unit_price": 1500.00,
"kra_status": "pending",
"created_at": "2025-01-01T00:00:00Z"
}Documents
All documents follow the same state machine and are submitted asynchronously to KRA via a background worker. Poll GET /v1/invoices/{id} to watch status change.
GET /v1/tenants/{tenantID}/invoices List invoices
Response 200
{
"data": [
{
"id": "55555555-...",
"invoice_number": "INV-1001",
"customer_name": "John Client",
"customer_pin": "A001234567X",
"total_amount": 1740.00,
"tax_amount": 240.00,
"currency": "KES",
"status": "success",
"receipt_no": "0000000001",
"receipt_sign": "base64-signature",
"created_at": "2025-01-01T00:00:00Z",
"updated_at": "2025-01-01T00:00:10Z"
}
]
}POST /v1/tenants/{tenantID}/invoices Submit invoice
Creates a pending invoice and enqueues the KRA submission. Use Idempotency-Key to safely retry.
Request body
| Field | Type | Req | Description |
|---|---|---|---|
pin_id | uuid | REQ | Must belong to tenant. |
branch_id | uuid | REQ | Must belong to the PIN. |
invoice_number | string | REQ | Merchant invoice number. |
customer_name | string | REQ | Buyer name. |
customer_pin | string | OPT | Buyer KRA PIN. |
total_amount | number | REQ | > 0. |
tax_amount | number | REQ | ≥ 0. |
currency | string | OPT | Default KES. |
curl -X POST https://api.taxpoa.com/v1/tenants/11111111-.../invoices \ -H "Authorization: Bearer $JWT" \ -H "Idempotency-Key: 8f2b1c80-..." \ -H "Content-Type: application/json" \ -d '{ "pin_id":"22222222-...", "branch_id":"33333333-...", "invoice_number":"INV-1001", "customer_name":"John Client", "customer_pin":"A001234567X", "total_amount":1740.00, "tax_amount":240.00, "currency":"KES" }'
Response 201
{
"id": "55555555-...",
"tenant_id": "11111111-...",
"pin_id": "22222222-...",
"branch_id": "33333333-...",
"invoice_number": "INV-1001",
"customer_name": "John Client",
"total_amount": 1740.00,
"tax_amount": 240.00,
"currency": "KES",
"status": "pending",
"created_at": "2025-01-01T00:00:00Z",
"updated_at": "2025-01-01T00:00:00Z"
}Idempotency-Key: <uuid> to make retries safe. Same key + different body returns 409.GET /v1/invoices/{id} Get invoice (poll status)
Returns one invoice by ID, including receipt_no and receipt_sign once KRA has accepted it.
curl https://api.taxpoa.com/v1/invoices/55555555-... \
-H "Authorization: Bearer $JWT"Response 200
{
"id": "55555555-...",
"invoice_number": "INV-1001",
"status": "success",
"receipt_no": "0000000001",
"receipt_sign": "base64-signature",
"failure_reason": null,
"created_at": "2025-01-01T00:00:00Z",
"updated_at": "2025-01-01T00:00:10Z"
}GET /v1/tenants/{tenantID}/credit-notes List credit notes
{
"data": [
{
"id": "66666666-...",
"original_invoice_id": "55555555-...",
"original_receipt_no": "0000000001",
"amount": 1740.00,
"reason": "Returned goods",
"status": "success",
"receipt_no": "0000000002",
"created_at": "2025-01-01T00:00:00Z"
}
]
}POST /v1/tenants/{tenantID}/credit-notes Issue credit note
The referenced invoice must be success. Original receipt_no is looked up server-side.
Request body
| Field | Type | Req | Description |
|---|---|---|---|
pin_id | uuid | REQ | PIN to submit under. |
branch_id | uuid | REQ | Branch of that PIN. |
original_invoice_id | uuid | REQ | Must be a successful invoice. |
amount | number | REQ | > 0. |
reason | string | REQ | Human-readable reason. |
curl -X POST https://api.taxpoa.com/v1/tenants/11111111-.../credit-notes \ -H "Authorization: Bearer $JWT" \ -H "Idempotency-Key: 9b..." \ -H "Content-Type: application/json" \ -d '{ "pin_id":"22222222-...", "branch_id":"33333333-...", "original_invoice_id":"55555555-...", "amount":1740.00, "reason":"Returned goods" }'
Response 201
{
"id": "66666666-...",
"original_invoice_id": "55555555-...",
"original_receipt_no": "0000000001",
"amount": 1740.00,
"reason": "Returned goods",
"status": "pending",
"created_at": "2025-01-01T00:00:00Z"
}GET /v1/tenants/{tenantID}/debit-notes List debit notes
{
"data": [
{
"id": "77777777-...",
"original_invoice_id": "55555555-...",
"original_receipt_no": "0000000001",
"amount": 500.00,
"reason": "Underpaid",
"status": "success",
"created_at": "2025-01-01T00:00:00Z"
}
]
}POST /v1/tenants/{tenantID}/debit-notes Issue debit note
Same shape as credit note. The referenced invoice must be success.
curl -X POST https://api.taxpoa.com/v1/tenants/11111111-.../debit-notes \ -H "Authorization: Bearer $JWT" \ -H "Idempotency-Key: 1a..." \ -H "Content-Type: application/json" \ -d '{ "pin_id":"22222222-...", "branch_id":"33333333-...", "original_invoice_id":"55555555-...", "amount":500.00, "reason":"Underpaid" }'
Response 201
{
"id": "77777777-...",
"original_invoice_id": "55555555-...",
"original_receipt_no": "0000000001",
"amount": 500.00,
"reason": "Underpaid",
"status": "pending",
"created_at": "2025-01-01T00:00:00Z"
}Wallet
Every tenant has a prepaid wallet. Successful live operations debit KES 0.30. Top up via Lipabiz — you're redirected, and funds are credited via an external callback.
GET /v1/tenants/{tenantID}/wallet/balance Balance
curl https://api.taxpoa.com/v1/tenants/11111111-.../wallet/balance \
-H "Authorization: Bearer $JWT"Response 200
{ "balance": 5000.00 }POST /v1/tenants/{tenantID}/wallet/topup Initiate top up
Creates a pending top-up and returns a Lipabiz payment URL. Open it in a browser; funds are credited when Lipabiz calls back.
Request body
| Field | Type | Req | Description |
|---|---|---|---|
amount | number | REQ | Positive; minimums may apply. |
email | string | REQ | Customer email used by Lipabiz. |
full_name | string | REQ | Customer name used by Lipabiz. |
curl -X POST https://api.taxpoa.com/v1/tenants/11111111-.../wallet/topup \ -H "Authorization: Bearer $JWT" \ -H "Content-Type: application/json" \ -d '{"amount":2000,"email":"[email protected]","full_name":"Jane Doe"}'
Response 201
{
"payment_url": "https://pay.lipabiz.com/pay_gate?..."
}GET /v1/wallet/ledger?tenant={tenantID} Wallet ledger
Chronological list of credits and debits, newest first.
Query
| Param | Type | Req | Description |
|---|---|---|---|
tenant | uuid | REQ | The tenant whose ledger to fetch (must be yours). |
curl "https://api.taxpoa.com/v1/wallet/ledger?tenant=11111111-..." \
-H "Authorization: Bearer $JWT"Response 200
{
"data": [
{
"id": "...",
"reason": "TOPUP",
"delta": 2000.00,
"balance_after": 7000.00,
"reference": "TAXPOA-...",
"created_at": "2025-01-01T00:00:00Z"
},
{
"id": "...",
"reason": "BILLABLE_OPERATION",
"delta": -0.30,
"balance_after": 4999.70,
"reference": "op:55555555-...",
"created_at": "2025-01-01T00:00:10Z"
}
]
}API Keys
Server-to-server credentials. Prefer creating them from the console, but they can also be managed here.
GET /v1/tenants/{tenantID}/api-keys List keys
{
"data": [
{
"id": "88888888-...",
"name": "POS integration",
"key_prefix": "tpk_live_3f...",
"secret_prefix": "tps_9a...",
"scopes": ["read","write"],
"mode": "live",
"status": "active",
"last_used_at": "2025-01-01T00:00:00Z",
"created_at": "2025-01-01T00:00:00Z"
}
]
}POST /v1/tenants/{tenantID}/api-keys Create key
Request body
| Field | Type | Req | Description |
|---|---|---|---|
name | string | REQ | 1–100 chars label. |
mode | string | REQ | live · test. |
curl -X POST https://api.taxpoa.com/v1/tenants/11111111-.../api-keys \ -H "Authorization: Bearer $JWT" \ -H "Content-Type: application/json" \ -d '{"name":"POS integration","mode":"live"}'
Response 201
{
"id": "88888888-...",
"name": "POS integration",
"api_key": "tpk_live_...",
"api_secret": "tps_...",
"mode": "live",
"status": "active",
"created_at": "2025-01-01T00:00:00Z"
}GET /v1/tenants/{tenantID}/api-keys/{keyID}/reveal Reveal key
{
"id": "88888888-...",
"name": "POS integration",
"api_key": "tpk_live_...",
"api_secret": "tps_...",
"mode": "live",
"status": "active"
}GET /v1/tenants/{tenantID}/api-keys/{keyID}/logs Key usage logs
Last 200 API-key-authenticated requests for a single key.
{
"data": [
{
"id": "...",
"method": "POST",
"path": "/v1/tenants/11111111-.../invoices",
"status_code": 201,
"latency_ms": 42,
"ip": "203.0.113.4",
"user_agent": "curl/8.4",
"error_code": null,
"created_at": "2025-01-01T00:00:00Z"
}
]
}DELETE /v1/tenants/{tenantID}/api-keys/{keyID} Delete key
curl -X DELETE https://api.taxpoa.com/v1/tenants/11111111-.../api-keys/88888888-... \
-H "Authorization: Bearer $JWT"Response 200
{ "status": "deleted" }Developer
Operational endpoints for diagnostics and analytics.
GET /v1/tenants/{tenantID}/logs API logs
Every authenticated request for the tenant, newest first. Same shape as per-key logs, without user_agent.
{
"data": [
{
"id": "...",
"method": "POST",
"path": "/v1/tenants/11111111-.../invoices",
"status_code": 201,
"latency_ms": 42,
"created_at": "2025-01-01T00:00:00Z"
}
]
}GET /v1/tenants/{tenantID}/analytics?days=14 Analytics
Aggregated usage: daily volume, totals, per-operation success/failure, latency percentiles, and total billed.
Query
| Param | Type | Req | Description |
|---|---|---|---|
days | int | OPT | 1–90. Default 14. |
{
"period_days": 14,
"generated_at": "2025-01-01T00:00:00Z",
"totals": {
"invoices": 120,
"success": 110,
"failed": 6,
"pending": 4,
"success_rate": 91.67,
"revenue": 180000.00,
"tax": 24000.00,
"billed": 33.00
},
"daily": [
{ "date":"2024-12-18", "success":9, "failed":0, "pending":1, "total":10 }
],
"operations": [
{ "type":"invoices", "count":120, "success":110, "failed":6 }
],
"latency_ms": { "p50":42, "p95":180, "p99":320, "avg":64.2 }
}GET /healthz Health
Public. Returns { "status": "ok" } when the database is reachable.
curl https://api.taxpoa.com/healthz
Response 200
{ "status": "ok" }