Tutorial: How to Update DNS Records Using the GoDaddy API – Domain Name Wire

Alvin Brown provides a tutorial on using GoDaddy’s API to retrieve and update DNS records for a given domain with the specified type and name.

Lately, I’ve been experimenting with listing domain names for sale from my GoDaddy account using Sedo, one of the domain industry’s largest marketplaces for buying and selling domains.

Although adding my domains to their listing was fairly trivial, I quickly saw how cumbersome Sedo’s ownership verification process was for each domain.

Verifying ownership is probably not a problem when you’re only listing a handful of domains at a time. Just add a DNS record for each domain at your domain registrar, and that’s it.

However, if you add more than 5 domains to Sedo, you will need to rethink how you go through Sedo’s ownership verification process.

Most people opt for bulk nameserver updates for bulk domains entered into their Sedo account. But what about those of us who don’t care to change nameserver settings or don’t want to park our domains with Sedo?

Today’s tutorial will help answer that question by explaining how to use GoDaddy’s API to update a given domain’s DNS records with Type and Last name.

By the end of this tutorial, I hope you will be able to create your own bulk update tool for Sedo ownership verification if your domains are managed by GoDaddy.

Get started with the GoDaddy API

Before I dive into the details, I won’t spend much time, if at all, on getting started with GoDaddy’s API.

If you’re new to using GoDaddy’s Developer Portal and API, I recommend checking out the following resources:

Let’s start!

Ways to Add and Replace GoDaddy DNS Records

As shown in the image below, a number of methods are shown to add and replace DNS records for a given GoDaddy domain using the API.

This tutorial focuses on the following method (as shown below in the image) to replace all DNS records for the specified Domain with the specified Type and Last name.

GoDaddy API - PUT method for DNS record change

I chose this method because Sedo’s ownership verification requires a SMS Where CNAME the record must be created using a verification ID provided by Sedo.

Sedo how to verify your property yourself

Today’s tutorial shows you how to add a SMSalthough you can easily switch to CNAME also, register on a domain managed by GoDaddy for Sedo to verify your ownership.

Configuring Required and Optional Variables

Open a text editor, name and save the following file: logger-dns.php.

The first action is to create a variable (i.e., $domains) containing an array (i.e., see examples below) of your GoDaddy domains listed or soon to be listed on Sedo.

$domains = array(
“mckinneydigital.com”, “dallasdigital.com”, “austindigital.com”
);

If there is only one domain, the code would look like this:

$domains = array(
“mckinneydigital.com”
);

Then create a for each statement to iterate over each of the array values ​​in the $domains variable. The for each ensures that a DNS record is added to each domain instead of just the first domain.

foreach($domains as $domain){

//additional code here

}

Within the for each statement, your GoDaddy API credentials should be set as variables along with the domain and DNS record variables needed and their respective values.

It is essential to add your respective API key and secret, otherwise this tutorial is dead in the water.

Regarding the definition of variables for DNS records, the following variables and their values ​​must be defined:

$dns_domain – using PHP strtolower method, skip it $domain variable as an argument, which ensures that all fields are lowercase.

$dns_type – set the value to SMS Where CNAME; additional values ​​are: Name server, A, MX, SRV, AAAA, CAA.

$dns_name – set the value to @.

$dns_data – set the data value to your Sedo verification ID.

$dns_port – set port value to 80 Where 443.

$dns_priority – set priority value to ten or an increment of 5.

$dns_protocol – set a protocol string value; set to ‘string of characters’ for this tutorial because it is not necessary.

$dns_service – set a service string value; set to ‘string of characters’ for this tutorial because it is not necessary.

$dns_ttl – set the value until it is 600 or one of the following: 1/2 Hour, 1 Hour, 12 Hours, 1 Day, 1 Week, Custom.

$dns_weight – set this value to ten or an increment of 5.

With the aforementioned variables set and values ​​set, set and set the value of one last variable: $dns_records.

The $dns_records variable contains the last seven variables as a json object or string (see below).

$dns_records = “[{”data”: ”$dns_data”,”port”: $dns_port,”priority”: $dns_priority,”protocol”: ”$dns_protocol”,”service”: ”$dns_service”,”ttl”: $dns_ttl,”weight”: $dns_weight}]”;

Make the call to add a DNS record

With the necessary variables and values ​​defined, we are now ready to instantiate the GoDaddy API call to add the DNS record using a user-defined function named addDNSRecord.

Define a named variable results and set it equal to addDNSRecord. This addDNSRecord The function does the heavy lifting of making the GoDaddy API call by passing the following four variables as arguments in their respective order: $dns_domain, $dns_type, $dns_name, and $dns_record.

$results = addDNSRecord($dns_domain, $dns_type, $dns_name, $dns_records);

Error checking addDNSRecord function

The last step in this tutorial is to add some error checking. While you can choose to dive deeper into providing more detail, I’ve chosen to display a simple success or failure text message based on whether or not the results variable returns a value.

if(!$results){
echo “All is well in Hollywood for the following domain: $dns_domain
“;
} other {
echo “Houston, we have a problem with the following domain: $dns_domain!” ;
}

If a value is returned during the API call, the success message is displayed and reads as follows:

All is well in Hollywood for the following domain:

If the API call is made in error, the failure message is displayed and reads as follows:

Houston, we have a problem with the following domain:

If the API call is successful, you should be able to view the newly added DNS record containing the Sedo verification ID for your respective domains in GoDaddy’s domain manager.

When assembling the code in its entirety, not including the functions section for addDNSRecordthere are about 40 lines of code.

GoDaddy API DNS Records Editing Tutorial Code

And that’s all there is to this tutorial.

addDNSRecord function

The addDNSRecord The function is the only function that does the heavy lifting for adding DNS records to a given domain.

addDNSRecord - GoDaddy API function

One thing to note is the following GoDaddy API URL used:

https://api.godaddy.com/v1/domains/$DNS_domain/records/$DNS_type/$DNS_name

GoDaddy API URL - PUT method for modifying DNS record

Also, this tutorial uses the PUT request method unlike previous tutorials which used the GET and POST request methods.

You can probably use this function in the future and just make minor changes to the URL value and request type variables.

Final Thoughts

I encourage you to download the tutorial code, make any necessary changes, and see where this tool takes you.

DOWNLOAD dns-recorder.zip for GoDaddy Domains API

This tutorial can easily be modified to add a simple HTML form interface probably using Bootstrap or basic HTML5.

Feel free to leave comments if you have any questions or encounter any technical difficulties while implementing the tutorial.

Thanks and that’s all for now!