Improvements to DNS API

July 3rd, 2012 by

All Mythic Beasts domain registrations include access to our DNS service, which includes a number of powerful features.  One of these is an API that allows you to programmatically make changes to the DNS records for your domain.  This has a number of uses including:

  • Automating DNS-based failover
  • Scripting the redirection of requests to another server to display a holding message during maintenance periods
  • Implementing “dynamic DNS” so that you can have a static hostname for a dynamically allocated IP address

The DNS API provides a simple, HTTP-based API, that is designed to be trivial to script.  We’ve recently made some improvements to the API.  The first is that where multiple commands are included in a single request, they are treated as an atomic transaction, meaning that they either all succeed or all fail, and there is no risk of the changes being made live with only some of the commands completed.  This means that you can change a DNS record by including a DELETE and an ADD command in a single request.

The other change is that the API now makes use of HTTP error codes to reflect the results of the transaction.  If you get a 200 response, all of the commands succeeded.  If you get anything else, then none of the commands will take effect.

You can find full details of the API, including some sample Perl code on our support pages. It’s also pretty easy to script it on the command line. Here’s an example of how to change a CNAME record using cURL:

curl --data 'domain=example.com&password=s3cr3t&command=DELETE www 86400 CNAME live.example.com.&command=DELETE www 86400 CNAME backup.example.com.'   https://secure.mythic-beasts.com/control/fcgi/customer/primarydnsapi