# Responses

All API requests return standard HTTP status codes to indicate success or failure. In this section, you'll find explanations of **success responses**, **error responses**, and **code examples** to help you handle them properly.

## 🟢 Success Responses

When a request is processed successfully, the API returns one of the following status codes:

<figure><img src="/files/UTZ69BxGeOiIv38QEVHh" alt=""><figcaption></figcaption></figure>

| **Status Code** | **Response**     | **Description**                                                                       |
| --------------- | ---------------- | ------------------------------------------------------------------------------------- |
| 200 OK          | Success          | The request was successful, and the server returns the requested data.                |
| 201 Created     | Resource Created | The request was successful, and a new resource has been created (e.g., after a POST). |
| 204 No Content  | No Content       | The request was successful, but there is no data to return (e.g., after DELETE).      |

### **📘 Example – 200 OK**

```json
{
"status": "success"
}
```

## 🔴 Error Responses

When something goes wrong, the API will return an appropriate error code and a message to help you debug the issue.

<figure><img src="/files/J1RKGguHeJxVQUBdTp3i" alt=""><figcaption></figcaption></figure>

| **Status Code**           | **Response Example**                                       | **Description**                                                                  |
| ------------------------- | ---------------------------------------------------------- | -------------------------------------------------------------------------------- |
| 400 Bad Request           | {"error": "Please provide username."}                      | Your request is malformed—missing fields, invalid data types, or incorrect JSON. |
| 401 Unauthorized          | {"error": "Invalid API key."}                              | Authentication failed—API key is missing, incorrect, or expired.                 |
| 403 Forbidden             | {"error": "API key is missing."}                           | You don't have permission to access the resource.                                |
| 500 Internal Server Error | {"error": "Something went wrong. Please try again later."} | A server-side error occurred. Contact support if the issue persists.             |

### 💡 Common Error Scenarios

<figure><img src="/files/DNAC1SvJBtow76lMgCNP" alt=""><figcaption></figcaption></figure>

| **Error Message**               | **Likely Cause**                           | **Recommended Fix**                            |
| ------------------------------- | ------------------------------------------ | ---------------------------------------------- |
| Please provide username.        | Missing username field in the request body | Ensure you're passing username as a string     |
| Please provide password.        | Missing password field                     | Include the password key in the request body   |
| Invalid API key.                | Wrong or expired API key                   | Verify your token and reauthenticate if needed |
| Incorrect username or password. | Login credentials are invalid              | Double-check credentials or reset password     |

### 🧪 Sample: Handling a 401 Error in Curl

```bash
curl -X GET https://your-subdomain.api.infraon.app/api/user \
-H "Authorization: ApiKey INVALID_KEY"
```

#### **Response**

```json
{
"error": "Invalid API key."
}
```

{% hint style="info" %}
Always verify your request payload and headers before retrying. Use tools like **Postman**, **Insomnia**, or **Swagger UI** to test and debug effectively.
{% endhint %}


---

# 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.infraon.io/infraon-infinity-api-guide/welcome/responses.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.
