0

I'm trying to query multiple domain name availability using php and curl but I can't seem to get a valid response back.

API: https://api.godaddy.com/v1/domains/available

Documentation here: https://developer.godaddy.com/doc/endpoint/domains#/v1/availableBulk

My code is below. Any help would be much appreciated.

$domains = array("name.com", "test.com", "monkey123er.com", "Sally123.co");

$domainsJSON = json_encode($domains);



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

    // see GoDaddy API documentation - https://developer.godaddy.com/doc
    // set your key and secret
    $header = array(
        'Authorization: sso-key XXX:XXXX'
    );

    //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, 'POST'); // Values: GET, POST, PUT, DELETE, PATCH, UPDATE 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $domainsJSON);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

    //execute post 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>';
Digishack
  • 61
  • 3
  • _“but I can't seem to get a valid response back”_ - mention what you _do_ get back in such a case then. // You should probably add a Content-Type header - this API accepts different request formats, so you need to specify which one you are using. – 04FS Oct 01 '19 at 07:19
  • I get this: Array ( [code] => NOT_FOUND [message] => Not Found : The requested resource was not found ) – Digishack Oct 01 '19 at 09:31
  • Did you try setting the appropriate Content-Type header? – 04FS Oct 01 '19 at 10:33
  • **[You should not switch off `CURLOPT_SSL_VERIFYHOST` or `CURLOPT_SSL_VERIFYPEER`](https://paragonie.com/blog/2017/10/certainty-automated-cacert-pem-management-for-php-software)**. It could be a security risk! [Here is how to get the certificate bundle if your server is missing one](https://stackoverflow.com/a/32095378/1839439) – Dharman Oct 02 '19 at 22:40
  • I added 'Content-Type: application/json' and it I get the same reponse back. – Digishack Oct 03 '19 at 04:44

0 Answers0