[link_popup id='2715' link_text='Click to open popup' name='Main Pop Up']
Digital strategies generating customer growth and revenue.

Bluehost.com Web Hosting $3.95

Reading Time: 7 minutes

Today I’m sharing a tutorial that is likely going to open and unlock the door into a realm of creativity some of you have longed for and imagined about at some point along the way, especially if you use GoDaddy as a domain registrar.

If you have no clue what I’m talking about, then simply keep reading and you will.

Nevertheless, I’m sharing with you a step-by-step tutorial about how to use PHP to make GoDaddy API calls.

For starters, you’ll need to be sure you have a GoDaddy Account and a GoDaddy Developer account.

If you have credentials and access to either account, then you have access to both account types.

Once you have access to the developer portal, visit the Developer Portal’s Get Started Page.

There you’ll have the opportunity to generate a API key and secret used when instantiating and authorizing GoDaddy API call.

Once necessary API access credentials are successfully generated, then you’ll need to become familiar with the API Documentation.

For the most part, GoDaddy has provided fairly basic API calls for most of its service offerings.

I won’t go into detail of each API service, but we’ll start easy and focus today’s tutorial on making a simple GoDaddy API call to check a domain’s availability.

GoDaddy API to Check a Domain’s Availability

Although GoDaddy provides a number of API request methods, such as POST, PUT, PATCH and DELETE, we’ll focus our efforts on using the GET request method (as indicated below).

When the above option is clicked from the GoDaddy’s API page, the following detailed section is displayed:

In short, we’re able to pass parameters to the API service URL to limit and restrict data returned. In this case, the following parameters can be passed when checking a domain’s availability:

  • domain
  • checkType
  • forTransfer

Refer to GoDaddy API documentation for more in-depth description and parameter values and data types. It’s also worth noting that GoDaddy uses JSON as it’s API content type.

Finally, API response codes, reasons and models are provided to help provide technical assistance and insight when encountering response messages making API calls.

To make an GoDaddy API to to check a domain’s availability, we’ll use PHP and PHP’s built-in cURL library.

Before you dive into this tutorial, be sure you have the following:

Please note this tutorial is a “quick and dirty” approach that uses procedural programming and not object-oriented programming (which I highly recommend).

I chose to use procedural programming as this tutorial is aimed at someone who does not come from nor have they ever had experience with software development in general.

Once procuring the aforementioned items, then you’re ready to proceed with the tutorial.

Open the text editor of your choice, naming and saving the following PHP file: gdapi.php.

The first step is to create a variable and define it’s value a domain name of your choice. In this example, I’m going to defined two domains using the same variable name $domain:

  • alvinbrown.com (registered)
  • alvinbrownz.com (not-registered)

Next, define a url variable and set its value equal to GoDaddy’s API url for checking a domain’s availability (see GoDaddy API documentation for /v1/domains/available).

At the very end of the value, append the domain query parameter and set is value equal to the $domain variable (see code below).

API Call Using cURL and PHP

Before we can make the API call using cURL and PHP, we’ll need to define a header variable that ‘ll contain API Key and Secret values using the Authorization header.

Replace the {API_KEY} and {API_SECRET} with your respective values.

Next, it’s time to create a cURL call. I won’t go into much detail, but feel free to read up on cURL and study a few examples.

Three things of importance about the code below and the cURL options:

  • CURLOPT_HTTPHEADER
  • CURLOPT_URL
  • CURLOPT_CUSTOMREQUEST

We previously defined and the value of the $header variable to contain the API Key and Secret credentials. The $header variable is passed as a value to the CURLOPT HTTPHEADER.

Also, notice the CURLOPT_URL value is set the $url variable while the CURLOPT_CUSTOMREQUEST value to be ‘GET’.

Pay close attention to the CURLOPT_CUSTOMREQUEST value when using GoDaddy’s API to make non-GET request calls.

In addition, I’ve indicated in the code below the various types of request methods as well as included a few commented out cURL variables to use when making POST API calls.

I’ll save the other API request methods for another tutorial. 😉

Once necessary variables and cURL options have be accurately defined, now execute API call and return a JSON response using PHP’s curl_exec.

Immediately following the call, be sure to close the cURL connection using PHP’s curl_close.

To display the date of whether or not the domain is available or registered, we’ll use PHP’s json_decode to turn the JSON into a PHP Array, passing the $result variable as the first argument.

Once a PHP array, then we’re ready to echo the output using PHP’s print_r method, passing to it the decoded JSON variable $dn.

Time to Test Your Coding Prowess

The time has come to see whether or not you’re able to call yourself a pseudo-coder.

But before we test the code, we’ll need to address the two $domain variables defined at the very beginning of this tutorial.

To test whether or not ‘alvinbrown.com’ is available or registered, you’ll need to comment out the second $domain variable by place “//“ in front of it. This should turn the entire line gray, which indicates the line is commented out.

To test whether or not ‘alvinbrownz.com’ is available or registered, simply uncomment the line by removing “//“ from the beginning of the second $domain variable.

By now, your code should look like the following in its entirety:

Save the gdapi.php file and then open it using a web browser.

When checking to see if alvinbrownz.com is available, the following should be displayed in the web browser:

As you can see in the image where it says ‘available’, the value is set to boolean value of 1 or true, which means the domain is NOT registered.

When checking to see if alvinbrown.com is available, the following should be displayed in the web browser:

As you can see in the image where it says ‘available’, the value is set to boolean value of 0, false or no value at all, which means the domain IS registered.

In closing, my hope is this tutorial helps and encourages you towards experimenting more with GoDaddy’s API.

In addition, I hope to spark a bit of creativity to develop your own ideas and tools to make domain investing more profitable and one of high efficiency.

Let me know if you have questions or comments, or simply encounter a technical glitch. That’s all for now.

Meet Alvin Brown

He's an experienced and passionate serial entrepreneur, founder and publisher of Kickstart Commerce. Alvin possesses a great love for startups dominating their market using profitable digital strategies for greater commerce.

Leave a Reply

Your email address will not be published. Required fields are marked *

*



Browse by topic

THE DAILY SCOOP

Subscribe today and receive instant access to need-to-know Domain marketing strategies, auctions, promo codes and other FREE resources.

Enter your email, and you're on your way!

Unsubscribe at any time.