# Threat defense

Switch Advanced Threat Defense and Deep Packet Inspection on or off, set the threat policy, override single DPI rules and search the threat intelligence.

This part of the API controls the Advanced Threat Defense (ATD) and the Deep Packet Inspection (DPI) of one domain. The paths start with `/v2/cdn/threat_defense/{domain_public_id}/`, where the id is the public id of the domain, taken from [the domains list](https://docs.diamwall.com/products/domains/#list-your-domains).

- [Settings](#settings): Switch ATD and DPI on or off, and tune ATD.
- [Threat policy](#threat-policy): Choose the action per threat level, per country and per provider.
- [DPI rules](#dpi-rules): Read the rule catalog, override single rules and declare packet inspection.
- [Search](#search): Look up an address, a network or the recent threats.

The examples on this page use these shell variables:

```bash
export DIAMWALL_API_KEY="your key"
export THREAT_DEFENSE="https://api.diamwall.com/v2/cdn/threat_defense/your-domain-public-id"
```

## How reads and writes work

Every read of a settings group or of the overrides answers the same envelope:

| Field | What it says |
| --- | --- |
| `revision` | The revision of what was read. The `ETag` header carries the same value. |
| `consistency` | `verified`, or `degraded` when the CDN could not verify everything. |
| `publication` | `status` and `rollout`. `rollout` is always `unknown`: the answer proves nothing about the other points of presence. |
| `data` | The settings or the items themselves. |

Every write takes the `ETag` of your last read in `If-Match`, exactly as it came, with its quotes. It is one strong ETag of the form `"sha256:<64 lowercase hexadecimal digits>"`.

- Without `If-Match` the write answers `428`.
- If what you read changed since, it answers `412 REVISION_MISMATCH` and nothing is written. Read again, then send the change with the new `ETag`.
- Each successful write answers a new `ETag`. Use it for the next write.

> **Unknown is not off**
> A value comes back as `{ "state": "resolved", "value": ... }`. A `state` of `unknown` has no `value` and means the CDN could not tell. Show it as unavailable. Never treat it as `false`, as disabled or as a default, and do not write on it.

## Settings

The `threat-defense` settings group says whether ATD and DPI are on, and holds three ATD options.

### Read the settings

[`GET /v2/cdn/threat_defense/{domain_public_id}/settings/threat-defense/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/GET/v2/cdn/threat_defense/{domain_public_id}/settings/threat-defense/)

```bash
curl -i "$THREAT_DEFENSE/settings/threat-defense/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

```json
{
  "revision": "sha256:3cf2e77fb74d...",
  "consistency": "verified",
  "publication": { "status": "verified", "rollout": "unknown" },
  "data": {
    "atd_enabled": { "state": "resolved", "value": true },
    "dpi_enabled": { "state": "resolved", "value": true },
    "atd": {
      "disabled_sources": { "state": "resolved", "value": ["dwchallenge"] },
      "reputation_overrides": {
        "low": { "state": "resolved", "value": "disabled" },
        "medium": { "state": "resolved", "value": "enabled" },
        "high": { "state": "resolved", "value": "inherit" }
      },
      "score_thresholds": {
        "high": { "state": "resolved", "value": 80 },
        "medium": { "state": "resolved", "value": 40 }
      }
    },
    "rate_limit_enabled": { "state": "resolved", "value": true }
  }
}
```

| Field | Values |
| --- | --- |
| `atd_enabled`, `dpi_enabled` | `true` or `false` |
| `atd.disabled_sources` | The ATD sources that are switched off: a list of `dwaf`, `dwchallenge` and `dwmitigation`. An empty list is a value. |
| `atd.reputation_overrides` | For each of `low`, `medium` and `high`: `inherit`, `enabled` or `disabled`. A value the API does not know comes back as `other`. |
| `atd.score_thresholds` | For each of `high` and `medium`: `null` or a whole number from 1 to 100. |
| `rate_limit_enabled` | `true` or `false`. Read-only: it cannot be written here. |

When the CDN cannot read the group at all, the answer is still `200`, with `"state": "unknown"`, a `revision` of `null`, no `data` and no `ETag`. There is nothing to write with until a read succeeds.

### Change the settings

[`PATCH /v2/cdn/threat_defense/{domain_public_id}/settings/threat-defense/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/PATCH/v2/cdn/threat_defense/{domain_public_id}/settings/threat-defense/)

The body holds exactly one of three fields: `atd_enabled`, `dpi_enabled` or `atd`. The fields you leave out keep their value. To change two of them, send two requests, the second with the `ETag` the first answered.

Read the group first to get its `ETag`:

```bash
ETAG=$(curl -s -o /dev/null -D - "$THREAT_DEFENSE/settings/threat-defense/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')
```

**Switch ATD off**

```bash
curl -X PATCH "$THREAT_DEFENSE/settings/threat-defense/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{ "atd_enabled": false }'
```

**Switch DPI on**

```bash
curl -X PATCH "$THREAT_DEFENSE/settings/threat-defense/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{ "dpi_enabled": true }'
```

**Tune ATD**

```bash
curl -X PATCH "$THREAT_DEFENSE/settings/threat-defense/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{
    "atd": {
      "disabled_sources": ["dwaf"],
      "reputation_overrides": { "medium": "disabled" },
      "score_thresholds": { "high": 80, "medium": null }
    }
  }'
```

Inside `atd`, send at least one of `disabled_sources`, `reputation_overrides` and `score_thresholds`:

- `disabled_sources` is always sent as the whole list, with no source twice.
- In `reputation_overrides` and `score_thresholds`, a level you leave out keeps its value.
- Booleans are JSON booleans and thresholds are JSON integers. `"true"`, `1` and `"50"` are refused.

The answer is the group as it is after the edit, in the same form as the read. An empty body (`{}`) answers `400 NO_CHANGES`. A body with two of the three fields answers `400 INVALID_REQUEST` and names them in `fields`. A field inside `atd` is named by its path, such as `atd.reputation_overrides.low`.

This endpoint switches DPI as a whole. To switch one DPI rule, use [an override](#override-a-rule).

## Threat policy

The `threat-policy` settings group holds the action taken per threat level, per country and per threat provider.

### Read the policy

[`GET /v2/cdn/threat_defense/{domain_public_id}/settings/threat-policy/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/GET/v2/cdn/threat_defense/{domain_public_id}/settings/threat-policy/)

```bash
curl -i "$THREAT_DEFENSE/settings/threat-policy/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

The parts of `data` you will use most:

| Field | What it holds |
| --- | --- |
| `policy` | What you set for this domain: `tiers`, `countries`, `country_tiers` and `providers`. A domain with nothing set answers `"configured": false` and an empty `policy`. |
| `defaults` | The platform defaults: `tiers` and `providers`. |
| `country_grid` | The action of each of the three levels for each country that has a rule. |
| `effective_policy` | For each provider, whether it is enabled and why: its `source` is `default`, `explicit`, `legacy` or `unknown`. With `unknown`, `enabled` can be `null`. |
| `capabilities` | The levels, actions and provider ids the policy accepts. |

A level that is present in `policy.tiers` is custom, even when its action is the same as the default. A level that is absent uses the action in `defaults.tiers`.

### Change the policy

[`PATCH /v2/cdn/threat_defense/{domain_public_id}/settings/threat-policy/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/PATCH/v2/cdn/threat_defense/{domain_public_id}/settings/threat-policy/)

Send only the parts that change, with the `ETag` of a read you just made. `null` removes what you set and goes back to the default.

| Part | Keys | Values | What a write does |
| --- | --- | --- | --- |
| `tiers` | `low`, `medium`, `high` | `skip`, `challenge`, `block`, `null` | Sets the action of a level for the whole domain. `null` restores the platform default. |
| `countries` | A country code, such as `PT` | `skip`, `challenge`, `block`, `null` | Sets one action for the country. It replaces the whole row of that country. |
| `country_tiers` | A country code, then `low`, `medium`, `high` | `inherit`, `ignore_atd`, `challenge`, `block`, `null` | Changes only the cells you send. A `null` cell removes its override. A `null` country removes the override of the country. |
| `providers` | `dwaf`, `dwchallenge`, `dwmitigation`, `abuseipdb`, `honeypot` | An object with `enabled`, or `null` | Switches a provider on or off. `null` removes the switch. |

**Level**

```bash
curl -X PATCH "$THREAT_DEFENSE/settings/threat-policy/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $POLICY_ETAG" \
  -d '{ "tiers": { "high": "block" } }'
```

**Country and level**

```bash
curl -X PATCH "$THREAT_DEFENSE/settings/threat-policy/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $POLICY_ETAG" \
  -d '{ "country_tiers": { "PT": { "medium": "challenge" } } }'
```

**Provider**

```bash
curl -X PATCH "$THREAT_DEFENSE/settings/threat-policy/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $POLICY_ETAG" \
  -d '{ "providers": { "honeypot": { "enabled": false } } }'
```

**Back to default**

```bash
curl -X PATCH "$THREAT_DEFENSE/settings/threat-policy/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $POLICY_ETAG" \
  -d '{ "tiers": { "high": null } }'
```

Things to know:

- With `skip` on a level, evaluation continues to the next protection. With `skip` on a country, evaluation continues to the level.
- A country that has no rule inherits all three levels.
- `countries` and `country_tiers` together accept up to 249 distinct countries, and a country may appear in only one of the two per request.
- A provider switch filters the evidence that already exists. It does not change what is collected, and the aggregate score stays the same.
- A provider id outside the five answers `400`, even with `null`.

> **Do not send the read back**
> Never send the whole answer of the read in the write. Send only the fields that change.
>
> - `{}` does not restore the defaults.
> - The `ETag` covers more than this group. A change to another policy group of the domain invalidates it, so read right before you write.
> - A write confirms what is declared. `data.publication` is `declared` and `data.rollout` is `unknown`: neither proves the change is applied at every point of presence.

### List the threat providers

[`GET /v2/cdn/threat_defense/{domain_public_id}/references/threat-providers/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/GET/v2/cdn/threat_defense/{domain_public_id}/references/threat-providers/)

```bash
curl "$THREAT_DEFENSE/references/threat-providers/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

Each item has an `id` and, when the catalog has them, a `kind` and a `default_enabled`, the default of its switch. The list is read-only and has no `ETag`. It pages with `limit` and `cursor`, like [the rules](#list-the-rules).

## DPI rules

DPI works from a catalog of rules. You can read the catalog, switch single rules for one domain with overrides, and declare a packet inspection policy for rules and groups of rules.

The catalog and the overrides are two separate reads. The API does not merge them: match an override to its rule by `rule_id`. Whether DPI is on at all is `dpi_enabled` in [the settings](#read-the-settings).

### List the rules

[`GET /v2/cdn/threat_defense/{domain_public_id}/references/dpi-rules/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/GET/v2/cdn/threat_defense/{domain_public_id}/references/dpi-rules/)

```bash
curl "$THREAT_DEFENSE/references/dpi-rules/?limit=50" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

```json
{
  "revision": "sha256:e955a22966cc...",
  "consistency": "verified",
  "publication": { "status": "verified", "rollout": "unknown" },
  "data": {
    "state": "resolved",
    "items": [
      {
        "id": "ExampleRule1",
        "category": "client",
        "description": "Illustrative client rule",
        "enabled": true,
        "name": "Example DPI rule",
        "severity": "high"
      },
      { "id": "ExampleRule2" }
    ],
    "page": { "limit": 50, "next_cursor": null, "total": 2 }
  }
}
```

- The `id` of a rule is what an override takes as `rule_id`.
- A rule may come with its `id` alone. A key that is absent says nothing: it is never `false`.
- `enabled` is what the catalog holds for the rule, not what this domain switched.
- `category` and `severity` are labels to show, not values from a fixed list.
- `limit` goes from 1 to 100. Without it a page holds 50 rules. Send `data.page.next_cursor` back as `cursor` until it is `null`.
- If the catalog changes between two pages, the next page answers `409 CURSOR_STALE`. Start again from the first page.

> **Unavailable is not empty**
> Only when `data.state` is `resolved` does the answer hold `items` and `page`. With any other state the answer is still `200`, with no `items` and no `page`: show the rules as unavailable, never as an empty catalog.

### List the overrides

[`GET /v2/cdn/threat_defense/{domain_public_id}/dpi-rule-overrides/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/GET/v2/cdn/threat_defense/{domain_public_id}/dpi-rule-overrides/)

```bash
curl -i "$THREAT_DEFENSE/dpi-rule-overrides/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

```json
{
  "revision": "sha256:2a13c7dbe841...",
  "consistency": "verified",
  "publication": { "status": "verified", "rollout": "unknown" },
  "data": {
    "items": [
      { "id": "Xk3-pQ7rT9vB2nM5cD8fG1hJ", "rule_id": "ExampleRule1", "enabled": false }
    ],
    "page": { "limit": 50, "next_cursor": null, "total": 1 }
  }
}
```

An override has its own `id`, the `rule_id` of its rule and `enabled`: `true` switches the rule on for this domain, `false` switches it off. An empty `items` is a domain with no override.

The `ETag` is the revision of the whole collection, not of one override. It is there for an empty list too, which is what you send to create the first override. `GET .../dpi-rule-overrides/{override_id}/` reads one override and answers the same `ETag`.

### Override a rule

[`POST /v2/cdn/threat_defense/{domain_public_id}/dpi-rule-overrides/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/POST/v2/cdn/threat_defense/{domain_public_id}/dpi-rule-overrides/)

Read the overrides to get the `ETag`, then send exactly `rule_id` and `enabled`:

```bash
ETAG=$(curl -s -o /dev/null -D - "$THREAT_DEFENSE/dpi-rule-overrides/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')

curl -i -X POST "$THREAT_DEFENSE/dpi-rule-overrides/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{ "rule_id": "ExampleRule1", "enabled": false }'
```

The answer is `201` with the new override under `data`. Its id is also in `operation.id`: use it to read, change or delete the override. The `ETag` header is the new revision of the collection.

> **One override per rule**
> A rule that already has an override answers `409 RESOURCE_CONFLICT`. Change the override it has. A `rule_id` that is not in the catalog answers `400 INVALID_REQUEST` with `rule_id` in `fields`.

### Change an override

[`PATCH /v2/cdn/threat_defense/{domain_public_id}/dpi-rule-overrides/{override_id}/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/PATCH/v2/cdn/threat_defense/{domain_public_id}/dpi-rule-overrides/{override_id}/)

The body is exactly `enabled`. The rule of an override cannot be changed: `rule_id` is refused here.

```bash
curl -i -X PATCH "$THREAT_DEFENSE/dpi-rule-overrides/Xk3-pQ7rT9vB2nM5cD8fG1hJ/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{ "enabled": true }'
```

An empty body (`{}`) answers `400 INVALID_REQUEST` with `enabled` in `fields`.

### Delete an override

[`DELETE /v2/cdn/threat_defense/{domain_public_id}/dpi-rule-overrides/{override_id}/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/DELETE/v2/cdn/threat_defense/{domain_public_id}/dpi-rule-overrides/{override_id}/)

```bash
curl -i -X DELETE "$THREAT_DEFENSE/dpi-rule-overrides/Xk3-pQ7rT9vB2nM5cD8fG1hJ/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "If-Match: $ETAG"
```

The rule is no longer overridden for this domain. The answer has no `data`, and `operation.id` is the id the override had. One request deletes one override. To delete several, send one request each, with the `ETag` the answer before gave.

### Packet inspection

[`GET /v2/cdn/threat_defense/{domain_public_id}/settings/packet-inspection/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/GET/v2/cdn/threat_defense/{domain_public_id}/settings/packet-inspection/)

The `packet-inspection` settings group declares, per rule, whether it is enabled and which action it takes: `skip`, `challenge` or `block`. The declaration is under `data.policy.rules`, a map from rule id to `enabled` and `action`.

```bash
curl -i "$THREAT_DEFENSE/settings/packet-inspection/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

A domain with nothing declared answers `"configured": false` and an empty `policy`.

### Change packet inspection

[`PATCH /v2/cdn/threat_defense/{domain_public_id}/settings/packet-inspection/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/PATCH/v2/cdn/threat_defense/{domain_public_id}/settings/packet-inspection/)

The body takes two optional parts:

| Part | Shape |
| --- | --- |
| `rules` | A map from rule id to an object with `enabled` and `action`, or to `null`. |
| `bulk` | A list of entries, each with a `selector` and a `policy`. The selector has one or more of `group`, `category`, `tag` and `compliance`. The policy has `enabled` and `action`. |

**One rule**

```bash
curl -X PATCH "$THREAT_DEFENSE/settings/packet-inspection/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $INSPECTION_ETAG" \
  -d '{ "rules": { "example_rule": { "enabled": false, "action": "skip" } } }'
```

**A group of rules**

```bash
curl -X PATCH "$THREAT_DEFENSE/settings/packet-inspection/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $INSPECTION_ETAG" \
  -d '{
    "bulk": [
      { "selector": { "group": "example_group" }, "policy": { "action": "skip" } }
    ],
    "rules": {
      "example_rule": { "enabled": false },
      "another_rule": { "enabled": false }
    }
  }'
```

How the parts combine:

- A selector with several keys matches the rules that fit all of them.
- Bulk entries apply in the order of the list. The `rules` you name apply last.
- The CDN expands each selector into its rules. `GET .../references/dpi-selectors/` lists the selectors you can send, each with its `kind`, its `value` and the `rule_ids` it expands to.
- `enabled` and `action` are set independently. A field you leave out of an entry is not filled in from the catalog default.
- Ten of the heuristics default to the `skip` action, so enabling one of them alone does not make it act.
- To keep every rule of a bulk entry disabled, set `enabled` to `false` on each of the selector's `rule_ids`.

The same cautions as [the threat policy](#change-the-policy) apply: send only what changes, `{}` does not restore the defaults, the `ETag` is invalidated by a change to another policy group, and a write confirms the declaration, not that it is applied at every point of presence.

## Search

Both searches read the threat intelligence and change nothing. They are `POST` requests with a JSON body, take no query parameter, and need neither `If-Match` nor `Idempotency-Key`. The body holds at most 1024 bytes.

### Search the ATD threat intelligence

[`POST /v2/cdn/threat_defense/{domain_public_id}/diagnostics/atd-search/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/POST/v2/cdn/threat_defense/{domain_public_id}/diagnostics/atd-search/)

The body is one of three, chosen by `mode`. A field of another mode is refused.

| `mode` | Fields | Answer in `data` |
| --- | --- | --- |
| `ip` | `value`: an IPv4 or IPv6 address | `exists`, and `result` when `exists` is `true` |
| `asn` | `value`: `AS` in upper case and a number, such as `AS64500`. Optional `limit`, 1 to 20 | `results`, at most 20 lines, and `count` |
| `recent` | Optional `page` (1 to 100), `page_size` (1 to 20) and `threat_level` (`all`, `low`, `medium`, `high`) | `results`, `page`, `page_size`, `threat_level` and `has_more` |

**One address**

```bash
curl -X POST "$THREAT_DEFENSE/diagnostics/atd-search/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "mode": "ip", "value": "192.0.2.123" }'
```

**One network**

```bash
curl -X POST "$THREAT_DEFENSE/diagnostics/atd-search/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "mode": "asn", "value": "AS64500", "limit": 20 }'
```

**Recent threats**

```bash
curl -X POST "$THREAT_DEFENSE/diagnostics/atd-search/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "mode": "recent", "page": 1, "page_size": 10, "threat_level": "all" }'
```

```json
{
  "diagnostic": "atd-search",
  "data": {
    "mode": "ip",
    "exists": true,
    "result": {
      "asn": "AS64500",
      "country": "PT",
      "flag_time": "2026-10-10 09:00:00",
      "info": "Illustrative threat intelligence entry",
      "ip": "192.0.2.xxx",
      "last_seen": "2026-10-10 09:05:00",
      "score": 85,
      "threat_level": "high"
    }
  }
}
```

- An address that is not known answers `"exists": false` with no `result`.
- The `recent` mode has no cursor and no total. `has_more` says whether there is a page after this one.
- An optional field you leave out is decided by the CDN.

### Search with DPI

[`POST /v2/cdn/threat_defense/{domain_public_id}/diagnostics/dpi-search/` in the API reference](https://docs.diamwall.com/api/#tag/threat-defense/POST/v2/cdn/threat_defense/{domain_public_id}/diagnostics/dpi-search/)

The body is one of two:

- `{}`: the recent threats of the highest level, at most 5, in `data.recent`.
- An object with `ip`: one address. The answer has `data.exists`, and `data.result` when `exists` is `true`.

```bash
curl -X POST "$THREAT_DEFENSE/diagnostics/dpi-search/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "ip": "192.0.2.123" }'
```

A request with no body at all is refused. Send `{}` for the recent threats.

### Reading a result line

Both searches answer lines with the same eight keys: `asn`, `country`, `flag_time`, `info`, `ip`, `last_seen`, `score` and `threat_level`.

- `score` is a whole number. `threat_level` is `low`, `medium` or `high`, or `other` for a level the API does not know.
- `flag_time` and `last_seen` are strings as the threat intelligence wrote them, not ISO 8601 times.
- `ip` is always masked: `192.0.2.xxx` for IPv4, or the start of an IPv6 address and `::`, such as `2001:db8::`. You never get a whole address.
- A key may be missing from a line. A line with no `ip` is a line whose address is not shown.

> **Unavailable is not empty**
> A search that could not run answers `503 DIAGNOSTIC_UNAVAILABLE`. Show it as unavailable, wait and search again. It never means that nothing was found: an empty list and `"exists": false` are real answers.

## Limits and permissions

- **Credits.** Each domain has a budget of 3000 credits a minute, shared by everyone who calls the API for that domain. Every call on this page costs 8 credits.
- **Refused requests.** A request the API refuses before it reaches the CDN, such as a body that is not in its form or a missing `If-Match`, spends no domain credits. A search the CDN refuses was one call, and is counted.
- **Out of credits.** The call answers `429 TOO_MANY_REQUESTS`, with the wait in `details.retry_after_seconds`.
- **Permissions.** Reads and both searches need `waf.view` on the domain. Changing the settings, changing packet inspection, and creating or changing an override need `waf.edit`. Deleting an override needs `waf.delete`: `waf.edit` alone is not enough.

## Errors you are likely to see

| Status | Code | What happened |
| --- | --- | --- |
| `400` | `INVALID_REQUEST` | A field is wrong, or the body is missing or has a field the API does not know. The answer names the field in `fields` when it can. |
| `400` | `NO_CHANGES` | The settings were edited with an empty body. |
| `400` | `INVALID_PRECONDITION` | `If-Match` is not one strong ETag with its quotes. |
| `404` | `RESOURCE_ITEM_NOT_FOUND` | No override of the domain has that id. It may have been deleted. |
| `404` | `SETTINGS_GROUP_NOT_FOUND` | The CDN does not have this settings group for the domain. Asking again answers the same. |
| `404` | `REFERENCE_NOT_FOUND` | The CDN does not have this catalog. Show it as unavailable, not as empty. |
| `404` | `DIAGNOSTIC_NOT_FOUND` | The CDN does not have this search to run. Asking again answers the same. |
| `409` | `CURSOR_STALE` | The list changed while you were paging. Start from the first page. |
| `409` | `RESOURCE_CONFLICT` | The rule already has an override, or the overrides are in a state that does not take the write. Nothing was written. |
| `409` | `INVALID_STATE` | The CDN refused the change for the state it found. Nothing was changed. Read the group before trying again. |
| `412` | `REVISION_MISMATCH` | What you are writing changed since your read. Read again and retry with the new `ETag`. |
| `428` | `PRECONDITION_REQUIRED` | The `If-Match` header is missing. |
| `429` | `TOO_MANY_REQUESTS` | The domain is out of credits for now. |
| `502` | `FILE_SERVER_OUTCOME_UNKNOWN` | The answer of a write was lost. The write may have been made. |
| `503` | `PUBLICATION_FAILED` | The CDN could not publish and verify a settings change. What is published now is not known from this answer. |
| `503` | `ROLLBACK_FAILED` | The CDN failed to publish an override write and could not put back what was there. |
| `503` | `DIAGNOSTIC_UNAVAILABLE` | The search could not run. Nothing in the request is wrong: wait and search again. |

After `FILE_SERVER_OUTCOME_UNKNOWN`, `PUBLICATION_FAILED`, `ROLLBACK_FAILED`, or a `FILE_SERVER_V2_ERROR` on a write, never repeat the request blindly. Read again first, compare with what you meant to write, and only then decide whether to send the change with the new `ETag`.

The errors that come from the key itself, such as `API_KEY_IP_NOT_ALLOWED`, are on the [Errors](https://docs.diamwall.com/reference/errors/) page.

## All Threat defense endpoints

Each row opens the endpoint in the API reference, with every parameter, rule and response.

See the [API reference](https://docs.diamwall.com/api/#tag/threat-defense) for every endpoint, with parameters and responses.
