Errors
Cobrofácil API errors use a consistent JSON response format. Every error response includes a human-readable message, and JSON exception responses also include an exception_code integer. Validation errors include an additional errors object keyed by field name.
Use the HTTP status code to decide how your integration should react, and use the response body to show or log the specific reason.
Error response shape
Most API errors use the same top-level fields. The exact message depends on the exception that occurred.
- Name
message- Type
- string
- Details
- required
- Description
A human-readable description of the error.
- Name
exception_code- Type
- integer
- Details
- required
- Description
The integer exception code returned by the API. When no custom code is set, this value is usually
0.
- Name
errors- Type
- object
- Details
- optional
- Description
Present on validation failures. Each key is a request field and each value is an array of validation messages for that field.
- Name
model- Type
- string
- Details
- optional
- Description
Present on some not found responses when the API can identify the missing resource type.
- Name
ids- Type
- array
- Details
- optional
- Description
Present on some not found responses when the API can identify the missing resource IDs.
Generic error response
{
"message": "Unauthenticated.",
"exception_code": 0
}
Validation errors
When request data is invalid, the API returns 422 Unprocessable Entity.
The errors object contains one entry for each invalid field. Field names
use the same names you sent in the request.
Validation error response
{
"message": "The given data was invalid.",
"errors": {
"first_name": [
"The first name field is required."
],
"phone_number": [
"The phone number field must be a valid phone number."
]
},
"exception_code": 0
}
Not found errors
Missing routes and missing records return 404 Not Found. When a resource
cannot be found, the response may include the resource type and IDs the API
attempted to resolve.
Model not found response
{
"message": "The requested client could not be found.",
"model": "client",
"ids": [
"client-300"
],
"exception_code": 0
}
Status codes
The Cobrofácil API uses standard HTTP status codes. These are the most common responses your integration should handle.
- Name
200- Description
The request succeeded.
- Name
401- Description
The request is not authenticated. Check that your bearer token is present and valid.
- Name
403- Description
The authenticated user or token cannot access the requested resource.
- Name
404- Description
The route or requested resource was not found.
- Name
409- Description
The request conflicts with the current application state.
- Name
422- Description
The request was understood, but one or more fields failed validation.
- Name
429- Description
Too many requests were sent in a short period. Retry after backing off.
- Name
500- Description
An unexpected server error occurred.