# Errors

The error codes the Diamwall public API answers, what each one means and what to do about it.

Every error is a JSON object with a stable code in `message`. Match on that code in your integration, not on the HTTP status alone: several codes share one status.

```json
{
  "message": "INVALID_REQUEST",
  "fields": ["limit"]
}
```

Some codes add more:

| Field | When it is there |
| --- | --- |
| `fields` | The names of the fields that were refused. |
| `details` | Numbers that go with the code, such as `retry_after_seconds` or a plan limit. |
| `request_id` | The id of the request at the CDN, when the CDN answered. |
| `organization` | The organization whose rule refused the request (`public_id` and `name`). |

The tables below cover the codes that many endpoints share. A code that belongs to one feature is listed on that feature's page, for example [DNS](https://docs.diamwall.com/products/dns/#errors-you-are-likely-to-see).

## Key and access

Every endpoint can answer these, before it looks at anything else.

| Status | Code | Meaning | What to do |
| --- | --- | --- | --- |
| 403 | `API_KEY_INVALID` | The key is invalid or inactive, or its account cannot use the API. | Check the key is the right one and still active. |
| 403 | `API_KEY_REQUIRED` | The operation only accepts an API key, and the request did not carry one. | Send `Authorization: Api-Key <your-key>`. |
| 403 | `API_KEY_QUERY_FORBIDDEN` | The key was sent in the URL. | Send it in the `Authorization` header. |
| 403 | `API_KEY_AMBIGUOUS_CREDENTIALS` | The request carried a session cookie as well as the key. | Send the key without a session cookie. |
| 403 | `API_KEY_IP_NOT_ALLOWED` | The caller's IP is outside the key's list. | Call from an allowed IP, or change the list in the API key settings. |
| 403 | `API_KEY_ACCESS_DENIED` | The domain is unknown, is outside the key's scope, or the account lacks a permission the endpoint needs. | Add the domain to the key, or ask for the permission. |
| 403 | `API_KEY_ENDPOINT_FORBIDDEN` | The key is not allowed to call this operation, for example registering or deleting a domain. | Use a key that has the operation enabled. |
| 403 | `SECURITY_IP_NOT_ALLOWED` | The caller's IP is outside the IP list of the organization named in `organization`. | Call from an IP on that list. Only the organization's owner can change it. |
| 403 | `SECURITY_2FA_REQUIRED` | The organization named in `organization` requires two-factor authentication on the account. | Turn on two-factor authentication for the account that owns the key. |
| 403 | `PUBLIC_API_DISABLED` | Public API access is disabled for the account. | The API is in preview and is enabled account by account. |
| 429 | `API_KEY_RATE_LIMITED` | Too many requests. | Wait, then send the request again. |
| 503 | `PUBLIC_API_UNAVAILABLE` | The public API cannot answer right now. | Try again later. |

