Dynadot

tips Domainers: Simply your life with the GoDaddy API

NameSilo
Watch

Kate

Domainosaurus RexTop Member
Impact
21,788
OK, probably there is not one real domainer one the planet who doesn't have an account at Godaddy, or hasn't had to deal with that registrar at one time. Chances are, even if you dislike them you have a number of domains registered with them because they were acquired at auctions or otherwise.
I am not really a fan of their interface, I find that I am wasting too much time performing simple but tedious steps.

In spite of their poor UI (imo) they have an API that is readily available to you, provided that you have enough technical knowledge. You do not have to put up with their UI really, you can automate maintenance with remote calls instead.

So here is the deal: I will now show you how to take advantage of their API in order to save time on domain name management.
Here are two features that I developed for an immediate need:
  1. Set name servers
  2. Retrieve EPP codes
Feature #1: set name servers

One of my pet peeves is that when you win a closeout domain it is configured to use Godaddy name servers. If you want to park the domain, you have to log in every time to set the name servers. A pain isn't it ?
As far as I know you cannot define default name servers, which is a shame.
Answer: use the API

Feature #2: get EPP codes for transfer

I normally consolidate domains to another registrar, so I will transfer names before they expire. For this you need to unlock the domain, and the EPP code.
Answer: use the API

I made a little script to implement these two features, it is attached in this thread.
The script is written in bash for Linux and there are no particular dependencies but you need to have the magical tool Curl installed on your system. Type curl in the command line to check. Most developers should already be familiar with it. It ships with many if not most Linux distros. If you don't have it, installing is as easy as:
Code:
apt-get install curl
(as root)
Or yum, dnf or pacman depending on your flavor of Linux.

If you are stuck on Windows, the code can still be ported. It should be easy to reuse the Curl snippets in Powershell for example.
Or you could set up a Linux virtual machine with Virtualbox or VMware to try out the code. A VPS on Linux is another possibility.
I apologize in advance for the average quality of this code, I spent only a few hours on it, and this is more a proof of concept than a complete solution. But it is very compact: less than 100 lines :)

First of all go to: https://developer.godaddy.com/

I recommend that you read up a bit the intro and the documentation to get acquainted with the possibilities.

Then click on Getting Access to generate API keys for your own use.
You will get two Key/Secret pairs, one to use on a test environment, and one to use on production servers.

Setting up a payment method is not required, because we will not performing financial operations.

Now that you have your own key pair, you are ready to go.

You need to adapt the script and enter the secret keys you've just obtained:
Code:
key="<your key goes here>" # key API
secret="<your key goes here>" # secret for API
You enter the production keys.

Also, enter your preferred name servers, for example:
Code:
name_servers="ns1.sedoparking.com,  ns2.sedoparking.com"
At least 2 NS are required, separated with a comma, whitespace optional.

When you are done editing the file, one final step:
Code:
chmod +x gdapi.sh
(to make the script executable)

Now run the script from the command line like this:
Code:
./gdapi.sh
or:
Code:
./gdapi.sh <domain>

(This is assuming the script is in the current directory)
If you do not provide a domain name as parameter, you will be prompted for one.

The menu is very simple and looks like this:

Choose an option:
1) Change domain name (current: yourdomain.com)
2) Get domain info incl. EPP code
3) Set name servers, unlock and disable auto-renew
4) Exit


1: change the current domain you will be working on.

2. output domain information in XML format, basically you get the contacts assigned to the domain plus extra info such as EPP code, autorenew and lock settings etc. Like an augmented whois record.
This option will also extract the EPP code for you.

3. Update domain name: this option performs several steps in one shot:
  • disable auto-renew
  • unlock the domain
  • set default name servers of your choice
Technical details
  • In this example, requests are sent in JSON format but responses are requested in XML format. It's a matter of preference, but parsing will differ depending on which one you choose.
  • Again, you need to have Curl installed on your system (available for nearly every platform). The script doesn't check whether Curl is installed.
  • There is no validation of the domain name
  • Obviously, you can only perform actions on domain names that belong to you
  • I have not tested with ccTLDs, only .com/.net. EPP-compliant ccTLDs should be OK.
In practice

The API is HTTP-based and returns standard HTTP codes. 200 means OK, 404 is self-explanatory: the URL is wrong.
Other possible codes include 204 (OK but no content returned).
I also have stumbled on:
Code:
HTTP/1.1 409 Conflict
{"code":"INELIGIBLE_DOMAIN","message":"The domain was not purchased with a subaccount","name":"ApiError"}
But the call otherwise succeeded. So I am not sure if I am doing something wrong or if it is a bug.

Finally...
  • Do not abuse the privilege, and overload Godaddy servers with useless traffic
  • Requests tend to run slowly (and are probably deliberately throttled), so this script is probably not a good option for dropcatching
  • NB: to the best of my knowledge the API does not grant access to the auctions
License: there isn't any but if you distribute the code, a link back to the source (this forum thread) is appreciated.
The code is provided as-is, with no guarantees.

