Skip to main content

API Design Reference

Related docs: Payment Architecture · Data Models · Security Compliance · Microservices


1. Conventions

ConventionValue
Base path/api/v1/
Data formatapplication/json
AuthenticationAuthorization: Bearer <accessToken>
Gateway headersx-pakashop-key (external) or x-internal-key (internal)
Error format{ "success": false, "error": "...", "code": "...", "message": "...", "details": {} }
Success format{ "success": true, "data": { ... } } or top-level object
CurrencyZMW; represented as number (decimal), displayed as K xxx.xx
DatesISO 8601 strings (2026-05-12T10:00:00.000Z)
Rate limit headersX-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset

1.1 Centralised Error Codes

All errors use codes from shared/constants/errors.js:

const ErrorCodes = {
// Authentication
AUTH_001: { status: 401, message: 'Authentication required' },
AUTH_002: { status: 403, message: 'Insufficient permissions' },
AUTH_003: { status: 401, message: 'Invalid internal API key' },
MFA_001: { status: 403, message: 'Multi-factor authentication required' },
MFA_002: { status: 400, message: 'Invalid MFA code' },

// Validation
VAL_001: { status: 400, message: 'Validation error' },
VAL_002: { status: 400, message: 'Invalid phone number format' },

// Orders
ORDER_001: { status: 404, message: 'Order not found' },
ORDER_002: { status: 409, message: 'Order cannot be cancelled' },

// Payments
PAY_001: { status: 400, message: 'Payment processing failed' },
PAY_002: { status: 409, message: 'Duplicate payment attempt' },
PAY_003: { status: 402, message: 'Payment required' },

// Fraud
FRAUD_001: { status: 403, message: 'Transaction blocked by fraud detection' },

// Rate Limiting
RATE_001: { status: 429, message: 'Too many requests' },

// Generic
NOT_FOUND: { status: 404, message: 'Resource not found' },
INTERNAL: { status: 500, message: 'Internal server error' },
};

2. Authentication Endpoints

MethodPathAuthDescription
POST/auth/registerNoneRegister with email + password
POST/auth/loginNoneLogin; returns accessToken + refreshToken
POST/auth/logoutRequiredInvalidate current session
POST/auth/refreshNoneExchange refreshToken for new accessToken
POST/auth/request-magic-linkNoneSend magic link to email
POST/auth/verify-magic-linkNoneVerify magic link token
POST/auth/request-password-resetNoneSend password reset email
POST/auth/reset-passwordNoneComplete password reset
POST/auth/verify-emailNoneVerify email with token
GET/auth/meRequiredGet authenticated user profile
GET/oauth/:providerNoneInitiate OAuth flow
GET/oauth/:provider/callbackNoneOAuth callback

2.1 MFA Endpoints

MethodPathAuthDescription
POST/auth/mfa/setupRequiredBegin MFA enrollment
POST/auth/mfa/verify-setupRequiredVerify MFA setup code
POST/auth/mfa/challengePartial (mfa_login token)Request MFA challenge
POST/auth/mfa/verify-loginPartial (mfa_login token)Verify MFA code and complete login
DELETE/auth/mfa/disableRequired + MFADisable MFA (requires verification)

3. Product Endpoints

MethodPathAuthDescription
GET/productsNoneList products with filters
GET/products/:idNoneSingle product with variants
GET/products/recommendationsOptionalPersonalised or popular products
GET/products/:productId/optionsNoneProduct option groups
GET/products/:productId/variantsNoneProduct variants
GET/products/:productId/wholesale-tiersNoneWholesale pricing tiers

Query params for /products: category, search, minPrice, maxPrice, sort, page, limit, featured, shopId, pricingModel.


4. Shop Endpoints

MethodPathAuthDescription
GET/shopsNoneList approved shops
GET/shops/searchNoneFull-text shop search
GET/shops/slug/:slugNoneShop by slug
POST/shops/requestRequiredRequest new shop (legacy flow)
GET/shops/my-shopsRequiredAuthenticated user's shops
GET/shops/:shopId/statsRequiredShop analytics
POST/shops/:shopId/productsRequiredCreate product in shop
GET/shops/:shopId/productsRequiredList shop's own products
PUT/shops/:shopId/products/:idRequiredUpdate product
DELETE/shops/:shopId/products/:idRequiredSoft-delete product
GET/shops/:shopId/inventoryRequiredView inventory
POST/shops/:shopId/inventory/adjustRequiredAdjust stock
GET/shops/:shopId/settlementsRequiredView settlement history

