# Getting started

Create an API key and make your first request to the Diamwall public API.

This page takes you from zero to a working request.

## 1. Create an API key

API keys are created in the Diamwall dashboard, not through the API.

1. Open the API keys page in the dashboard and choose to create a key.
2. Give the key a name. Optionally set an expiry date, a list of allowed IPs and the domains the key may act on. See [IP and domain restrictions](https://docs.diamwall.com/guides/restrictions/).
3. Confirm with your authenticator code if your account uses two-factor authentication, or with your password otherwise.
4. Copy the key.

:::caution
The key is shown only once, right after you create it. Store it in a secret manager. If you lose it, revoke it and create a new one.
:::

## 2. Make your first request

Send the key in the `Authorization` header, with the `Api-Key` prefix:

```bash
curl https://api.diamwall.com/public-api/domains/ \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

The answer is a paginated list of the domains this key can access.

To look up one domain, filter by its full name. The match ignores letter case:

```bash
curl "https://api.diamwall.com/public-api/domains/?name=example.com" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

## 3. Call the CDN endpoints

With a domain in hand you can call the CDN operations that accept an API key. The [API reference](https://docs.diamwall.com/api/) lists every one of them, with parameters and response shapes.

## If the request fails

| What you see | Why | What to do |
| --- | --- | --- |
| `403 API_KEY_INVALID` | The key is invalid or inactive. | Check the header is exactly `Authorization: Api-Key <your-key>` and that the key is still active. |
| `403 API_KEY_IP_NOT_ALLOWED` | The request comes from an IP outside the key's list. | Call from an allowed IP, or update the key's IP list in the dashboard. |
| `403 API_KEY_ACCESS_DENIED` | The key is not allowed to act on that domain. | Add the domain to the key in the dashboard. |
| `403 SECURITY_IP_NOT_ALLOWED` | The domain's organization has its own IP list and your IP is not on it. | Call from an IP on the organization's list. |

The full list is in [Errors](https://docs.diamwall.com/reference/errors/).