Code

Code:
#!/bin/bash

# Constants
api_url="https://api.godaddy.com/v1/"

# Your API keys
key="" # key API
secret="" # secret for API

# comma-separated list of name servers, spaces allowed
# at least 2 name servers are required
name_servers="ns1.sedoparking.com,  ns2.sedoparking.com"

headers="Authorization: sso-key $key:$secret"


# if the domain name was not provided in parameter
if [ -z $1 ]; then
    echo -n "Enter domain name: "
    read domain
else
    domain=$1
fi

if [ -z $domain ]; then
    echo "Domain name may not be blank, exit"
    exit 1
fi

while true; do
    options=("Change domain name (current: $domain)" "Get domain info incl. EPP code" "Set name servers, unlock and disable auto-renew" "Exit")

    echo -e "\nChoose an option: "
    select opt in "${options[@]}"; do
        case $REPLY in
            1) domain=""
            while [ -z $domain ]; do
                echo -n "Enter domain name: "
                read domain
            done
        break ;;

            2) echo "Fetching domain info ($domain)..."

            # send query
            result=$(curl --silent --include -X GET -H "$headers" -H "Content-Type: application/json" -H "Accept: text/xml" "$api_url/domains/$domain")
            # uncomment below to see Curl response
            echo "$result"
            # extract EPP code from XML response
            epp_code=$(echo $result | grep -Po '<authCode>.*</authCode>' | sed 's/<\/*authCode>//g')
            echo -e "\nEPP code: $epp_code\n"
        break ;;

            3) echo "Set name servers, unlock domain name and disable auto-renew ($domain)...";
            # parse list of name servers (build list)
            ns_list=$(echo "$name_servers" | sed 's/,\s*/", "/g')

            request="{ \"locked\": false, \"nameServers\": [ \"$ns_list\" ], \"renewAuto\": false, \"subaccountId\": \" \" }"

            # send request
            result=$(curl --silent --include -X PATCH -H "$headers" -H "Content-Type: application/json" -H "Accept: text/xml" -d "$request" "https://api.godaddy.com/v1/domains/$domain")
            echo "$result"
        break ;;

            4) exit 0;
        break ;;

        *) echo "Invalid option"
        ;;
        esac
    done
done
 

Attachments

  • gdapi.sh.zip
    1 KB · Views: 258
15
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Thanks Kate, very useful post!
 
0
•••
I did not know they had an API! Nice. I might poke at that.
I too hate their UI. It's like 4 different company websites depending on what you click on.

Cheers
 
0
•••
Wow @Kate my hat is off to you, I totally agree that everyone has a godaddy account and everyone has a few beefs against it.

What a great great post (y)(y)(y)(y)(y)

Unfortunately my biggest beef with godaddy cannot be solved with any script. Even with the discount club they are still higher priced than my standard registrar. I think I have 3-4 domains with them just to keep the account active. I found a neat place where I can go for my domains that I now bypasses the whole godaddy auction thing and I am having a grand time registering domains that meet my criteria. No more bidding, winning and then having the domain not show up in my account.

That said, if they ever straighten up their act and aggressively try to get the domainers business I will surely come back to this topic to implement your scripts.

I don't get wowed often.... but wow what a great post. :xf.cool:
 
0
•••
Thanks :) I only use the script the park the closeouts won and to transfer them out in due time. It's not a lot of domains but the administrative overhead was disproportionate.
This is what I no longer have to do:

1. Domain won:
  • log in
  • wait
  • click click click
  • locate the right domain
  • enter the name servers manually (quite a few clicks and hoops for nothing)
2. Transfer out:
  • log in
  • wait
  • click click click
  • locate the right domain
  • unlock the domain
  • request the EPP code
  • check the mail and retrieve the EPP code
I am easily saving a few minutes every time. Even for one domain it's such a breeze.
Time is in short supply and we live only once. Enjoy.

Domainers: try to automate things as much as you can, thus you become more efficient and you have more time to spend on productive activity.
 
3
•••
Thanks so much for sharing!

I can already envision creative implementations of your code.
 
0
•••
I've tried the api and it's not working to update the NS, anyone had answer to this?

this is my payload which i make during the call


{
"locked": false,
"nameServers": [
"my first ns","my 2nd ns"
],
"renewAuto": true
}

i know you need to at least include 2 nameserver , but whenever i tried adding new nameserver, it returns 204 status but it's not reflecting on the dashboard or api call for the domain
 
Last edited:
0
•••
@Kate very helpful article, thank you. I was wondering though, if you knew if GD's Appraisal functionality is available via their API?

Update: Nm, I found that it is available.
 
Last edited:
0
•••
does anyone have a working example of updating nameservers using the API? I tried and searched and when I tested using their interface I got an error the domain is not registered or has no zone files.

All I want to do is to change the nameservers.
 
2
•••
@Kate,

One of the many reasons why you’re so revered.

Samer
 
Last edited:
1
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back