5. Order Endpoints

MethodPathAuthDescription
POST/ordersRequiredCreate order
GET/orders/myRequiredAuthenticated user's orders
GET/orders/:idRequiredSingle order details
PATCH/orders/:id/cancelRequiredCancel order
GET/orders/:id/trackingRequiredGet delivery tracking snapshot
GET/orders/:id/receiptRequiredGenerate PDF receipt

POST /orders request body:

{
"items": [
{
"productId": "uuid",
"shopId": "uuid",
"quantity": 2,
"price": 125.00,
"variantId": "uuid"
}
],
"shippingAddress": {
"firstName": "John",
"lastName": "Banda",
"email": "john@example.zm",
"phone": "0977123456",
"address": "Plot 123, Cairo Road",
"city": "Lusaka",
"province": "Lusaka",
"country": "Zambia"
},
"paymentMethod": "MTN_MONEY",
"couponCode": "SUMMER2026",
"loyaltyPointsToRedeem": 500,
"total": 250.00
}

6. Payment Endpoints

MethodPathAuthDescription
POST/payments/initiateRequiredInitiate payment for an order
GET/payments/status/:orderIdRequiredGet payment + settlement status
POST/payments/webhook/:providerNoneReceive gateway webhooks
POST/payments/release/:orderIdAdminManually release vendor funds
POST/payments/refund/:orderIdAdminProcess refund

POST /payments/initiate

Request:

{
"orderId": "uuid",
"paymentMethod": "MTN" | "AIRTEL" | "ZAMTEL" | "CARD",
"phoneNumber": "0977123456"
}

Response — mobile money:

{
"success": true,
"data": {
"transactionId": "pawa-debit-abc123",
"provider": "PAWAPAY",
"type": "ussd",
"message": "A payment request has been sent to 0977123456. Please enter your PIN."
}
}

Response — card:

{
"success": true,
"data": {
"redirectUrl": "https://checkout.flutterwave.com/v3/hosted/pay/...",
"provider": "FLUTTERWAVE",
"type": "redirect"
}
}

GET /payments/status/:orderId

Response:

{
"success": true,
"data": {
"settlement": { "settlementStatus": "HELD" },
"payments": [
{
"id": "uuid",
"gateway": "PAWAPAY",
"status": "CAPTURED",
"amount": 250.00,
"currency": "ZMW",
"createdAt": "2026-05-12T10:00:00Z"
}
],
"fraudCheck": {
"score": 12,
"status": "PASSED"
}
}
}

Frontend maps status === 'CAPTURED'paymentStatus = 'PAID'.


7. Notification Endpoints

MethodPathAuthDescription
GET/notificationsRequiredList user's notifications
PATCH/notifications/:id/readRequiredMark as read
PATCH/notifications/read-allRequiredMark all as read
GET/notifications/preferencesRequiredGet user preferences
PUT/notifications/preferencesRequiredUpdate preferences
GET/notifications/streamRequiredSSE real-time notification stream

8. Seller Application Endpoints

MethodPathAuthDescription
POST/seller-applicationsRequiredCreate application draft
GET/seller-applications/my-applicationRequiredGet own application
PUT/seller-applications/:id/phase/:phaseRequiredUpdate a phase
POST/seller-applications/:id/documentsRequiredUpload KYC documents
POST/seller-applications/:id/submitRequiredSubmit for review
GET/seller-applicationsAdminList all applications
PUT/seller-applications/:id/statusAdminUpdate application status
POST/seller-applications/:id/approveAdminApprove; create shop

9. Delivery Endpoints

9.1 Agent Operations

MethodPathAuthDescription
POST/delivery/applyRequiredSubmit delivery agent application
GET/delivery/agent/meRequiredGet current agent profile
PATCH/delivery/agent/availabilityRequiredToggle availability
GET/delivery/agent/deliveriesRequiredGet assigned deliveries
POST/delivery/agent/confirmRequiredPIN-based delivery confirmation (Tier 1)
POST/delivery/signature/:id/captureRequiredDigital signature capture (Tier 2)

