Errors

The API reports a failure through the HTTP status code. Most error responses carry a JSON body with the structure below; 401, 403 and 429 do not.

Error body

FieldDescriptionType
statusThe HTTP status code of the responseInteger
errorThe error code, listed under Status codesString
messagesOne or more entries describing the errorArray

Each entry in messages has:

FieldDescriptionType
messageA description of the error, in Brazilian PortugueseString
attributeThe parameter, field or rule that caused the error. Absent on record_not_found and standard_errorString
modelThe type of resource that was not found, e.g. Order. Only on record_not_found, and not always presentString
extraContext about the operation that failed. Only on unprocessable_action; an object or an array, depending on the operationObject or Array

message is written for people. To handle an error in code, use error and attribute.

Status codes

StatuserrorMeaning
400 Bad Requestparameter_missingA required parameter is missing. attribute names it
400 Bad Requestunprocessable_actionA business rule rejected the request. attribute names the rule
401 Unauthorized—The token is missing, invalid or disabled. The body is an empty JSON object, {}. See Authentication
403 Forbidden—Requests from your IP address are blocked. The body is the plain text Forbidden. Contact support
404 Not Foundrecord_not_foundThe resource does not exist, or your token cannot access it
422 Unprocessable Contentrecord_invalidThe data failed validation. messages has one entry per failed validation, so a field can appear more than once
422 Unprocessable Contentunprocessable_actionA business rule rejected the request. A few rules answer 422 instead of 400, e.g. enabling an offer that is already enabled
429 Too Many Requests—A rate limit was exceeded. The body is empty. See Rate Limits
500 Internal Server Errorstandard_errorAn unexpected server error. Contact support

Examples

parameter_missing

POST /external_api/v1/orders without offer_id:

{
    "status": 400,
    "error": "parameter_missing",
    "messages": [
        {
            "attribute": "offer_id",
            "message": "Parâmetro obrigatório ausente ou inválido."
        }
    ]
}

unprocessable_action

POST /external_api/v1/orders without the signature object:

{
    "status": 400,
    "error": "unprocessable_action",
    "messages": [
        {
            "attribute": "signature",
            "message": "O objeto signature é obrigatório e deve conter remote_ip e user_agent.",
            "extra": {
                "offer_id": "8dd4fffd-e1b3-503f-a7f2-963c6d32c0cd",
                "controller": "external_api/v1/orders",
                "action": "create"
            }
        }
    ]
}

Unauthorized

A request without a valid token:

{}

record_not_found

GET /external_api/v1/orders/:id with an ID that does not exist:

{
    "status": 404,
    "error": "record_not_found",
    "messages": [
        {
            "message": "Não foi possível encontrar um registro com os parâmetros enviados.",
            "model": "Order"
        }
    ]
}

record_invalid

POST /external_api/v1/webhooks with a url that is not https:

{
    "status": 422,
    "error": "record_invalid",
    "messages": [
        {
            "attribute": "url",
            "message": "Url não é uma URL válida"
        }
    ]
}

standard_error

{
    "status": 500,
    "error": "standard_error",
    "messages": [
        {
            "message": "Ocorreu um erro inesperado. Tente novamente mais tarde."
        }
    ]
}