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

If you do not know what I’m talking about, keep reading, and you will.

Nevertheless, I’m sharing a step-by-step tutorial about using 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 an API key and secret used when instantiating and authorizing GoDaddy API calls.

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 about 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 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 descriptions, parameter values, and data types. It’s also worth noting that GoDaddy uses JSON as its 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 a GoDaddy API 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 that this tutorial is a “quick and dirty” approach that uses procedural programming, 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 has ever had experience with software development.

Once you procure the aforementioned items, 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 its value as a domain name of your choice. In this example, I’m going to define 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 end of the value, append the domain query parameter and set the value equal to the $domain variable (see code below).

<?PHP

	$domain = 'alvinbrown.com';
	$domain = 'alvinbrownz.com';

    // see GoDaddy API documentation - https://developer.godaddy.com/doc
    // url to check domain availability
    $url = "https://api.godaddy.com/v1/domains/available?domain=".$domain;

?>

API Call Using cURL and PHP

Before making the API call using cURL and PHP, we’ll need to define a header variable containing API Key and Secret values using the Authorization header.

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

<?PHP

    // set your key and secret
    $header = array(
        'Authorization: sso-key {API_KEY}:{API_SECRET}'
    );

?>

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 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 as the $url variable while the CURLOPT_CUSTOMREQUEST value is ‘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. 😉

<?PHP

    //open connection
    $ch = curl_init();
    $timeout=60;

    //set the url and other options for curl
    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'); // Values: GET, POST, PUT, DELETE, PATCH, UPDATE 
    //curl_setopt($ch, CURLOPT_POSTFIELDS, $variable);
    //curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

?>

Once necessary variables and cURL options have been accurately defined, now execute the 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, we’re ready to echo the output using PHP’s print_r method, passing the decoded JSON variable $dn to it.

<?PHP

    //execute call and return response data.
    $result = curl_exec($ch);

    //close curl connection
    curl_close($ch);

    // decode the json response
    $dn = json_decode($result, true);

    echo '<pre>';
    print_r($dn);
    echo '</pre>';

?>

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 placing “//“ in front of it. This should turn the entire line gray, which indicates the line is commented out.

<?PHP

	$domain = 'alvinbrown.com';
	//$domain = 'alvinbrownz.com';

?>

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

<?PHP

	$domain = 'alvinbrown.com';
	$domain = 'alvinbrownz.com';

?>

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

<?PHP

	$domain = 'alvinbrown.com';
	//$domain = 'alvinbrownz.com';

    // see GoDaddy API documentation - https://developer.godaddy.com/doc
    // url to check domain availability
    $url = "https://api.godaddy.com/v1/domains/available?domain=".$domain;

    // set your key and secret
    $header = array(
        'Authorization: sso-key {API_KEY}:{API_SECRET}'
    );

    //open connection
    $ch = curl_init();
    $timeout=60;

    //set the url and other options for curl
    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'); // Values: GET, POST, PUT, DELETE, PATCH, UPDATE 
    //curl_setopt($ch, CURLOPT_POSTFIELDS, $variable);
    //curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

    //execute call and return response data.
    $result = curl_exec($ch);

    //close curl connection
    curl_close($ch);

    // decode the json response
    $dn = json_decode($result, true);

    echo '<pre>';
    print_r($dn);
    echo '</pre>';

?>

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 a 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 a 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 to experiment more with GoDaddy’s API.

In addition, I hope to spark some creativity to develop your own ideas and tools to make domain investing more profitable and highly efficient.

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

Share:
Written by 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.