DNS API:et låter dig hantera DNS-poster programmatiskt via HTTP-anrop. Du kan använda det från scripts, automatiseringsverktyg eller egna applikationer.
Kontakta din administratör för att få en API-nyckel. Nyckeln är personlig och ska hållas hemlig.
Alla API-anrop:
Base URL: https://tools.tornevall.net/api
curl https://tools.tornevall.net/api/dns/zones \
-H "Authorization: Bearer DIN_API_NYCKEL"
curl https://tools.tornevall.net/api/dns/zones \
-H "X-API-Key: DIN_API_NYCKEL"
curl https://tools.tornevall.net/api/dns/zones?api_key=DIN_API_NYCKEL
GET /api/dns/zones
Exempel:
curl https://tools.tornevall.net/api/dns/zones \
-H "Authorization: Bearer DIN_API_NYCKEL"
Svar:
{
"ok": true,
"count": 5,
"zones": [
{
"zone": "example.com",
"file": "example.com/example.com",
"key": "example.com"
},
{
"zone": "test.se",
"file": "test.se/test.se",
"key": "test.se"
}
],
"is_admin": false,
"access_type": "authenticated"
}
GET /api/dns/zones/{zone}
Exempel:
curl https://tools.tornevall.net/api/dns/zones/example.com \
-H "Authorization: Bearer DIN_API_NYCKEL"
Svar:
{
"ok": true,
"zone": "example.com",
"method": "AXFR",
"record_count": 12,
"zoneData": [
{
"name": "example.com",
"type": "A",
"rdata": "192.0.2.1",
"ttl": 3600,
"class": "IN"
},
{
"name": "www.example.com",
"type": "A",
"rdata": "192.0.2.1",
"ttl": 3600,
"class": "IN"
}
]
}
POST /api/dns/records/add
Content-Type: application/json
{
"domain": "test.example.com",
"type": "A",
"target": "192.0.2.1",
"ttl": 3600
}
Exempel:
curl -X POST https://tools.tornevall.net/api/dns/records/add \
-H "Authorization: Bearer DIN_API_NYCKEL" \
-H "Content-Type: application/json" \
-d '{
"domain": "test.example.com",
"type": "A",
"target": "192.0.2.1",
"ttl": 3600
}'
Svar (framgång):
{
"ok": true,
"message": "✓ Update successful (via DnsDirect)",
"domain": "test.example.com",
"type": "A",
"target": "192.0.2.1",
"ttl": 3600
}
Svar (fel):
{
"ok": false,
"reason": "validation_failed",
"errors": {
"target": ["The target field is required."]
}
}
POST /api/dns/records/delete
Content-Type: application/json
{
"domain": "test.example.com",
"type": "A"
}
Exempel:
curl -X POST https://tools.tornevall.net/api/dns/records/delete \
-H "Authorization: Bearer DIN_API_NYCKEL" \
-H "Content-Type: application/json" \
-d '{
"domain": "test.example.com",
"type": "A"
}'
Svar:
{
"ok": true,
"message": "✓ Update successful (via DnsDirect)",
"domain": "test.example.com",
"type": "A"
}
POST /api/dns/records/update
Content-Type: application/json
{
"domain": "test.example.com",
"type": "A",
"old_target": "192.0.2.1",
"new_target": "192.0.2.100",
"ttl": 3600
}
Exempel:
curl -X POST https://tools.tornevall.net/api/dns/records/update \
-H "Authorization: Bearer DIN_API_NYCKEL" \
-H "Content-Type: application/json" \
-d '{
"domain": "test.example.com",
"type": "A",
"old_target": "192.0.2.1",
"new_target": "192.0.2.100",
"ttl": 3600
}'
Lägg till eller ta bort flera poster samtidigt:
POST /api/dns/records/bulk
Content-Type: application/json
{
"operations": [
{
"action": "ADD",
"domain": "test1.example.com",
"type": "A",
"target": "192.0.2.1",
"ttl": 300
},
{
"action": "DELETE",
"domain": "test2.example.com",
"type": "A"
}
]
}
Exempel:
curl -X POST https://tools.tornevall.net/api/dns/records/bulk \
-H "Authorization: Bearer DIN_API_NYCKEL" \
-H "Content-Type: application/json" \
-d '{
"operations": [
{"action":"ADD","domain":"test1.example.com","type":"A","target":"192.0.2.1","ttl":300},
{"action":"ADD","domain":"test2.example.com","type":"A","target":"192.0.2.2","ttl":300}
]
}'
{
"domain": "www.example.com",
"type": "A",
"target": "192.0.2.1",
"ttl": 3600
}
{
"domain": "www.example.com",
"type": "AAAA",
"target": "2001:db8::1",
"ttl": 3600
}
{
"domain": "blog.example.com",
"type": "CNAME",
"target": "example.com.",
"ttl": 3600
}
OBS: Target måste sluta med punkt!
{
"domain": "example.com",
"type": "MX",
"target": "10 mail.example.com.",
"ttl": 3600
}
{
"domain": "example.com",
"type": "TXT",
"target": "v=spf1 include:_spf.google.com ~all",
"ttl": 3600
}
{
"domain": "subdomain.example.com",
"type": "NS",
"target": "ns1.provider.com.",
"ttl": 3600
}
#!/bin/bash
API_KEY="din-api-nyckel"
DOMAIN="home.example.com"
CURRENT_IP=$(curl -s ifconfig.me)
# Uppdatera A-record
curl -X POST https://tools.tornevall.net/api/dns/records/add \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"domain\": \"$DOMAIN\",
\"type\": \"A\",
\"target\": \"$CURRENT_IP\",
\"ttl\": 300
}"
echo "Updated $DOMAIN to $CURRENT_IP"
import requests
API_KEY = "din-api-nyckel"
BASE_URL = "https://tools.tornevall.net/api"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# Lägg till post
def add_record(domain, record_type, target, ttl=3600):
data = {
"domain": domain,
"type": record_type,
"target": target,
"ttl": ttl
}
response = requests.post(
f"{BASE_URL}/dns/records/add",
headers=headers,
json=data
)
return response.json()
# Ta bort post
def delete_record(domain, record_type):
data = {
"domain": domain,
"type": record_type
}
response = requests.post(
f"{BASE_URL}/dns/records/delete",
headers=headers,
json=data
)
return response.json()
# Användning
result = add_record("test.example.com", "A", "192.0.2.1")
print(result)
const API_KEY = 'din-api-nyckel';
const BASE_URL = 'https://tools.tornevall.net/api';
async function addDnsRecord(domain, type, target, ttl = 3600) {
const response = await fetch(`${BASE_URL}/dns/records/add`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ domain, type, target, ttl })
});
return await response.json();
}
// Användning
addDnsRecord('test.example.com', 'A', '192.0.2.1')
.then(result => console.log(result))
.catch(error => console.error(error));
<?php
$apiKey = 'din-api-nyckel';
$baseUrl = 'https://tools.tornevall.net/api';
function addDnsRecord($domain, $type, $target, $ttl = 3600) {
global $apiKey, $baseUrl;
$data = [
'domain' => $domain,
'type' => $type,
'target' => $target,
'ttl' => $ttl
];
$ch = curl_init("$baseUrl/dns/records/add");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $apiKey",
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Användning
$result = addDnsRecord('test.example.com', 'A', '192.0.2.1');
var_dump($result);
{
"ok": false,
"reason": "permission_denied",
"message": "No permission for zone: example.com"
}
Vanliga fel:
unauthenticated: Ogiltig eller saknad API-nyckelpermission_denied: Saknar access till zonvalidation_failed: Felaktiga parametrarzone_not_found: Zonen finns inteX-RateLimit-Remaining visar återstående anropRetry-After header✅ Gör:
❌ Gör INTE:
Om API-nyckel har läckt:
Version: 1.0
Senast uppdaterad: 2026-02-16