Code snippet for new Hetzner DNS API (11/2025+)

Here is a short code snippet how I update Hetzner DNS with the new API starting 11/2025.

:local HOST "router"
:local DOMAIN "example.com”
:local IPv4 "1.2.3.4"

:local TTL 60
:local APITOKEN "ARKiFdJVIM...SZV0kS7Eo"

...

    # update Hetzner IPv4 address
    :do {
      /tool fetch \
        http-method=delete \
        http-header-field="Authorization: Bearer $APITOKEN" \
        url="https://api.hetzner.cloud/v1/zones/$DOMAIN/rrsets/$HOST/A" \
        as-value output=user
    } on-error= {}

    /tool fetch \
      http-method=post \
      http-header-field="Authorization: Bearer $APITOKEN,Content-Type: application/json" \
      http-data="{\"name\":\"$HOST\",\"type\":\"A\",\"ttl\":$TTL,\"records\":[{\"value\":\"$IPv4\"}]}" \
      url="https://api.hetzner.cloud/v1/zones/$DOMAIN/rrsets" \
      as-value output=user 
1 Like