9.2 Courier Company Operations

MethodPathAuthDescription
GET/delivery/courier/agentsRequired (FLEET_MANAGER)List sub-agents
POST/delivery/courier/agentsRequired (FLEET_MANAGER)Add sub-agent
DELETE/delivery/courier/agents/:idRequired (FLEET_MANAGER)Remove sub-agent

9.3 Admin Operations

MethodPathAuthDescription
GET/delivery/admin/applicationsAdminList pending applications
GET/delivery/admin/agentsAdminList all verified agents
PATCH/delivery/admin/agents/:id/approveAdminApprove application
PATCH/delivery/admin/agents/:id/rejectAdminReject with reason
PATCH/delivery/admin/agents/:id/suspendAdminSuspend agent
PATCH/delivery/admin/agents/:id/activateAdminRe-activate agent

10. Tracking Endpoints

MethodPathAuthDescription
POST/tracking/locationRequired (DELIVERY_AGENT)Post GPS location
GET/tracking/:orderId/currentRequiredGet tracking snapshot
GET/tracking/:orderId/historyRequiredGet event timeline
GET/tracking/:orderId/etaRequiredGet/recalculate ETA
GET/tracking/admin/activeAdminAll active deliveries
WS/tracking/wsRequiredWebSocket connection for live tracking

11. Coupon Endpoints

MethodPathAuthDescription
POST/couponsRequired (SHOP_OWNER)Create coupon
GET/couponsNoneList available coupons
GET/coupons/:idNoneGet coupon details
PUT/coupons/:idRequired (SHOP_OWNER)Update coupon
DELETE/coupons/:idRequired (SHOP_OWNER)Deactivate coupon
POST/coupons/:id/validateRequiredValidate coupon for cart

12. Loyalty Endpoints

MethodPathAuthDescription
GET/loyalty/pointsRequiredGet current points balance
GET/loyalty/historyRequiredGet points transaction history
POST/loyalty/redeemRequiredRedeem points for discount
GET/loyalty/shop/:shopIdRequiredGet shop-specific loyalty program

13. Fraud Endpoints

MethodPathAuthDescription
GET/fraud/queueRequired (FRAUD_ANALYST, PLATFORM_ADMIN)List pending reviews
POST/fraud/queue/:id/approveRequired (FRAUD_ANALYST, PLATFORM_ADMIN)Approve blocked transaction
POST/fraud/queue/:id/rejectRequired (FRAUD_ANALYST, PLATFORM_ADMIN)Reject blocked transaction
GET/fraud/rulesRequired (PLATFORM_ADMIN)List fraud rules
PUT/fraud/rules/:idRequired (PLATFORM_ADMIN)Update fraud rule

14. Admin Endpoints

MethodPathAuthDescription
GET/admin/usersAdminList all users
PATCH/admin/users/:id/roleAdminUpdate user role
GET/admin/analyticsAdminPlatform-wide analytics
GET/admin/reconciliationAdminFinancial reconciliation report
POST/admin/broadcastAdminSend broadcast notification
GET/admin/feature-flagsAdminList feature flags
PUT/admin/feature-flags/:keyAdminToggle feature flag
GET/admin/moderation/flagsAdmin, MODERATORList flagged content
POST/admin/moderation/flags/:id/approveAdmin, MODERATORApprove flagged content
POST/admin/moderation/flags/:id/rejectAdmin, MODERATORReject flagged content
GET/admin/zra/transmissionsAdmin, FINANCE_ADMINZRA transmission log
POST/admin/zra/retransmit/:idAdmin, FINANCE_ADMINRetry failed ZRA transmission

15. Error Response Format

All errors return a consistent shape:

{
"success": false,
"error": "ORDER_NOT_FOUND",
"code": "ORDER_001",
"message": "Order not found",
"details": {
"orderId": "ord_123",
"suggestion": "Check the order ID and try again"
}
}
HTTP StatusMeaning
400Bad request / validation error
401Unauthenticated
402Payment required
403Unauthorised (wrong role or MFA not verified)
404Resource not found
409Conflict (e.g., duplicate order)
429Rate limit exceeded
500Internal server error

For internal use only. Do not distribute outside Pakashop engineering.