More on the IP and domain checks: [IP and domain restrictions](https://docs.diamwall.com/guides/restrictions/).

## The request itself

| Status | Code | Meaning | What to do |
| --- | --- | --- | --- |
| 400 | `INVALID_REQUEST` | A field is missing, not in its form, or not accepted. | Fix the fields named in `fields`. |
| 400 | `NO_CHANGES` | An edit was sent with nothing to change. | Send at least one field. |
| 404 | `DOMAIN_NOT_FOUND` | The CDN does not have this domain, or cannot serve it. | Check the domain's public id. |
| 404 | `RESOURCE_ITEM_NOT_FOUND` | Nothing has that id. | Read the list again and use an id from it. |
| 415 | `UNSUPPORTED_MEDIA_TYPE` | The body is not JSON. | Send it as `application/json`. |
| 428 | `PRECONDITION_REQUIRED` | A write was sent without `If-Match`. | Read what you are writing first, and send the `ETag` of that answer in `If-Match`. |
| 412 | `REVISION_MISMATCH` | What you are writing changed since your read. | Read again and send the write with the new `ETag`. |

## The state of the domain

| Status | Code | Meaning | What to do |
| --- | --- | --- | --- |
| 403 | `FEATURE_NOT_AVAILABLE` | The domain's plan does not include this. | Nothing to retry. `details` says what the plan lacks. |
| 409 | `DOMAIN_WITHOUT_KEY` | The domain is not active on the network yet. | Sending the request again changes nothing. Wait for the domain to be active. |
| 409 | `DOMAIN_BUSY` | Something else is changing the domain right now. | Try again shortly. |
| 409 | `DOMAIN_REPLACEMENT_PENDING` | The domain is being renamed. Nothing was written. | Try again later. |
| 409 | `INVALID_STATE` | The CDN refused the change for the state it found. | Read the current state before trying again. |
| 409 | `CURSOR_STALE` | A list changed while you were paging through it. | Start again from the first page. |
| 503 | `STATE_CHANGING` | What the request acts on kept changing. | Back off, then send the same request again with the same `Idempotency-Key`. |

## The events feed

These come from `GET /public-api/organizations/{org_public_id}/siem/events/`. See [Events feed](https://docs.diamwall.com/products/events/#errors-you-are-likely-to-see).

| Status | Code | Meaning |
| --- | --- | --- |
| 403 | `SIEM_ACCESS_DENIED` | No access to the organization or to the domain, the `siem` permission is missing, or no firewall source the consumer asked for can be read yet. |
| 400 | `SIEM_INVALID_QUERY` | A parameter is not valid, or the combination is not allowed. |
| 400 | `SIEM_INVALID_CURSOR` | The cursor cannot be used. Start again from the base URL. |
| 409 | `SIEM_CONSUMER_FILTER_MISMATCH` | The filters differ from the ones stored for the consumer. |
| 409 | `SIEM_CONSUMER_LIMIT_REACHED` | The organization already has 8 consumers. |
| 429 | `API_KEY_RATE_LIMITED` | Too many requests. Wait for the time in `Retry-After`. |
| 409 | `SIEM_CONSUMER_BUSY` | Another request is reading with this consumer. |
| 503 | `SIEM_SOURCE_NOT_READY` | A source cannot be read yet. Try again later. |

## Event destinations

These come from `/public-api/organizations/{org_public_id}/siem/event-destinations/`. The full table is on the [Event destinations](https://docs.diamwall.com/products/event-destinations/#errors-you-are-likely-to-see) page.

| Status | Code | Meaning |
| --- | --- | --- |
| 400 | `SIEM_DESTINATION_INVALID_REQUEST` | The body is not valid. |
| 400 | `SIEM_SENTINEL_INVALID_*` | The named field of `configuration` is not valid. |
| 400 | `SIEM_SPLUNK_INVALID_ENDPOINT_URL`, `SIEM_SPLUNK_INVALID_TOKEN` | The Splunk address or token is not valid. |
| 400 | `SIEM_SYSLOG_INVALID_HOST`, `SIEM_SYSLOG_INVALID_PORT`, `SIEM_SYSLOG_INVALID_MESSAGE_LIMIT`, `SIEM_SYSLOG_INVALID_CA_CERTIFICATE` | The named Syslog field is not valid. |
| 404 | `SIEM_DESTINATION_NOT_FOUND` | The organization has no destination with that id. |
| 409 | `SIEM_DESTINATION_LIMIT_REACHED` | The organization already has 8 destinations. |
| 409 | `SIEM_DESTINATION_NAME_TAKEN` | Another destination has that name. |
| 409 | `SIEM_DESTINATION_BUSY` | A delivery is in progress. Try again shortly. |
| 503 | `SIEM_HTTPS_DISABLED` | Sending to SIEMs is not switched on. |
| 503 | `SIEM_HTTPS_CIPHER_UNAVAILABLE`, `SIEM_HTTPS_CREDENTIAL_INVALID` | The secret could not be stored or read safely. |

## Request logs

These come from the [request logs](https://docs.diamwall.com/products/request-logs/). The [delivery history](https://docs.diamwall.com/products/event-destinations/#see-what-was-sent) of event destinations uses the same filter, cursor and unavailable codes.

| Status | Code | Meaning |
| --- | --- | --- |
| 400 | `PUBLIC_API_LOG_FILTER_INVALID` | A filter is not valid. |
| 400 | `PUBLIC_API_LOG_CURSOR_INVALID` | The cursor cannot be used. Start again without `cursor`. |
| 403 | `AUDIT_LOGS_ACCESS_DENIED` | The `audit_logs.view` permission is missing in the organization. |
| 429 | `PUBLIC_API_LOG_RATE_LIMITED` | Too many requests. Wait for the time in `Retry-After`. |
| 503 | `PUBLIC_API_LOGS_UNAVAILABLE` | The history cannot be read right now. Try again later. |

## Limits

Both answers carry the wait in `details.retry_after_seconds`, which is also the `Retry-After` header.

| Status | Code | Meaning |
| --- | --- | --- |
| 429 | `TOO_MANY_REQUESTS` | A limit of this API was reached, per user or per domain. Nothing ran. |
| 429 | `RATE_LIMIT_EXCEEDED` | The CDN refused the domain and the action did not run. |

## When the answer is uncertain

These tell you whether the action ran, which decides if it is safe to send again.

| Status | Code | Did it run? | What to do |
| --- | --- | --- | --- |
| 502 | `FILE_SERVER_NO_ANSWER` | No. Nothing changed. | Send the same request again. |
| 500 | `UNEXPECTED_ERROR` | Maybe. | Send the same request again with the same `Idempotency-Key`, within 24 hours. |
| 502 | `FILE_SERVER_OUTCOME_UNKNOWN` | Maybe. The answer was lost. | Send the same request again with the same `Idempotency-Key`, within 24 hours. |
| 503 | `PUBLICATION_FAILED` | The CDN could not publish and verify the change, and tries to roll it back. | Read the current state before trying again. |
| varies | `FILE_SERVER_V2_ERROR` | The CDN answered with a code this API has no code of its own for. | Keep the `request_id` from the answer. |

:::tip[Why the same Idempotency-Key]
A repeated request with the same key and the same body does not run the action twice. If the first attempt did run, you get its answer back.
:::

## When managing keys in the dashboard

These come from the key pages of the dashboard, not from calls made with a key.

| Code | Meaning |
| --- | --- |
| `API_KEY_CONFIRMATION_REQUIRED` | The change needs your authenticator code or password. |
| `API_KEY_CONFIRMATION_FAILED` | The authenticator code or password was wrong. |
| `API_KEY_LIMIT_REACHED` | The account already has its maximum number of active keys. |
| `API_KEY_INACTIVE` | The key is expired or revoked and cannot be edited. |
| `API_KEY_INVALID_IP_RULES` | An allowed IP entry is not valid, is repeated, uses `/0` or has a zone (`%`). |
| `API_KEY_DOMAINS_REQUIRED` | This key must list at least one domain. |
| `API_KEY_INVALID_DOMAINS` | A domain is repeated or cannot be given to this key. |
| `API_KEY_INVALID_REQUEST` | An edit did not include both the IP list and the domain list. |
| `API_KEY_NOT_FOUND` | The key does not exist. |
