# DNS

Read and change the DNS records of a domain, tune its SOA and run diagnostics.

Everything here works on one domain at a time. The paths start with `/v2/cdn/dns/{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).

- [Records](#records): List, create, edit and delete the records of the zone.
- [SOA](#soa): Read the SOA, change its timings or apply a profile.
- [Diagnostics](#diagnostics): Check the name servers and what the zone answers.
- [Zone settings](#zone-settings): See what the CDN publishes for the zone as a whole.

The examples on this page use these shell variables:

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

## Records

### What a record is made of

| Field | Example | Notes |
| --- | --- | --- |
| `name` | `shop` | Relative to the domain. @ is the domain itself, * a wildcard. |
| `type` | `a` | One of 15 types, in lower case. |
| `value` | `203.0.113.20` | Its form depends on the type. Always sent whole. |
| `proxied` (optional) | `true` | Only on a and cname. Left out, the CDN decides. |
| `ttl` (optional) | `300` | Seconds, 60 to 86400. |

The `value` changes shape with the `type`. Numbers are sent as numbers, never as strings, and a field the type does not have is refused.

| `type` | `value` |
| --- | --- |
| `a`, `aaaa` | A string: an IPv4 or IPv6 address |
| `cname`, `ns`, `ptr` | A string: a hostname |
| `alias` | A string: a relative name, with no wildcard |
| `txt`, `spf` | A string: the text, not empty, at most 16 KiB |
| `mx` | An object with `destination` and `priority` |
| `srv` | An object with `target`, `port`, `priority` and `weight` |
| `caa` | An object with `flag`, `tag` and `value` |
| `tlsa` | An object with `usage`, `selector`, `matching_type` and `certificate` |
| `ds` | An object with `key_tag`, `algorithm`, `digest_type` and `digest` |
| `https`, `svcb` | An object with `priority` and `target`, and optionally `alpn`, `no_default_alpn`, `port`, `ipv4hint` and `ipv6hint` |

### Writes need the latest revision

Two people editing the same zone must not overwrite each other. So every create, edit and delete has to prove it saw the latest state of the records.

1. **Read.** `GET .../records/` answers with an `ETag` header: the revision of the whole set of records.
2. **Send it back.** Put that value in `If-Match` on the create, edit or delete, exactly as it came.
3. **Check the answer.** `2xx`: written, keep the new `ETag` for the next write. `412`: the records changed since your read, so read again and retry. `428`: the `If-Match` header is missing.

### List the records

[`GET /v2/cdn/dns/{domain_public_id}/records/` in the API reference](https://docs.diamwall.com/api/#tag/dns/GET/v2/cdn/dns/{domain_public_id}/records/)

```bash
curl "$DNS/records/?limit=50" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

```json
{
  "revision": "sha256:c8dda7bd8cfc...",
  "data": {
    "items": [
      {
        "id": "6064981d2b888b2e7074",
        "name": "@",
        "type": "a",
        "value": "203.0.113.10",
        "proxied": true,
        "ttl": 300
      }
    ],
    "page": { "limit": 50, "next_cursor": "eyJyIjoic2hhMjU2...", "total": 23 }
  }
}
```

- `limit` goes from 1 to 100. Without it a page holds 50 records.
- To read the next page, send `data.page.next_cursor` back as `cursor`, until it is `null`.
- `data.page.total` is the number of records in the whole zone.
- If a record changes between two pages, the next page answers `409 CURSOR_STALE`. Start again from the first page.

### Add a record

