Authentication
Exchange your API key for an access token, and send the token on every call.
You use two credentials:
- Your API key, which you create in the dashboard and send to the token endpoints only.
- An access token, which you send on every other call. It lasts five minutes.
A test key (fpk_test_…) gives a token that reaches test mode only. A live key (fpk_live_…) gives a token for live mode.
See Test mode.
Get an access token
Send the whole key in the X-Api-Key header, with grant_type=client_credentials in a form body, to
Create an access token:
curl -X POST "https://api-malipo.flex.co.tz/api/v1/oauth/token" \
-H "X-Api-Key: fpk_test_your_key" \
-d grant_type=client_credentials{
"access_token": "eyJraWQiOiJmbGV4cGF5LTEiLCJhbGciOiJSUzI1NiJ9...",
"token_type": "Bearer",
"expires_in": 300,
"scope": "payments.read payments.write"
}Then send the token on every other call:
Authorization: Bearer eyJraWQiOiJmbGV4cGF5LTEiLCJhbGciOiJSUzI1NiJ9...Reuse a token until shortly before expires_in runs out, then get a new one. Getting a token counts against your
rate limit. To stop a token working before it expires, revoke it with
Revoke an access token.
Scopes
Give each key only the scopes its system needs. A token has all of its key's scopes unless you ask for fewer with the
scope parameter, a list separated by spaces.
| Scope | Lets the key |
|---|---|
payments.read | Retrieve and list payments, preview fees, read the balance, list payment methods and payment records, list and retrieve webhook endpoints, and read email settings and previews. |
payments.write | Create payments, switch payment methods on or off, manage webhook endpoints, and change email settings. |
payouts.write | Create payouts. A payout also needs payments.write. |
refunds.write | Create refunds. Reading refunds needs payments.read. |
checkout.read | Retrieve and list checkout sessions. |
checkout.write | Create and expire checkout sessions. |
billing.read | Read customers, customer credit, products, prices, subscriptions, invoices and their receipts, credit notes, meters and settings. |
billing.write | Create and change those objects, record meter events, record payments on invoices and withdraw invoices, and grant credit. |
A call without the scope it needs is refused with 403 and the code permission_denied. A scope value that the key
does not hold is refused with 400 and invalid_scope.
Keeping keys safe
- Keep keys on your server. Never put one in a mobile app, a web page or a repository. Browsers cannot call the API: call it from your server.
- Use one key for each of your systems, such as your web shop and your point of sale, each with only the scopes it needs. Tag payments with metadata to tell your channels apart.
- Restrict a key to your servers' IP addresses. From any other address, getting a token fails with
401, and a call with a token fails with403. - Rotate a key if it may have leaked, and revoke a key you no longer use.
When authentication fails
Getting a token fails with 401 and invalid_client when the key is missing, wrong, disabled, revoked or expired, when
you call from outside the key's allowed addresses, or when you use a live key before your merchant is verified. These
errors use the OAuth 2.0 shape of RFC 6749: error is one of invalid_request, invalid_client, invalid_scope or
unsupported_grant_type, with an error_description.
{
"error": "invalid_client",
"error_description": "Client authentication failed"
}Every other call fails with 401 when the token is missing, expired or revoked, with the usual error body
and the code authentication_required. Every such 401 carries the header WWW-Authenticate: Bearer realm="Flex Malipo".
A 403 does not. Get a new token and retry.