Change the DNS of your domain from your own scripts - e.g. for domain verification with other services, a change of IP address or automatic setup.
With the DNS API a program can add, change and delete these records on your domain:
_sip._tls), Minecraft and other servicesName servers, DKIM, the standard mail SRV records and free text cannot be changed through the API - they are changed in the DNS manager in the control panel as before.
Changes are saved exactly as when you save in the DNS manager and are sent to the name servers automatically. It usually takes a few minutes before a change can be seen on the internet.
In the same window you can:
192.0.2.10, 198.51.100.0/24. Empty field = all.The DNS API line is only shown when the domain uses our DNS manager (our name servers) and the DNS API has been opened for the domain. Contact support if you would like it opened.
All addresses start with:
https://www.webhosting.dk/cgi-bin/dnsapi.pl/v1
The key is sent in the header (either of them):
Authorization: Bearer YOUR-KEY
X-Api-Key: YOUR-KEY
Data is sent and received as JSON. The answer always has "ok": true or "ok": false; on errors also "error" (a code) and "message" (an explanation). The explanations are in English; send the header Accept-Language: da to get them in Danish.
The name of a record can be written in several ways - they all mean the same:
| You write | Means (for example.dk) |
|---|---|
@ or empty | example.dk (the domain itself) |
www | www.example.dk |
www.example.dk or www.example.dk. | www.example.dk |
_verify.shop | _verify.shop.example.dk |
| Method | Address | What |
|---|---|---|
| GET | /records | All records |
| POST | /records | Add or change one record |
| DELETE | /records | Delete one record |
| POST | /spf | Add or remove a part of SPF |
| POST | /batch | Up to 20 changes - all or none |
| POST | /undo | Undo the latest API change |
| GET | /changes | The latest 20 API changes |
| GET | /status | Serial number, and whether the change has been sent to the name server |
| GET | /check?name=…&type=… | What the name server answers right now |
curl -H "Authorization: Bearer YOUR-KEY" \
https://www.webhosting.dk/cgi-bin/dnsapi.pl/v1/records
Answer (shortened):
{
"ok": true,
"domain": "example.dk",
"version": "5dfb3e05d2e3c3c9d38298565fcefc41",
"records": [
{"name": "@", "fqdn": "example.dk", "type": "A", "value": "192.0.2.10"},
{"name": "www", "fqdn": "www.example.dk", "type": "A", "value": "192.0.2.10"},
{"name": "@", "fqdn": "example.dk", "type": "MX", "value": "mail1.webhosting.dk.", "priority": 10},
{"name": "@", "fqdn": "example.dk", "type": "TXT","value": "v=spf1 a mx ~all"}
],
"limits": {"txt_used": 1, "txt_max": 6, "mx_used": 1, "mx_max": 10},
"not_in_api": {"dkim": 1, "srv": 0, "free_text": 0}
}
version changes every time the DNS is changed - see section 11. not_in_api shows how many records exist that can only be changed in the DNS manager.
curl -X POST -H "Authorization: Bearer YOUR-KEY" \
-d '{"type":"A","name":"test","value":"192.0.2.20"}' \
https://www.webhosting.dk/cgi-bin/dnsapi.pl/v1/records
| Field | Description |
|---|---|
type | A, AAAA, CNAME, MX, TXT or SRV |
name | The name, see section 4. MX only on the domain itself (@). SRV: _service._protocol, e.g. _sip._tls. |
value | IP address, host name or text. SRV: "priority weight port target", e.g. "100 1 443 sipdir.online.lync.com" |
priority | MX, 0-32767 (default 10) - or SRV, if value is only "weight port target" |
If an A, AAAA or CNAME already exists on the name, it is changed. TXT and MX are added next to the existing ones. An SRV with the same name and target gets its numbers changed; otherwise it is added.
If exactly the same record already exists, the API answers "ok": true, "changed": false - so it is safe to send the same change again.
The answer shows what was changed, and any warnings:
{
"ok": true, "changed": true, "change_id": 12,
"changes": [{"op": "add", "record": "test.example.dk A 192.0.2.20"}],
"warnings": [],
"version": "81178d68cf6a8c10ba113bf0f85972d7"
}
# IPv6 on www (www must already have an A record)
{"type":"AAAA","name":"www","value":"2001:db8::10"}
# CNAME
{"type":"CNAME","name":"shop","value":"shops.myshopify.com"}
# MX with priority
{"type":"MX","name":"@","value":"mx2.example.net","priority":20}
# TXT - domain verification
{"type":"TXT","name":"@","value":"google-site-verification=abc123"}
# DMARC (replaces an existing DMARC record)
{"type":"TXT","name":"_dmarc","value":"v=DMARC1; p=quarantine; rua=mailto:dmarc@example.dk"}
# SRV - Microsoft 365 / Teams
{"type":"SRV","name":"_sip._tls","value":"100 1 443 sipdir.online.lync.com"}
# SRV - Minecraft on port 25565
{"type":"SRV","name":"_minecraft._tcp","value":"0 5 25565 mc.example.dk"}
curl -X DELETE -H "Authorization: Bearer YOUR-KEY" \
-d '{"type":"TXT","name":"_verify","value":"abc123"}' \
https://www.webhosting.dk/cgi-bin/dnsapi.pl/v1/records
value matches exactly.value must say which one (the host name).value must give the target (the host name).@) cannot be deleted - only changed.not_found (HTTP 404).A domain may only have one SPF record. So you add and remove parts of it instead of creating a new one:
# add Google Workspace
curl -X POST -H "Authorization: Bearer YOUR-KEY" \
-d '{"action":"add","value":"include:_spf.google.com"}' \
https://www.webhosting.dk/cgi-bin/dnsapi.pl/v1/spf
# remove it again
-d '{"action":"remove","value":"include:_spf.google.com"}'
You can also give an IP address (192.0.2.10 becomes ip4:192.0.2.10) or a domain (mailgun.org becomes include:mailgun.org). If the domain has no SPF, one is created with v=spf1 a mx … ~all.
The SPF record may make at most 10 DNS lookups and be at most 255 characters - otherwise the change is refused.
Up to 20 changes in one call. Either all are saved, or none - if one fails, nothing is changed, and the answer tells you which one ("index", counted from 0).
curl -X POST -H "Authorization: Bearer YOUR-KEY" \
-d '{"changes":[
{"op":"add", "type":"A", "name":"test", "value":"192.0.2.20"},
{"op":"delete", "type":"TXT", "name":"@", "value":"old-verification"},
{"op":"spf_add","value":"include:_spf.google.com"}
]}' \
https://www.webhosting.dk/cgi-bin/dnsapi.pl/v1/batch
op can be add, delete, spf_add and spf_remove.
Add ?dry_run=1 to the address (or "dry_run": true in the JSON), and the API shows what would be changed, without saving anything:
curl -X POST -H "Authorization: Bearer YOUR-KEY" \
-d '{"type":"CNAME","name":"www","value":"example.netlify.app"}' \
"https://www.webhosting.dk/cgi-bin/dnsapi.pl/v1/records?dry_run=1"
The answer has "dry_run": true and the list of changes - e.g. that the A record on www would be deleted and replaced by the CNAME.
Fetch the records, and send the version you got with your change. If the DNS has been changed in the meantime (in the control panel or by another script), the change is refused with version_conflict (HTTP 409), and you can fetch the records again.
curl -X POST -H "Authorization: Bearer YOUR-KEY" \
-H 'If-Match: 5dfb3e05d2e3c3c9d38298565fcefc41' \
-d '{"type":"A","name":"@","value":"192.0.2.30"}' \
https://www.webhosting.dk/cgi-bin/dnsapi.pl/v1/records
Instead of the header you can send "if_version": "…" in the JSON.
curl -X POST -H "Authorization: Bearer YOUR-KEY" \
https://www.webhosting.dk/cgi-bin/dnsapi.pl/v1/undo
Undoes the latest change made through the API. Call again to go one more change back. To be sure you undo exactly your own change, send its number: {"change_id": 12} (change_id from the answer to the change) - if a newer change has been made since, it is refused.
It only works if the DNS has not been changed in another way since - otherwise the answer is changed_since. Use ?dry_run=1 to see what would be undone.
GET /changes shows the latest 20 changes with time and IP address.
{"ok": true, "domain": "example.dk", "serial": "2026112305",
"pending": true, "zone_ok": true, "primary_ns": "ns1pri.webhosting.dk", "version": "…"}
pending: true means the change is waiting to be picked up by the name server.
Asks our primary name server what it answers right now - handy for waiting until a record is active:
curl -H "Authorization: Bearer YOUR-KEY" \
"https://www.webhosting.dk/cgi-bin/dnsapi.pl/v1/check?name=_verify&type=TXT"
{"ok": true, "name": "_verify.example.dk", "type": "TXT",
"server": "ns1pri.webhosting.dk", "answers": ["abc123"]}
. = the service does not exist).@). If a CNAME is created on a name with an A record, it replaces the A record." and \.| HTTP | error | Means |
|---|---|---|
| 400 | rejected | The change is not allowed - see message |
| 400 | bad_json | The content is not valid JSON |
| 400 | too_many | More than 20 changes in one batch |
| 401 | no_key | The key is missing in the header |
| 401 | bad_key | Wrong key, or the API is switched off |
| 403 | ip_not_allowed | The call comes from an IP address that is not allowed |
| 403 | adminlock | Admin lock is switched on for the domain |
| 403 | inactive | The domain is not active |
| 403 | https_only | Use https |
| 404 | not_found | The record to be deleted does not exist |
| 404 | no_dns | The domain does not use our DNS manager |
| 404 | nothing_to_undo | No API change to undo |
| 409 | version_conflict | The DNS has changed since the version you sent |
| 409 | ambiguous | Several records match - give value |
| 409 | changed_since | Cannot be undone, the DNS has changed since |
| 409 | not_newest | The change you gave with change_id is not the newest - undo the newer ones first |
| 409 | busy | Another change is in progress - try again |
| 429 | rate_limit | Too many calls - wait a minute |