Errors
Tell a failed request from a failed payment, and what to do about each.
Check the HTTP status of every response: 2xx means it worked, 4xx means you have to change the request, and 5xx
means the problem is on our side.
The error body
Every error has this body, whatever endpoint it comes from:
{
"error": {
"type": "invalid_request_error",
"code": "resource_missing",
"message": "Payment not found",
"param": "id",
"requestId": "req_4f1c2a9e8b7d4c3a9f0e1d2c3b4a5f6e"
}
}| Field | Meaning |
|---|---|
type | The group of the error. Read it first. |
code | A lower_snake code. Branch on this field. |
message | What happened and what to do. Log it or show it to your team, but do not branch on it, since messages can be reworded. |
param | The request field at fault, such as amount or Idempotency-Key. Absent when no field is at fault. |
requestId | The call's request ID. |
The HTTP status is the only status. The body does not repeat it.
The OAuth endpoints, /api/v1/oauth/token and /api/v1/oauth/revoke, answer in the OAuth 2.0 shape of RFC 6749
instead. Their errors have an error string such as invalid_client, and an error_description. See
Authentication.
Types
type | When |
|---|---|
invalid_request_error | Something is wrong with the request or with the state it targets: 400, 401, 403, 404, 409 and 422. |
idempotency_error | An Idempotency-Key was reused for another request, or the first request with it is still running. |
rate_limit_error | You sent too many requests: 429. |
api_error | The failure is on our side: 500, 502, 503 and 504. |
Request IDs
Log the Request-Id response header, such as req_4f1c2a9e8b7d4c3a9f0e1d2c3b4a5f6e. It is the same value as requestId
in the body. Quote it when you contact support, so the call can be found.
Authentication errors
Every 401 carries a WWW-Authenticate: Bearer realm="Flex Malipo" header next to the error body, with the code
authentication_required. A 403 does not carry that header. It answers with the code permission_denied.
Status codes
| Code | Meaning | What to do |
|---|---|---|
200, 201, 202, 204 | It worked. 202 means the outcome comes later. | |
400 | The request is invalid: a missing or malformed field, or a value the API does not accept. | Fix the request. Do not retry it unchanged. |
401 | The access token is missing, expired or revoked. | Get a new token and retry. |
403 | The token lacks the scope the call needs, the call is not available to you, or your key may not be used from this address. | Check the key's scopes and allowed addresses. |
404 | You have no resource with this ID, or there is nothing at this path. | Check the ID and the path. |
405, 406, 415 | The method is not allowed on the path, you ask for a format other than JSON, or the body is not JSON. | Fix the request. |
409 | The request conflicts with the state of a resource, or an earlier request with the same Idempotency-Key is still running. | For idempotency_request_in_progress, retry with the same Idempotency-Key after a short wait. For any other code, do not retry: read the resource, then decide. |
422 | The request is valid but cannot be done, such as a payment to a network you switched off. | Change what you ask for. |
429 | You sent too many requests. | Wait the seconds in Retry-After, then retry. See Rate limits. |
500, 502, 504 | The request did not complete. | Retry with the same Idempotency-Key. |
503 | The service cannot answer right now. | Retry only when the response has a Retry-After header, after that many seconds. Without it, do not retry. |
Retry a write only with the same Idempotency-Key. See Idempotency. Wait longer after each
retry, for example 1 second, then 2, then 4, and stop after 2 retries.
Codes you may meet
Every error has a code. The generic ones come from any endpoint.
| Code | Status | Meaning |
|---|---|---|
parameter_invalid | 400 | A field is missing, has the wrong type or format, or breaks a limit. param names the first field at fault, and message lists every one. |
parameter_missing | 400 | A required query parameter or header is missing. |
amount_invalid | 400 | An amount is not an integer in the currency's minor unit. See Money. |
api_version_invalid | 400 | The version you sent is not one this API serves. See Versioning. |
resource_already_exists | 400 | Another object already has this value of a field that must be unique, such as a customer's externalId or a price's lookupKey. param names the field, and message names the object that has it. |
authentication_required | 401 | The token is missing, invalid or expired. |
permission_denied | 403 | The credential cannot do this. |
resource_missing | 404 | There is no such resource, or nothing at this path. |
method_not_allowed | 405 | The method is not allowed on this path. |
not_acceptable | 406 | The API answers in application/json only. |
media_type_unsupported | 415 | Send the body as application/json. |
conflict | 409 | The request conflicts with the state of a resource, with no more specific code. |
request_not_allowed | 422 | The request is valid but cannot be done, with no more specific code. |
rate_limited | 429 | You sent too many requests. |
service_unavailable | 503 | The service cannot answer right now. Retry-After is present when a retry is safe. |
upstream_failed | 502 | A service Flex Malipo depends on failed. |
upstream_timeout | 504 | The service took too long to answer. |
internal_error | 500 | Something went wrong on our side. |
These codes belong to one area.
| Code | Status | Meaning |
|---|---|---|
account_not_verified | 403 | Live mode is off until your business is approved. Test mode is not affected. See Go live. |
idempotency_key_reused | 400 | The Idempotency-Key was already used with a different request. Type idempotency_error. |
idempotency_request_in_progress | 409 | A request with this Idempotency-Key is still running. Type idempotency_error. Retry with the same key after a short wait. |
amount_too_large | 400 | An amount is above the largest the network takes, a refund is more than what is left to refund, or a payment you record is more than what is still to pay on the invoice. limit.maximum shows the largest amount. See Amount limits. |
refund_window_passed | 400 | The payment succeeded more than 1 year ago. |
refund_not_supported | 400 | The payment's network cannot send a refund yet. |
payment_not_refundable | 400 | Only a SUCCEEDED collection can be refunded. |
insufficient_balance | 400 | Your available balance does not cover the refund and its payout fee. |
subscription_exists | 409 | The customer already holds an open subscription the rules do not allow a second to. See One subscription per customer. |
too_many_prompts | 429 | Too many payment requests to one phone number. Retry-After says how long to wait. |
amount_too_small | 400 | An amount is below the smallest the network takes, or a part payment would leave less to pay than the smallest amount a customer can pay. limit.minimum shows the smallest amount. See Amount limits. |
payment_method_unactivated | 422 | The customer's number is on a network you cannot take payments on: it is not available to you, you switched it off, it cannot pay out, or, with a live key, the number is on no network. The message names the networks you can take. See Amount limits. |
invoice_not_open | 409 | The invoice is paid or void, its subscription takes no payment, or it is an invoice for an upgrade that has expired. See Record a payment. |
quote_mismatch | 409 | The quote you sent is not for this subscription and this request. |
quote_expired | 409 | The quote has expired. Request a new preview and send its quoteId. |
invalid_status | 409 | The subscription is in a status that does not allow this change. |
upgrade_pending | 409 | An upgrade is waiting for payment, so the subscription cannot be changed yet. |
payment_in_progress | 409 | A payment on this invoice is still in progress. |
invoice_not_withdrawable | 409 | The invoice cannot be withdrawn. |
period_closed | 409 | The billing period the usage belongs to has closed. |
dimension_limit_exceeded | 422 | A meter event has more dimension values than the meter allows. |
A 503 from Create a payment or from a checkout session carries
Retry-After when the request can be sent again with the same Idempotency-Key.
Payment failures are not errors
A payment the customer declines is not an HTTP error: creating it worked, so you get 201. You learn the outcome later
from a payment.failed webhook, or from the payment's status and failureCode.
failureCode | Why the payment failed |
|---|---|
CUSTOMER_DECLINED | The customer declined on their phone. |
INSUFFICIENT_FUNDS | The customer's wallet did not have enough money. |
INSUFFICIENT_BALANCE | A payout that your available balance could not cover. |
EXPIRED | A collection the customer did not approve within 3 minutes, or a payout that was not sent within 4 hours. The status is EXPIRED. |
Mobile money networks can report other codes. Treat an unknown failureCode as a failure and show failureMessage to your team,
not to the customer.