[`POST /v2/cdn/dns/{domain_public_id}/records/` in the API reference](https://docs.diamwall.com/api/#tag/dns/POST/v2/cdn/dns/{domain_public_id}/records/)

Read the records first to get the `ETag`, then send it in `If-Match`:

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

**Proxied address**

```bash
curl -X POST "$DNS/records/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{
    "name": "shop",
    "type": "a",
    "value": "203.0.113.20",
    "proxied": true,
    "ttl": 300
  }'
```

**Mail server**

```bash
curl -X POST "$DNS/records/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{
    "name": "@",
    "type": "mx",
    "value": { "destination": "mail.example.com.", "priority": 10 },
    "ttl": 3600
  }'
```

**Text**

```bash
curl -X POST "$DNS/records/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{ "name": "_dmarc", "type": "txt", "value": "v=DMARC1; p=none" }'
```

The answer is `201` with the new record under `data`, and a new `ETag` header to use on your next write.

> **One proxied record per name**
> A second proxied record at the same name is refused with `409 RESOURCE_CONFLICT`. To balance traffic between several origins, keep one proxied record and add the origins at that name through the Network endpoints.

### Change a record

[`PATCH /v2/cdn/dns/{domain_public_id}/records/{record_id}/` in the API reference](https://docs.diamwall.com/api/#tag/dns/PATCH/v2/cdn/dns/{domain_public_id}/records/{record_id}/)

Send only the fields that change. A field you leave out keeps its value, and `value` is always sent whole.

```bash
curl -X PATCH "$DNS/records/6064981d2b888b2e7074/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{ "ttl": 600 }'
```

An empty body answers `400 NO_CHANGES`.

### Delete a record

[`DELETE /v2/cdn/dns/{domain_public_id}/records/{record_id}/` in the API reference](https://docs.diamwall.com/api/#tag/dns/DELETE/v2/cdn/dns/{domain_public_id}/records/{record_id}/)

```bash
curl -X DELETE "$DNS/records/6064981d2b888b2e7074/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "If-Match: $ETAG"
```

The zone always keeps at least one valid `ns` record at `@`. An edit or delete that would remove the last one answers `409 DNS_APEX_NS_REQUIRED` and writes nothing.

## SOA

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

The SOA record of the zone has nine fields: `contact`, `mname`, `serial` and six timings (`ttl`, `soa_ttl`, `refresh`, `retry`, `expire`, `negttl`).

```bash
curl "$DNS/settings/soa/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

Each field comes back as `{ "state": "resolved", "value": ... }`. A `state` of `unknown` means the CDN could not tell. Treat it as unavailable, never as `0` or `false`.

There are three ways to change the SOA:

| You want to | Call | Header it needs |
| --- | --- | --- |
| Apply a ready-made set of timings | `POST .../actions/soa-apply-profile/` | `Idempotency-Key` |
| Set individual timings | `PATCH .../settings/soa/` | `If-Match` |
| Make secondary name servers fetch the zone again | `POST .../actions/soa-bump-serial/` | `Idempotency-Key` |

### Apply a profile

[`POST /v2/cdn/dns/{domain_public_id}/actions/soa-apply-profile/` in the API reference](https://docs.diamwall.com/api/#tag/dns/POST/v2/cdn/dns/{domain_public_id}/actions/soa-apply-profile/)

The profiles are `low-latency`, `balanced`, `high-cache` and `migration`. `GET .../references/soa-profiles/` lists the timings each one applies. A profile never changes `contact`, `mname` or `serial`.

```bash
curl -X POST "$DNS/actions/soa-apply-profile/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: soa-profile-2026-11-22-a1" \
  -d '{ "profile": "balanced" }'
```

> **Idempotency-Key**
> Actions do not take `If-Match`. They take an `Idempotency-Key` that you make up: 16 to 128 characters, one key per intent. Sending the same key with the same body again within 24 hours does not run the action twice. You get the first answer back, with `idempotency_replayed: true`.

### Set individual timings

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

Read `settings/soa/` to get its `ETag`, then send at least one of the six timings:

```bash
curl -X PATCH "$DNS/settings/soa/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $SOA_ETAG" \
  -d '{ "refresh": 3600, "negttl": 120 }'
```

The allowed range of each timing is in the reference entry for this endpoint.

### Raise the serial

[`POST /v2/cdn/dns/{domain_public_id}/actions/soa-bump-serial/` in the API reference](https://docs.diamwall.com/api/#tag/dns/POST/v2/cdn/dns/{domain_public_id}/actions/soa-bump-serial/)

The body is exactly `{}`. A serial that was raised does not come back down, so do not repeat the request to make sure. The answer tells you what happened.

```bash
curl -X POST "$DNS/actions/soa-bump-serial/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: soa-serial-2026-11-22-b7" \
  -d '{}'
```

## Diagnostics

[DNS in the API reference](https://docs.diamwall.com/api/#tag/dns)

| Diagnostic | What it answers | Cost |
| --- | --- | --- |
| `GET .../diagnostics/dns-nameservers/` | The name servers the domain is delegated to, in `data.nameservers` | 8 credits |
| `GET .../diagnostics/dns-all/` | A lookup of the domain itself and of 39 common subdomains | 120 credits |

> **dns-all is expensive**
> Run `dns-all` only when a person asks for it. Never call it on a page load, on a timer or in a retry loop.

## Zone settings

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

`GET .../settings/dns/` is read-only. It answers three things about the zone as a whole:

- `dnssec_enabled`: whether DNSSEC is on.
- `records`: the published zone, as a map from name to record type.
- `proxied_records`: the names known to be proxied. The list may be incomplete.

## Limits and permissions

- **Credits.** Each domain has a budget of 3000 credits a minute, shared by everyone who calls the API for that domain. A DNS call costs 8 credits. Creating a record costs 16 on the Pro and Business plans, because the plan's record limit is read first. `dns-all` costs 120.
- **Out of credits.** The call answers `429 TOO_MANY_REQUESTS`, with the wait in `details.retry_after_seconds`.
- **Record limit.** A create beyond the plan's limit answers `400 PLAN_LIMIT_EXCEEDED`, with `details.limit` and `details.current`.
- **Permissions.** Reads need `dns.view` on the domain. Writes need `dns.create`, `dns.edit` or `dns.delete`.

## Errors you are likely to see

| Status | Code | What happened |
| --- | --- | --- |
| `400` | `INVALID_REQUEST` | A field is wrong. The answer names it in `fields`. |
| `400` | `NO_CHANGES` | An edit was sent with nothing to change. |
| `400` | `PLAN_LIMIT_EXCEEDED` | The zone is at the record limit of its plan. |
| `404` | `RESOURCE_ITEM_NOT_FOUND` | No record has that `id`. |
| `409` | `CURSOR_STALE` | The records changed while you were paging. Start from the first page. |
| `409` | `RESOURCE_CONFLICT` | There is already a proxied record at that name. |
| `409` | `DNS_APEX_NS_REQUIRED` | The write would remove the last name server of the domain. |
| `412` | `REVISION_MISMATCH` | The records changed since your read. Read again and retry. |
| `428` | | The `If-Match` header is missing. |
| `429` | `TOO_MANY_REQUESTS` | The domain is out of credits for now. |

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 DNS 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/dns) for every endpoint, with parameters and responses.
