Change DNS records in bulk
Create Edge DNS records from a JSON file, then update and delete many records of a zone, with shell loops over the Azion API v4.
You can create, update, and delete many Edge DNS records of a zone with shell loops over the Azion API v4. The records endpoint takes one record per request, so each loop sends one request per record. To add, edit, or delete a single record from Azion Console, the CLI, or the API, refer to Add, edit, or delete a record.
Prerequisites
- A personal token. To create one, refer to Manage personal tokens.
- Permission to edit Edge DNS. Refer to Teams permissions.
curl, to call the API, andjq, to read the records file and the API responses.- A zone in Edge DNS. To create one, refer to Create a zone. The examples use a zone for the domain
example.org.
Find the ID of the zone
Every record path carries the ID of its zone.
To find the ID of the zone:
-
Store your token in a shell variable. Replace the value with your token:
-
Search the zones for your domain. Replace the domain with your own:
ShellJSON -
Store the
idof the zone whosedomainis yours. Replace the value with thatid, or the shell refuses the line:
ZONE_ID holds the ID of the zone, and every request in this guide reads it.
Create records from a file
A JSON file holds one object per record. Each object needs name, type, and rdata, and this file also sets ttl, which defaults to 3,600 seconds. An ANAME record takes a ttl of 20 only, so its object sets "ttl": 20. For the value format of each record type, refer to Record types.
To create the records:
-
Create a
records.jsonfile with the records. Replace the names and values with your own:records.json -
Send one
POSTrequest per record. The loop prints one line per record, with the name and type from the file. Theerrorsfield of the line holds the error when the API refuses the record, andnullotherwise. Replace[TOKEN VALUE]and<your-zone-id>with your own values:ShellText
The zone holds one record per object of the file. A refused record does not stop the loop: its line carries the error, and the next record is sent.
You can run the loop again after you fix a refused record. A name and type hold one record with the simple policy, the default.
A second one is refused with code 19004, Record Already Exists. For a second CNAME with the same name, the code is 19014, CNAME Record Name Conflict. On a second run of the same file, the loop prints:
Weighted records can share a name and type, so the API accepts a second one. Before you run the loop again, remove the weighted records that already exist from the file.
A name that a resolver queried before its record existed is answered NXDOMAIN for up to one hour. To fix it, refer to A new record returns NXDOMAIN.
Update several records
A loop lists the records, selects the ones to change with jq, and sends one PATCH request to each. A PATCH body carries only the fields to change, so every other field of the record keeps its value.
Set the time to live (TTL) of every A record of the zone to 600 seconds. Replace [TOKEN VALUE] and <your-zone-id> with your own values:
Every A record of the zone has a TTL of 600 seconds, and its other fields keep their values.
A changed record can take a few minutes to reach every nameserver. Resolvers then keep the old value until its TTL runs out.
Delete several records
A loop lists the records, selects every record with a given name, whatever its type, and sends one DELETE request to each.
To delete the records named api and shop:
-
List the records named
apiandshopbefore you delete them. Replace[TOKEN VALUE]and<your-zone-id>with your own values:ShellText -
Delete the records that the list shows. Replace
[TOKEN VALUE]and<your-zone-id>with your own values:ShellText
Check the records that remain in the zone. Replace [TOKEN VALUE] and <your-zone-id> with your own values:
The zone no longer holds the records named api and shop.