> ## Documentation Index
> Fetch the complete documentation index at: https://docs.donate.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors

> The error body, what each status means, every code, and what to do about each

Every response that is not a success has the same JSON body and an HTTP status that matches it.

```json theme={null}
{
  "code": "NOT_FOUND",
  "message": "Not found."
}
```

| Field | Meaning |
| - | - |
| `code` | A stable identifier in upper snake case. Branch on this |
| `message` | A sentence for a person. The wording can change; do not match on it |
| `issues` | On a `VALIDATION_ERROR` about a field: one entry per problem, each naming the field. Absent on every other error, and on a [`VALIDATION_ERROR` about what a value names](#without-issues) |

This holds for every operation and for the answers no operation produces: a missing key, a rate
limit, a path that does not exist and a method a path does not support.

## What a status means

A status means one thing, on every operation. It tells you what to do next before you read the
code.

| Status | Meaning | What to do |
| - | - | - |
| `400` | The request is malformed | Fix the request. Do not retry it as is |
| `401` | The API key is missing or not valid | Send a valid `donate-api-key` |
| `403` | The key is valid and the thing belongs to another project | Use the project that owns it |
| `404` | The URL names nothing | Check the id and the path |
| `405` | The path exists and does not support this method | Use a method in the `Allow` header |
| `409` | The thing exists and its state forbids this | Read its state; do not retry as is |
| `413` | The request body is larger than 256 KiB | Send a smaller body |
| `422` | The body is well formed and names something that cannot be used | Change what the body names |
| `429` | You are over a rate limit | Wait for `Retry-After` seconds |
| `500` | Something failed on our side | Retry later with backoff |
| `503` | A chain or an outside service could not be read | Retry later. Keep showing what you had |

## Invalid requests

A path, query or body that does not fit the operation's parameters answers `400` with
`VALIDATION_ERROR` and `issues`. This is the answer to
`GET /v2/beneficiaries?term=help&limit=51`:

```json theme={null}
{
  "code": "VALIDATION_ERROR",
  "message": "The query is invalid.",
  "issues": [
    { "path": "limit", "code": "too_large", "message": "Too big: expected number to be <=50" }
  ]
}
```

| Field of an issue | Meaning |
| - | - |
| `path` | The field, written as you would write it: `limit`, `beneficiaries[1].weight`. Empty for the request as a whole |
| `code` | `required`, `invalid`, `too_small`, `too_large`, `unknown` or `duplicate` |
| `message` | A sentence for a person |

When `issues` is there, `message` at the top says where the problem is: `The path is invalid.`,
`The query is invalid.` or `The request body is invalid.`

A parameter or body field the operation does not know is an error, not something the API ignores,
so a misspelled filter cannot silently return unfiltered results:

```json theme={null}
{
  "code": "VALIDATION_ERROR",
  "message": "The query is invalid.",
  "issues": [{ "path": "sortBy", "code": "unknown", "message": "This field is not accepted" }]
}
```

The same beneficiary twice in a config is reported at the entry that repeats it:

```json theme={null}
{
  "code": "VALIDATION_ERROR",
  "message": "The request body is invalid.",
  "issues": [
    {
      "path": "beneficiaries[1]",
      "code": "duplicate",
      "message": "This beneficiary is already in the config"
    }
  ]
}
```

### Without `issues`

Some requests are well formed and still wrong, because of what a value names. They answer `400`
with `VALIDATION_ERROR` too. The body is `code` and `message` with no `issues`, and `message` is
the only place the reason is said.

| Operation | The request |
| - | - |
| `POST /v2/configs` | Names recipients that together would pay more than five receivers. See [configs and weights](https://docs.donate.gg/concepts.md#configs-and-weights) |
| `GET /v2/campaigns` | Has a `categoryId` that is not an `id` from `GET /v2/categories` |
| `GET /v2/configs/{configId}/fee` | Has a `chainId` a donation cannot be made on, or a `creditedAddress` that is not an address on that chain |
| `POST /v2/campaigns/{campaignId}/deposit-addresses` | Names a chain the campaign takes no deposits on |
| `GET /v2/campaigns/{campaignId}/deposits/{chainId}/{transactionHash}` | Has a `transactionHash` that is not one on the chain in the path |
| `GET /v2/registers/{registerId}/entries` | Has a `term` the register cannot be searched with |
| Any operation with a `configId` or an `address` in its path | Has a config id that is not 32 bytes, or an address that is not one on its chain |

Branch on `code`, as for any error, and show `message` to the person who can fix the request.

## Codes

### On any operation

| Status | `code` | Meaning |
| - | - | - |
| `400` | `VALIDATION_ERROR` | A path, query or body value is invalid. See `issues`, when it is there |
| `401` | `UNAUTHENTICATED` | The operation needs a key and none was sent, or the key sent is not valid. A public operation also answers this to a key that is not valid |
| `404` | `ROUTE_NOT_FOUND` | No operation has this path. Check the version and the spelling |
| `405` | `METHOD_NOT_ALLOWED` | The path does not support this method. `Allow` lists the ones it does |
| `429` | `RATE_LIMIT_EXCEEDED` | You are over a [rate limit](https://docs.donate.gg/api/rate-limits.md). `Retry-After` is the wait in seconds |
| `500` | `INTERNAL_ERROR` | Something failed on our side |
| `503` | `PROVIDER_UNAVAILABLE` | A chain or an outside service could not be read |

`NOT_FOUND` and `ROUTE_NOT_FOUND` are both `404` and mean different things: `NOT_FOUND` is a real
operation that found nothing for the id you sent, and `ROUTE_NOT_FOUND` is a path that is not an
operation.

### Reading one thing

| Status | `code` | Meaning |
| - | - | - |
| `404` | `NOT_FOUND` | Nothing has this id. A charity that is hidden, disabled or has opted out, or a hidden campaign, is not a `404` on its own read: it is read as a [stand-in](https://docs.donate.gg/api/pagination-and-formats.md#a-recipient-that-is-withheld). Its donations and messages are a `404` |
| `403` | `FORBIDDEN` | On an operation about your own configs: the config belongs to another project |

### Lists

| Status | `code` | Meaning |
| - | - | - |
| `400` | `INVALID_CURSOR` | The `cursor` is not one this API returned for this exact request. Start again without a cursor. See [pagination](https://docs.donate.gg/api/pagination-and-formats.md#lists) |

### Requests with a body

| Status | `code` | Meaning |
| - | - | - |
| `400` | `INVALID_JSON` | The body is not JSON |
| `413` | `PAYLOAD_TOO_LARGE` | The body is larger than 256 KiB |

### Creating a config

| Status | `code` | Meaning |
| - | - | - |
| `422` | `BENEFICIARY_NOT_FOUND` | A beneficiary does not exist, or is [withheld](https://docs.donate.gg/api/pagination-and-formats.md#a-recipient-that-is-withheld). The two are answered alike |
| `422` | `BENEFICIARY_NOT_ELIGIBLE` | A beneficiary is visible and takes no new configs, such as a campaign that has ended |
| `503` | `PROVIDER_UNAVAILABLE` | A campaign's provider could not be read, or a change to a beneficiary is still being applied. Send the same request again shortly |

Both name the entries at fault in `issues`, each by its path in the body, such as
`beneficiaries[1]`. `issues` is absent when the refusal cannot be tied to an entry, which
happens while a change to a beneficiary is still being applied.

More than five beneficiaries, a weight that is not a positive whole number, a duplicate
beneficiary and an `id` that holds a control character are `VALIDATION_ERROR` with `issues`.
Beneficiaries that together would pay more than five receivers are `VALIDATION_ERROR`
[without `issues`](#without-issues).

### Campaign deposit addresses

| Status | `code` | Meaning |
| - | - | - |
| `409` | `DEPOSITS_CLOSED` | The campaign exists and is not accepting deposits |
| `429` | `RATE_LIMIT_EXCEEDED` | This operation has its own, lower limit. Wait for `Retry-After` seconds |

### Charity requests

| Status | `code` | Meaning |
| - | - | - |
| `400` | `REGISTRATION_INVALID` | The registration number is not in the format the register accepts |
| `422` | `REGISTRATION_NOT_FOUND` | The register has no organisation with this number |
| `422` | `REGISTRATION_NOT_ELIGIBLE` | The organisation is in the register and cannot be listed |
| `409` | `CHARITY_UNAVAILABLE` | The charity is not available on Donate |
| `409` | `NEEDS_MANUAL_REVIEW` | The request needs a person at Donate to look at it before it can continue |

## Retrying

Retry `429`, `500` and `503`, with the wait from `Retry-After` when it is there and backoff
otherwise. Do not retry `400`, `401`, `403`, `404`, `409` or `422` without changing the request:
the answer will be the same.

Creating a config is safe to repeat. For your project, the same beneficiaries and weights always
give the same config, so a retry after a timeout returns the config the first attempt created,
with `200` instead of `201`.

## Errors on v1

`/api/v1` has its own body, and it keeps it:

```json theme={null}
{ "error": "Charity not found", "code": "NOT_FOUND" }
```

`error` is the sentence and `code` the identifier. Its codes and some of its statuses differ from
the ones above (a missing key is `400 MISSING_API_KEY` and a wrong one `403 INVALID_API_KEY`), and
`issues` on a `VALIDATION_ERROR` is a list of raw validation details. The reference page of each
v1 operation lists what it can answer. [Versions](https://docs.donate.gg/api/versions.md) explains the two.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.