Protection
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.
The examples on this page use these shell variables:
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
Section titled “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-Matchthe write answers428. - If what you read changed since, it answers
412 REVISION_MISMATCHand nothing is written. Read again, then send the change with the newETag. - Each successful write answers a new
ETag. Use it for the next write.
Settings
Section titled “Settings”The threat-defense settings group says whether ATD and DPI are on, and holds three ATD options.
Read the settings
Section titled “Read the settings”curl -i "$THREAT_DEFENSE/settings/threat-defense/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "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
Section titled “Change the settings”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:
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 }')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 }'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 }'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_sourcesis always sent as the whole list, with no source twice.- In
reputation_overridesandscore_thresholds, a level you leave out keeps its value. - Booleans are JSON booleans and thresholds are JSON integers.
"true",1and"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.
Threat policy
Section titled “Threat policy”The threat-policy settings group holds the action taken per threat level, per country and per threat provider.
Read the policy
Section titled “Read the policy”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
Section titled “Change the 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. |
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" } }'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" } } }'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 } } }'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
skipon a level, evaluation continues to the next protection. Withskipon a country, evaluation continues to the level. - A country that has no rule inherits all three levels.
countriesandcountry_tierstogether 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 withnull.
List the threat providers
Section titled “List the threat providers”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.
DPI rules
Section titled “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.
List the rules
Section titled “List the rules”curl "$THREAT_DEFENSE/references/dpi-rules/?limit=50" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "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
idof a rule is what an override takes asrule_id. - A rule may come with its
idalone. A key that is absent says nothing: it is neverfalse. enabledis what the catalog holds for the rule, not what this domain switched.categoryandseverityare labels to show, not values from a fixed list.limitgoes from 1 to 100. Without it a page holds 50 rules. Senddata.page.next_cursorback ascursoruntil it isnull.- If the catalog changes between two pages, the next page answers
409 CURSOR_STALE. Start again from the first page.
List the overrides
Section titled “List the overrides”curl -i "$THREAT_DEFENSE/dpi-rule-overrides/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "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
Section titled “Override a rule”Read the overrides to get the ETag, then send exactly rule_id and enabled:
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.
Change an override
Section titled “Change an override”The body is exactly enabled. The rule of an override cannot be changed: rule_id is refused here.
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
Section titled “Delete an override”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
Section titled “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.
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
Section titled “Change 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. |
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" } } }'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
rulesyou name apply last. - The CDN expands each selector into its rules.
GET .../references/dpi-selectors/lists the selectors you can send, each with itskind, itsvalueand therule_idsit expands to. enabledandactionare 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
skipaction, so enabling one of them alone does not make it act. - To keep every rule of a bulk entry disabled, set
enabledtofalseon each of the selector’srule_ids.
The same cautions as the threat 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
Section titled “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
Section titled “Search the ATD threat intelligence”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 |
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" }'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 }'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" }'{ "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": falsewith noresult. - The
recentmode has no cursor and no total.has_moresays whether there is a page after this one. - An optional field you leave out is decided by the CDN.
Search with DPI
Section titled “Search with DPI”The body is one of two:
{}: the recent threats of the highest level, at most 5, indata.recent.- An object with
ip: one address. The answer hasdata.exists, anddata.resultwhenexistsistrue.
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
Section titled “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.
scoreis a whole number.threat_levelislow,mediumorhigh, orotherfor a level the API does not know.flag_timeandlast_seenare strings as the threat intelligence wrote them, not ISO 8601 times.ipis always masked:192.0.2.xxxfor IPv4, or the start of an IPv6 address and::, such as2001:db8::. You never get a whole address.- A key may be missing from a line. A line with no
ipis a line whose address is not shown.
Limits and permissions
Section titled “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 indetails.retry_after_seconds. - Permissions. Reads and both searches need
waf.viewon the domain. Changing the settings, changing packet inspection, and creating or changing an override needwaf.edit. Deleting an override needswaf.delete:waf.editalone is not enough.
Errors you are likely to see
Section titled “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 page.
All Threat defense endpoints
Section titled “All Threat defense endpoints”Each row opens the endpoint in the API reference, with every parameter, rule and response.
Loading the endpoints...