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 the payment status set to failed and the reason in source.message and source.response_code. See Payment Errors and Response Codes.

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
}

Validation Error​

Most endpoints, including POST /v1/payments, validate request parameters before doing anything else and return a validation_error when they fail:

HTTP/1.1 400
Bad Request

{
"type": "validation_error",
"message": "Data validation failed",
"errors": { "amount": ["The value must be an integer."] }
}

Some validations are reported as invalid_request_error instead:

HTTP/1.1 400
Bad Request

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

Record Not Found Error​

HTTP/1.1 404
Not Found

{
"type": "record_not_found",
"message": "The Payment record you were looking for was not found",
"errors": null
}

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 the main error types returned from API. Some endpoints also return a more specific type for a business rule that failed (for example invalid_request or used_given_id), with a message explaining it. Handle any type not listed here using the HTTP status code:

TypeMeaning
validation_errorThe request included invalid or missing parameters. See errors for each field.
invalid_request_errorThe request included invalid parameters.
authentication_errorYou didn't authenticate yourself correctly, check our guide on Authentication
record_not_foundThe requested resource doesn't exist.
rate_limit_errorToo many requests hit the API too quickly.
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. API errors should be rare.

A declined or failed payment is not an API error: the request returns 201 with the payment status set to failed. See Payment Errors.