It’s been a while since I graced you all with a tutorial using GoDaddy’s Aftermarket API.

In fact, I haven’t written a tutorial since the one about retrieving a list of GoDaddy domains you own.

Although today’s tutorial is not about retrieving a list of domains, you’ll likely use the previous tutorial in conjunction to today’s tutorial covering how to renew a domain for a given time period.

I won’t bore you with the details of all that is needed to get started using GoDaddy’s API. In fact, I’ve covered most of it in another article, Get Started Using GoDaddy API With PHP.

Renewing a domain using the GoDaddy API, specifically the Domains API for renewals, is quite easy.

In short, you’ll submit a POST request that includes the domain and the extension length or period of time to renew domain using a json object.

POSTing json data with PHP cURL is a bit different than making GET requests, although not all that different.

As shown in the code example below, you’ll want to replace the domain and length variables with your respective data.

Once both variables are defined a domain from your portfolio, then you’re ready to use the renewDomain function — the code logic that performs the heavy lift to make domain renewal request.

One more important thing to note is you’ll need to replace {API_KEY} and {API_SECRET} with your own GoDaddy API credentials.

When the aforementioned tweaks to the code have been made, then you’re ready to copy and paste code into a php file, upload file to a web server, and then access the file using a web browser.


$domain = '';
$length = '5';

$msg = renewDomain($domain,$length);

echo $msg;

function renewDomain($domain,$length){

        $url = "$domain/renew";

        $body = array('period' => , '5');
        $body = json_encode($body);

        // set your key and secret
        $header = array(
            'Authorization: sso-key {API_KEY}:{API_SECRET}',
            'Content-Type: application/json',
            'Content-Length: '.strlen($body)

        //open connection
        $ch = curl_init();
        //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, 'POST'); // Values: GET, POST, PUT, DELETE, PATCH, UPDATE 
        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
        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
        // decode the json response
        $dn = json_decode($result, true);

return $dn;



While the code above is written to be a one off renewal script, you’re not far off from adding a few lines and cron job to make this script a back domain renewal script should your registrar forget to renew the domain.

Of course, the same script could also simply a be an app that allows a user to enter or select from a list of domains they own to renew.

Let me know if you have questions or encounter any technical challenges. Thanks, and that’s all for now.

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.