Error Codes
Quickly identify and resolve API request failures.
Overview
The parcelLab API uses standard HTTP status codes to indicate whether a request was successful or not. In case of an error, the response body will contain details of the error in a JSON object with the following structure.
{
"type": "client_error",
"errors": [
{
"code": "error_code",
"detail": "Error message.",
"attr": "Optional additional information."
}
]
}
HTTP Status Codes
When you make an API call, receiving a 2xx response (for example: 200 OK) would indicate that the client’s request was successfully received, understood, and processed by the server.
For a failed API request, error codes are categorized into different groups to indicate specific issues encountered during the request process:
4xx client errors - these codes indicate issues with the client's request (for example: incorrect parameters or unauthorized access)
5xx server errors - these codes indicate that the server failed to process the request
Error Code Examples
Some example error codes are described in the following sections.
401 Unauthorized
These errors are returned with the status code 401 whenever the authentication fails or a request is made to an endpoint without providing the authentication information as part of the request. Here are the two possible errors that can be returned.
{
"type": "client_error",
"errors": [
{
"code": "authentication_failed",
"detail": "Incorrect authentication credentials.",
"attr": null
}
]
}
{
"type": "client_error",
"errors": [
{
"code": "not_authenticated",
"detail": "Authentication credentials were not provided.",
"attr": null
}
]
}
405 Method Not Allowed
This is returned when an endpoint is called with an unexpected http method (for example: if updating a user requires a POST request and a PATCH is issued instead) this error is returned. Here's how the response would look.
{
"type": "client_error",
"errors": [
{
"code": "method_not_allowed",
"detail": "Method “patch” not allowed.",
"attr": null
}
]
}
406 Not Acceptable
This is returned if the Accept
header is submitted and contains a value other than application/json
. Here's how the response would look.
{
"type": "client_error",
"errors": [
{
"code": "not_acceptable",
"detail": "Could not satisfy the request Accept header.",
"attr": null
}
]
}
415 Unsupported Media Type
This is returned when the request content type is not JSON. Here's how the response would look.
{
"type": "client_error",
"errors": [
{
"code": "not_acceptable",
"detail": "Unsupported media type “application/xml” in request.",
"attr": null
}
]
}
500 Internal Server Error
This is returned when the API server encounters an unexpected error. Here's how the response would look.
{
"type": "server_error",
"errors": [
{
"code": "error",
"detail": "A server error occurred.",
"attr": null
}
]
}
Was this helpful?