> For the complete documentation index, see [llms.txt](https://moonie.gitbook.io/mooniepay/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://moonie.gitbook.io/mooniepay/introduction/responses-format.md).

# Responses Format

All MooniePay API responses follow a single, consistent JSON structure — whether the request succeeds or fails. Understanding this format is essential to correctly parsing results and handling edge cases in your integration.

***

### Response Structure

Every response from the MooniePay API returns a JSON object with three top-level fields:

```json
{
  "success": true,
  "message": "Operation completed successfully.",
  "data": {}
}
```

| Field     | Type                      | Description                                                 |
| --------- | ------------------------- | ----------------------------------------------------------- |
| `success` | `boolean`                 | `true` if the HTTP status is `2xx`, `false` otherwise       |
| `message` | `string`                  | A human-readable summary of the result                      |
| `data`    | `object \| array \| null` | The response payload on success *(present only on success)* |
| `errors`  | `any \| null`             | Error details on failure *(present only on failure)*        |

> 💡 **Important:** The `data` key and the `errors` key are **mutually exclusive**. A successful response contains `data`. A failed response contains `errors`. You will never see both in the same response.

***

### Successful Response

When an operation completes successfully (HTTP `2xx`), the response includes `success: true` and a `data` field containing the result payload.

```json
{
  "success": true,
  "message": "Payment initialized successfully.",
  "data": {
    "id": "pay_xxxxxxxxxxxxxxxx",
    "status": "pending",
    "amount": 5000,
    "currency": "XAF",
    "created_at": "2024-06-10T12:00:00.000000Z"
  }
}
```

The structure of `data` varies per endpoint. Refer to each endpoint's documentation for its specific payload shape.

***

### Error Response

When an operation fails (HTTP `4xx` or `5xx`), the response includes `success: false` and an `errors` field in place of `data`. A `code` field is also included to help you programmatically identify the error type.

```json
{
  "success": false,
  "code": "AUTHENTICATION_HEADERS_REQUIRED",
  "message": "Missing authentication headers.",
  "errors": []
}
```

| Field     | Type                      | Description                                                          |
| --------- | ------------------------- | -------------------------------------------------------------------- |
| `success` | `boolean`                 | Always `false` for error responses                                   |
| `code`    | `string`                  | Machine-readable error code for programmatic handling                |
| `message` | `string`                  | Human-readable explanation of what went wrong                        |
| `errors`  | `array \| object \| null` | Additional error details, validation messages, or field-level issues |

***

### Validation Error Response

For requests that fail input validation, the `errors` field contains field-level details to help you pinpoint exactly what needs to be corrected:

```json
{
  "success": false,
  "code": "VALIDATION_ERROR",
  "message": "The given data was invalid.",
  "errors": {
    "amount": ["The amount field is required."],
    "currency": ["The currency field must be a valid ISO 4217 code."]
  }
}
```

***

### Response at a Glance

| Scenario               | `success` | `data` present | `errors` present | HTTP Status   |
| ---------------------- | --------- | -------------- | ---------------- | ------------- |
| Request succeeded      | `true`    | ✅              | ❌                | `2xx`         |
| Auth / signature error | `false`   | ❌              | ✅                | `401` / `403` |
| Validation error       | `false`   | ❌              | ✅ (field map)    | `422`         |
| Not found              | `false`   | ❌              | ✅                | `404`         |
| Server error           | `false`   | ❌              | ✅                | `500`         |

> ⚠️ Always check the `success` field first. Do not assume a `200 OK` response contains valid data without verifying `success: true`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://moonie.gitbook.io/mooniepay/introduction/responses-format.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
