# HTTP Status Codes

When an API request results to an error, BACE sends a response with the error details in the body and a corresponding HTTP status code. The response body contains a description of the error and possible causes.

BACE sends the following HTTP status codes in the header:

* [2xx](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#successful_responses) - The request is successful.
* [4xx](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses) - The request failed because of the information in the request, such as values with incorrect format, or not having the required fields.
* [5xx](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) - The request failed because of errors with BACE's servers.

### Error Response fields

|         |                                                                                                                                                                                                  |
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name    | A generic description of the problem.                                                                                                                                                            |
| message | An explanation of the error.                                                                                                                                                                     |
| code    | Custom application code for a variation on the given error. For example, this can be a developer-tracked reason for a authentication issue.                                                      |
| status  | The HTTP status code. More information on HTTP Status codes can be found here.                                                                                                                   |
| type    | The type of exception that triggered this error response. Can be interpreted as a developer-readable meaning of the status code, or a custom error class that helps track down potential issues. |

### Example

Here's an example of an error response for a request that uses non existing record id.

```json
{
  "name": "Not Found",
  "message": "The requested record with id 8f14e83c-10a0-46a4-9028-c56916162b7c could not be found or is inaccessible",
  "code": 0,
  "status": 404,
  "type": "yii\\web\\NotFoundHttpException"
}
```

## Troubleshooting requests

### Bad Request - 400

#### Cause <a href="#cause" id="cause"></a>

BACE APIs return this error when:

* The request is malformed or is not in the expected format.

#### Solution

Check the syntax and format of your request.

### Unauthorized - 401

#### Cause <a href="#cause" id="cause"></a>

BACE APIs return this error when:

* You are trying to access API endpoint, but Authorization header is missing in request or API token is not valid.&#x20;
* Your account lacks the permission to access an endpoint.

#### Solution

Make sure that the request is using an existing and valid API token.\
We show all endpoints that you may have access to in the documentation and it is up to your implementation to handle this response gracefully.

If you feel that an endpoint may be of use to you, but you receive an unauthorized response in your application, you may contact us to request additional permissions for your account(s).

Example:

```json
{
    "name": "Unauthorized",
    "message": "Your request was made with invalid credentials.",
    "code": 0,
    "status": 401,
    "type": "yii\\web\\UnauthorizedHttpException"
}
```

### Not Found - 404

#### Cause <a href="#cause" id="cause"></a>

BACE APIs return this error when:

* A request is trying to perform an operation on a resource that does not exist.
* A POST request contains a resource ID that does not exist.

#### Solution

Make sure that the request is using an existing resource ID. Make sure you are using correct route, and you do not have typo in your URL.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bace-iot.com/reference/http-status-codes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
