Integration Guide
This guide covers best practices for integrating the Afriex Business API into your application.OpenAPI spec
Get the full OpenAPI spec at this endpoint for code generation, SDKs, and API tooling.
MCP server
Add the Afriex Business API to your MCP client and search the docs from Cursor, Claude Code, and other MCP-enabled tools.
Environments
The Afriex API provides two environments:Authentication
All API requests require authentication using your API key in thex-api-key header:
Idempotency
For critical operations like creating transactions, use idempotency keys to prevent duplicate processing:Error Handling
The API uses standard HTTP status codes:Error response format
All error responses follow a consistent structure:Pagination
List endpoints support pagination withpage and limit parameters:
All list endpoints return results in this shape:
total field to calculate the number of pages: Math.ceil(total / limit).
Webhook Integration
Set up webhooks to receive real-time event notifications:- Configure your webhook URL in the Dashboard
- Verify the
x-webhook-signatureheader (RSA-SHA256, base64) using the raw request body - Use the webhook public key from Dashboard -> Developers -> Webhooks (staging and production keys are different)
- Return
200quickly after successful verification and processing
400 or 401. Afriex retries failed deliveries up to 12 times with exponential backoff (starting at 30 seconds).
Webhook Documentation
Learn more about webhook setup, security, and event types.
Rate Limiting
Be mindful of rate limits when making API calls:- Implement exponential backoff for retries
- Cache exchange rates and other static data
- Use webhooks instead of polling for status updates
Testing Your Integration
1
Test in Staging
Use the staging environment to test all API calls without affecting live data.
2
Verify Webhooks
Test webhook handling with the staging environment events.
3
Go Live
Switch to production base URL and API keys when ready.
Testing transaction outcomes in sandbox
In the sandbox/staging environment, transactions reach a final status automatically, usually within 1-2 minutes of creation, so you can build and test your integration end to end. The matchingTRANSACTION.UPDATED webhook is sent when the transaction settles.
You can choose the outcome through the transaction’s meta.reference:
- If
meta.referencecontains the wordfail(case-insensitive), the transaction settles as FAILED. For withdrawals, the amount is returned to your wallet. - Otherwise, the transaction settles as SUCCESS.
Simulating OTP-required deposits
Some deposits (for example, certain mobile-money payments) require the customer to confirm a one-time password (OTP) before they complete. In sandbox you can trigger this flow deterministically through the deposit’smeta.reference:
- Include
SIMULATE_OTPinmeta.referenceto make the deposit return theCUSTOMER_ACTION_REQUIREDstatus, meaning an OTP is needed. - Include
SIMULATE_NO_OTPto make the deposit complete without an OTP step.
123456:
123456 is rejected, so you can test the wrong-OTP path. Once authorized, the deposit settles automatically like any other sandbox transaction (a meta.reference that also contains fail settles as FAILED, otherwise SUCCESS). These values apply to the sandbox/staging environment only; production ignores them.
