Skip to main content

Errors

Moyasar uses conventional HTTP response codes to indicate the success or failure of an API request.

tip

 In general, codes in the 2xx range indicate success, codes in the 4xx range indicate an error that failed because of the information provided (e.g., a required parameter was omitted, a charge failed, etc.), and codes in the 5xx range indicate an error with Moyasar’s servers (these should be rare).

Not all errors map cleanly onto HTTP response codes, however. When a request is valid but does not complete successfully (e.g., a credit card is declined by the bank), we return the normal 201 success code with a response message detailing the error.

HTTP status code

The Moyasar API uses the following error codes:

Error CodeMeaning
200OK – Everything worked as expected
400Bad Request – The request was unacceptable, often due to missing a required parameter
401Unauthorized – No valid API key was provided
403Forbidden – credentials not enough to access resources
404Not Found – The requested resource doesn’t exist
405Method Not Allowed – Entity not activated to use live account
429Too Many Requests – Too many requests hit the API too quickly.
500Internal Server Error – We had a problem with our server. Try again later.
503Service Unavailable – We are temporarily offline for maintenance. Please try again later.

Moyasar Errors

Invalid API Key Authentication Error

HTTP/1.1 401
Unauthorized

{ "type": "authentication_error",
"message": "Invalid authorization credentials",
"errors": null
}

Credit Card Payment Validation Error

You will receive an error response from API in case something went wrong.

HTTP/1.1 400
Bad Request

{
"type": "invalid_request_error",
"message": "Validation Failed",
"errors": { "amount" : ["must be an integer"] }
}

Each error response will contain a message attribute describing the reason shortly. For some error types, there might be a detailed errors attribute that lists and details more information.

The following table summarizes each error type returned from API:

TypeMeaning
invalid_request_errorThe request included invalid parameters.
authentication_errorYou didn't authenticate yourself correctly, check our guide on Authentication
rate_limit_errorToo many requests hit the API too quickly.
api_connection_errorFailure to connect to Moyasar’s API.
account_inactive_errorYour Account hasn't been activated to accept real payments, contact our sales team for more information.
api_errorAPI errors cover any other type of problem (e.g. resource is not found). API errors should be rare.
3ds_auth_errorThe credit card payment transaction failed due unauthorized attempt by the cardholder.