Hi, i was struggling today what to do after transfer to new server, Adam told me to use api, and with little help of claude i have this simple script so im sharing maybe u will need it someday.
It will update your DNS records and in my case also add ipv6.
https://pastebin.com/mRT88hGC
import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
BASE_URL = "https://NEW_SERVER_IP:2087/api/v2"
API_TOKEN = "API_TOKEN"
ORG_ID = "ORG_ID_you-will-get-this-when-creating-token"
OLD_IP = "111111111111111"
NEW_IP = "222222222222222"
NEW_IPV6 = "dead::beef"
HEADERS = {
"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json",
}
def get(path):
r = requests.get(f"{BASE_URL}{path}", headers=HEADERS, verify=False)
r.raise_for_status()
return r.json()
def post(path, data):
r = requests.post(f"{BASE_URL}{path}", headers=HEADERS, json=data, verify=False)
r.raise_for_status()
return r
def patch(path, data):
r = requests.patch(f"{BASE_URL}{path}", headers=HEADERS, json=data, verify=False)
r.raise_for_status()
return r
print("Fetching websites...")
websites = get(f"/orgs/{ORG_ID}/websites?limit=100").get("items", [])
print(f"Found {len(websites)} website(s)\n")
for site in websites:
site_id = site["id"]
site_name = site.get("domain", {}).get("domain", site_id)
try:
domains_resp = get(f"/orgs/{ORG_ID}/websites/{site_id}/domains")
domains = domains_resp.get("items", [])
except Exception as e:
print(f" [{site_name}] Could not fetch domains: {e}")
continue
for domain in domains:
domain_id = domain["domainId"]
domain_name = domain.get("domain", domain_id)
try:
zone = get(f"/orgs/{ORG_ID}/websites/{site_id}/domains/{domain_id}/dns-zone")
records = zone.get("records", [])
except Exception as e:
print(f" [{domain_name}] Could not fetch DNS zone: {e}")
continue
has_new_ip_a = False
has_aaaa = False
for record in records:
rtype = record.get("kind", "")
rvalue = record.get("value", "")
rname = record.get("name", "@")
record_id = record["id"]
if rtype == "A" and rvalue == OLD_IP:
print(f" [{domain_name}] Updating A '{rname}': {OLD_IP} → {NEW_IP}")
try:
patch(f"/orgs/{ORG_ID}/websites/{site_id}/domains/{domain_id}/dns-zone/records/{record_id}", {
"kind": "A", "name": rname, "value": NEW_IP, "ttl": record.get("ttl", 3600)
})
print(f" ✓ A record updated")
has_new_ip_a = True
except Exception as e:
print(f" ✗ Failed: {e}")
if rtype == "A" and rvalue == NEW_IP: has_new_ip_a = True
if rtype == "AAAA" and rvalue == NEW_IPV6: has_aaaa = True
if has_new_ip_a and not has_aaaa:
print(f" [{domain_name}] Adding AAAA → {NEW_IPV6}")
try:
post(f"/orgs/{ORG_ID}/websites/{site_id}/domains/{domain_id}/dns-zone/records", {
"kind": "AAAA", "name": "@", "value": NEW_IPV6, "ttl": 3600
})
print(f" ✓ AAAA record added")
except Exception as e:
print(f" ✗ Failed: {e}")
print("\nDone.")