1

I am trying to fetch all the domains I have purchased from Godaddy account using their API. However, It's not showing in a table format for proper view. Can anybody guide me on how to create a table out of this API results? Currently, it's showing results each at a different line but I prefer to view them in a table format.

Thanks!!

<?php
    $domains = getDomains();

    // check if error code
    if(isset($domains['code'])){

        $msg = explode(":",$domains['message']);

        $msg = '<h2 style="text-align:center;">'.$msg[0].'</h2>';

    // proceed if no error
    } else {

        $msg = '';
        foreach ($domains as $domain){

            $msg .= $domain['domain'].'</br>';
            $msg .= $domain['createdAt'].'<br>';

            $domain['createdAt'];
            $domain['domain'];
            $domain['domainId'];
            $domain['expirationProtected'];
            $domain['expires'];
            $domain['holdRegistrar'];
            $domain['locked'];
            $domain['nameServers'];
            $domain['privacy'];
            $domain['renewAuto'];
            $domain['renewDeadline'];
            $domain['renewable'];
            $domain['status'];
            $domain['transferProtected'];



        }

    }

    echo $msg;


    function getDomains(){

            $status = 'ACTIVE';
            $limit = '999';

            $url = "https://api.godaddy.com/v1/domains?statuses=$status&limit=$limit";

            // set your key and secret
            $header = array(
                'Authorization: #########'
            );

            //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);

    return $dn;

    }

    ?>
Prateek Gupta
  • 2,422
  • 2
  • 16
  • 30
Ali
  • 11
  • 2

0 Answers0