> ## 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.

# Authentication

> Send your key in the donate-api-key header. Most reads work without one

Authenticate with your project's API key in the `donate-api-key` header.

```bash theme={null}
curl "https://api.donate.gg/api/v2/configs" \
  -H "donate-api-key: $DONATE_API_KEY"
```

[API keys](https://docs.donate.gg/api-keys.md) explains how to get one.

## When you need a key

A key is required when an operation acts for your project or reads what belongs to it. Everything
else is a public read.

| Operation | Key |
| - | - |
| `POST /v2/configs` | Required |
| `GET /v2/configs` | Required |
| `GET /v2/configs/{configId}/stats` | Required |
| `GET /v2/configs/{configId}/donors` | Required |
| `GET /v2/donation-sources/{chainId}/{address}/coins` | Required |
| `POST /v2/charity-requests` | Required |
| Every other operation, including `POST /v2/campaigns/{campaignId}/deposit-addresses` | Optional |
| `GET /api/openapi`, `GET /api/postman` | None |

Send the key on a public read too: the call then counts against your organization's
[rate limit](https://docs.donate.gg/api/rate-limits.md) instead of the 20 a minute an IP address gets. An integration that
runs on your backend sends it on every call.

The three reads about your own things answer for your project only. A config of another project
answers `403` with `FORBIDDEN` on its stats and donors, and a donation source of another project
answers `404`.

## Call from your server

The API accepts browser requests from Donate's own sites only. A request from a page on your
domain is blocked by CORS whether or not it carries a key. Make every call from your server, and
never put the key in code that runs on someone else's device.

## When authentication fails

A missing key and a key that is not valid are the same answer: `401` with `UNAUTHENTICATED`.

```json theme={null}
{
  "code": "UNAUTHENTICATED",
  "message": "This operation needs your API key. Send it in the donate-api-key header."
}
```

Two details to know:

* **A key that is not valid fails a public read too.** If you send a key, it must be valid.
* **A path that does not exist is `404`, not `401`.** A mistyped path answers `ROUTE_NOT_FOUND`
  with or without a key, so a `401` always means the key.

[Errors](https://docs.donate.gg/api/errors.md) lists every code. v1 answers a missing key with `400 MISSING_API_KEY` and a
wrong one with `403 INVALID_API_KEY`; see [Errors on v1](https://docs.donate.gg/api/errors.md#errors-on-v1).

## Runnable check

```bash theme={null}
export DONATE_API_KEY="your key"

# A public read with no key
curl "https://api.donate.gg/api/v2/categories"

# An operation that needs a key, without one: 401 UNAUTHENTICATED
curl -i "https://api.donate.gg/api/v2/configs"

# The same operation with the key
curl "https://api.donate.gg/api/v2/configs?limit=5" -H "donate-api-key: $DONATE_API_KEY"
```


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