Alvin Brown provides a tutorial on retrieving a list of domains from your GoDaddy account using GoDaddy’s API.
If you’re not familiar with GoDaddy’s Application Programming Interface (API), then you’re missing out on a great opportunity to streamline the management of your GoDaddy domain portfolio.
Why would anyone ever consider using GoDaddy’s API to manage my domain portfolio when GoDaddy provides a user-friendly Domain Manager experience? That’s the question I hope to reveal and answer in today’s tutorial.
While GoDaddy’s user experience has greatly improved throughout the years (with additional areas for improvement to realize), GoDaddy’s API offers management opportunities for the following areas of interest:
- Abuse API
- Aftermarket API
- Agreements API
- Certificates API
- Countries API
- Domains API
- Orders API
- Shoppers API
- Subscriptions API
This tutorial will focus on the Domains API section, specifically the GET Domains method — Retrieve a list of Domains for the specified Shopper.
Integrate the Domains method with a landing page and database using a bit of elbow grease, and you could be well on your way to creating a simple domain inquiry tracking system, or at the very least a backup for your domain portfolio.
Getting started
Before diving into this tutorial, be sure you have access to the following:
- A web host environment or localhost environment, preferably Linux hosting
- A GoDaddy Developer account (sign up)
- GoDaddy API Credentials (see here)
- A text editor (Notepad++, Sublime, TextWrangler, Dreamweaver, Notepad)
If you encounter issues setting up or logging into your GoDaddy Developer account, watch this video.
You’ll also need to become familiar with learning to use PHP curl to execute GoDaddy API calls.
To get started with this tutorial, open a text editor of your choice, name and save the following php file: domains.php.
Once the domains.php file is created, define a variable named domains and set it equal to the function we’ll soon discuss: getDomains();.
$domains = getDomains();
Retrieve a list of Domains using GoDaddy API
To retrieve a list of domains using GoDaddy’s API, I’ve chosen to create a function and have given it the name getDomains. Functions are quite helpful in regards to making code more portable and easily managed.
In the case of the getDomains function, it’ll contain PHP and cURL to instantiate the GoDaddy API call to retrieve a list of domains from your GoDaddy account.
I won’t cover all the nitty-gritty details of executing a GoDaddy API call using PHP. However, there is no need to fear. A tutorial exists to help get you acclimated: Getting Started With GoDaddy API Using PHP.
As for the specifics of the getDomains function, take a moment to review the first method of the Domains API via GoDaddy’s API Documentation.
The Domains API method contains the following parameters that act as filters when retrieving the list of domains from your GoDaddy account:
X-Shopper-Id – This parameter is the shopper id or account id of the respective account domains are being retrieved. Although listed as a parameter, this parameter is not set as a query parameter. The authentication or authorization process we’ll soon discuss replaces the X-Shopper-Id.
statuses – Set this parameter to return domains of a certain status. There are over 224 available values to select from. For this tutorial, use ‘ACTIVE’ as the value status value. See documentation for full list of values.
statusGroupsOnly – Set this parameter to return domains from specified groups. There are five different values for this field: INACTIVE, PRE_REGISTRATION, REDEMPTION, RENEWABLE, VERIFICATION_ICANN, and VISIBLE. For this tutorial, a value is not set for this parameter.
limit – Set this parameter for the maximum number of domains to be returned. For this tutorial, use ‘5’ or another integer as the value. To return all domains, simply do not set a value for this parameter or forgo using the parameter.
marker – Set this parameter to offset results using a domain. If you have hundreds of domains in your account, then this parameter could come in handy if you want to return domains after a certain domain. For this tutorial, a value is not set for this parameter.
includes – Set this parameter to include optional details about domains in the response. The available values for this parameter are as follows: authCode, contacts, nameServers. For this tutorial, a value is not set for this parameter.
modifiedDate – Set this parameter to only include results that have been modified since a specified date. For this tutorial, a value is not set for this parameter.
Now that parameter options have been identified, it’s time to define and set the values accordingly. Set the statuses and limit parameters to the following values using PHP variables status and limit respectively:
$status = ‘Active’;
$limit = ‘5’;
Using GoDaddy’s API Documentation, define a url variable and its value to be the base API url to retrieve domains with status and limit variables and their respective values appended to the url as query parameters.
$url = “https://api.godaddy.com/v1/domains?statuses=$status&limit=$limit”;
Next, change {API_KEY} and {API_SECRET} values to be your respective API credentials. Generate an API key and secret to be used when instantiating and authorizing GoDaddy API calls.
Once API key and secret credentials are in place, the API call can be made to request and retrieve a list of active domains associated with your GoDaddy account.
The API call is made using PHP’s built-in cURL method. The getDomains function returns a decoded json response object (i.e., dn variable returned at end of function) — think a list of your specified domains — containing domains.
Error checking and parsing domain response
While you likely don’t need to add error checking, it’s always in your best interest too. To do so, I use an if else statement to check for errors by simply checking the response from the domains variable that is set equal to the getDomains function.
If the domains variable has an object key set for code, this means an error of some sort occurred when instantiating the GoDaddy API call request.
Within the if statement, simply explode and parse the response data for the message object key to obtain and display a human-readable error message. Feel free to refer to GoDaddy’s API Documentation for additional explanation and definition of each error.
Within the else statement, I can proceed to parse the response data and display the following attributes for each domain:
- createdAt
- domain
- domainId
- expirationProtected
- expires
- holdRegistrar
- locked
- nameServers
- privacy
- renewAuto
- renewDeadline
- renewable
- status
- transferProtected
Most of the aforementioned attributes are intuitive and somewhat self explanatory. Feel free to refer to GoDaddy’s API Documentation for additional explanation and definition of each attribute.
For this tutorial, I display only the domain name immediately followed by a line break using and echoing the msg variable to the web browser.
Time to test your technical chops
Well, you’ve endured to the end! Now it’s time to test your technical chops.
The code in its entirety should lie similar to the gd-domains.php file contained in the YourGoDaddyDomains.zip file.
DOWNLOAD YourGoDaddyDomains.zip
PLEASE DO NOT FORGET TO ADD YOUR RESPECTIVE GODADDY API CREDENTIALS OR THIS TUTORIAL WILL NOT WORK!
Download, extract, and save the gd-domains.php file to an accessible web directory. Open gd-domains.php via a web browser (just like how you would visit a web page – http://yourdomain/gd-domains.php).
Once gd-domains.php is opened and executed via a web browser, your web browser should display a list of domains identical to domains listed in your GoDaddy account.
Closing Thoughts
I hope this and previous tutorials spark your interest as well as ideas for how GoDaddy’s API can be used to become more efficient and effective in managing your domain portfolio external of GoDaddy’s native user interface and experience.
As I stated in the opening, integrating a landing page and database with this tutorial provides an opportunity to create a simple domain inquiry tracking system, or a backup of your domain portfolio at least.
In closing, please do not hesitate to leave me questions, comments, or propose ideas for future tutorials using GoDaddy’s API.
Shailendra Mishra says
I quickly downloaded your model file, generated API credentails for the first time, inserted the credentials within the mentioned {} parenthesis, and uploaded it to a live URL.
It was’t enough. I see a bold “UNAUTHORISED” error. What can be the possible reason?
P.S. I have 2FA enabled. Maybe thats why?
Alvin Brown says
Hi Shailendra – Feel free to email me at [email protected]. I’d be glad to jump on a quick call to see if we can freely troubleshoot the technical challenge you’ve encountered. Thanks.
goranduskic says
Great tutorial, I didn’t know GoDaddy API had such capabilities.
But for me personally, it’s an overkill. For a backup of my domain portfolio (that also includes domains from other registrars as well) I use a free service called https://webmaster.ninja.
There I just log in, type the domain name, and the system catches registrar name, expiration date, and other stuff.
Alvin Brown says
Nice, didn’t know Webmaster.Ninjas existed. Thanks for the share.
Jazib says
It’s awesomely creafted Alvin. Can you please tell me how to display the domain names in four columns with details like CreatedAt, Numbers etc…
It will be really helpful for me.
Thanks
Leo Angelo says
Thanks, Alvin.
To retrieve more than the maximum allowed of 500, chain the requests.
The following retrieves my GoDaddy active domains – name, expiration, and the first nameserver:
0) {
foreach ($domains as $domain){
$msg .= $domain[‘domain’].’,’.substr($domain[‘expires’],0,10).’,’.strtolower($domain[‘nameServers’][0]).”;
}
$from = end($domains)[‘domain’].’0′;
$domains = getDomains($from);
}
echo $msg;
function getDomains(string $from){
$status = ‘ACTIVE’;
$limit = ‘500’;
$options = ‘nameServers’;
$url = “https://api.godaddy.com/v1/domains?statuses=$status&limit=$limit&includes=$options&marker=$from”;
// set your key and secret
$header = array(
‘Authorization: sso-key MyApiKey:MyApiSecret’
);
$ch = curl_init();
$timeout=60;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘GET’);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
curl_close($ch);
$dn = json_decode($result, true);
return $dn;
}
?>
Leo Angelo says
The code got truncated – trying
0) {
foreach ($domains as $domain){
$msg .= $domain[‘domain’].’,’.substr($domain[‘expires’],0,10).’,’.strtolower($domain[‘nameServers’][0]).”;
}
$from = end($domains)[‘domain’].’0′;
$domains = getDomains($from);
}
echo $msg;
function getDomains(string $from){
$status = ‘ACTIVE’;
$limit = ‘500’;
$options = ‘nameServers’;
$url = “https://api.godaddy.com/v1/domains?statuses=$status&limit=$limit&includes=$options&marker=$from”;
// set your key and secret
$header = array(
‘Authorization: sso-key MyApiKey:MyApiSecret’
);
$ch = curl_init();
$timeout=60;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘GET’);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
curl_close($ch);
$dn = json_decode($result, true);
return $dn;
}
?>