API key authentication (X-API-KEY)
Every call to the Senfenico API authenticates with a secret key sent in the X-API-KEY header.
The X-API-KEY header
Section titled “The X-API-KEY header”X-API-KEY: sk_test_...The header is named X-API-KEY, not Authorization. An Authorization: Bearer … header is ignored, and a request that sends only that header is refused.
Test key and live key
Section titled “Test key and live key”| Prefix | Mode | Real money | IP restriction |
|---|---|---|---|
sk_test_ |
Test | No, everything is simulated | Never |
sk_live_ |
Live | Yes | If you set up an IP allowlist |
There is no mode parameter: the key prefix selects the mode. Every object returned carries a live_mode field (false in test, true in live).
Test and live objects are separate
Section titled “Test and live objects are separate”A payment created with the test key doesn’t exist for the live key, and vice versa. Fetching a test reference with the live key returns 404. If you get an unexpected 404, first check that you are using the right key.
Where to find and regenerate your keys
Section titled “Where to find and regenerate your keys”Your keys are in the dashboard, under Developer › API keys (/user_dashboard/api_keys/).
- Senfenico only stores a fingerprint of your keys, so a key is shown only once, when you generate it. Copy it straight into your secrets manager.
- Generating a new key immediately invalidates the old one. Plan to update your servers right after.
- The live key button only produces a key once your account is verified (see going live). Until then, it shows nothing.
If a key has leaked, regenerate it right away. For the live key, also add an IP allowlist. A stolen key then becomes useless anywhere but on your servers.
Your first authenticated call
Section titled “Your first authenticated call”Reading the balance is a good first call, because it creates nothing.
curl https://api.senfenico.com/v1/payment/balances/ \ -H "X-API-KEY: $SENFENICO_KEY"$ch = curl_init('https://api.senfenico.com/v1/payment/balances/');curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'X-API-KEY: ' . getenv('SENFENICO_KEY'), ],]);$body = json_decode(curl_exec($ch), true);$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);curl_close($ch);import osimport requests
res = requests.get( "https://api.senfenico.com/v1/payment/balances/", headers={"X-API-KEY": os.environ["SENFENICO_KEY"]}, timeout=30,)body = res.json()const res = await fetch( 'https://api.senfenico.com/v1/payment/balances/', { headers: { 'X-API-KEY': process.env.SENFENICO_KEY } },);const body = await res.json();Response (shortened):
{ "status": true, "message": "Balance retrieved", "data": { "deposit_balances": { "bf": { "available": "…", "currency": "XOF" } }, "transfer_balances": { "orange_money_bf": { "available": "…" } } }}Response format
Section titled “Response format”Every response is JSON, with the same envelope. On success, it contains these fields:
| Field | Type | Description |
|---|---|---|
status |
boolean | true |
message |
string | Human-readable message, in English |
data |
object or list | The result |
pagination |
object | Lists only (10 items per page, 50 for refunds, ?page=) |
On error, it contains these fields:
| Field | Type | Description |
|---|---|---|
status |
boolean | false |
message |
string | Human-readable explanation, for your logs |
error_code |
string | Stable code to branch on in your code, for example INVALID_DATA. Missing on some errors |
errors |
object | Per-field details, on validation errors |
{ "status": false, "message": "Invalid data provided. Please check the input and try again.", "error_code": "INVALID_DATA", "errors": { "amount": ["Ensure this value is greater than or equal to 100."] }}The full list of codes is in the error reference.
HTTP status codes to expect
Section titled “HTTP status codes to expect”| Code | Meaning |
|---|---|
200 |
Request processed. Read status: some operations (charge initialization, OTP submission) return 200 with status: false |
201 |
Object created, for example a charge or a transfer |
202 |
Transfer batch accepted for processing |
400 |
Invalid data (INVALID_DATA, see errors) |
403 |
Missing or invalid key, IP not allowed or insufficient balance. Read message and error_code |
404 |
Object not found, or created in the other mode |
429 |
Too many requests. Try again later |
500 |
Internal error. Before retrying, check that the operation was not created (see Reconciliation) |
Always check the HTTP code and the status field, in that order.
Missing or invalid key
Section titled “Missing or invalid key”Without an X-API-KEY header, or with an unknown key (revoked, mistyped), the API returns 403:
{ "status": "False", "message": "Invalid API Key." }Without the header, the message is No API key provided.
# -w prints the HTTP code after the bodycurl -s -w "\nHTTP %{http_code}\n" \ https://api.senfenico.com/v1/payment/balances/ \ -H "X-API-KEY: $SENFENICO_KEY"$ok = $http >= 200 && $http < 300 && ($body['status'] ?? null) === true;if (!$ok) { error_log("Senfenico $http: " . ($body['message'] ?? ''));}ok = res.ok and body.get("status") is Trueif not ok: print("Senfenico", res.status_code, body.get("message"))const ok = res.ok && body.status === true;if (!ok) { console.error('Senfenico', res.status, body.message);}