0
votes

I am making a domain purchase call via the godaddy API. I have been successful purchasing a domain on their test environment: https://developer.godaddy.com/doc/endpoint/domains


                $bodyContent=json_encode($bodyContent);

                $ch = curl_init();
                $timeout=60;

                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); 
                curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyContent);
                curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);

                $result = curl_exec($ch);

                $dn = json_decode($result,true);
                $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

                dd($http_status);

The URL endpoint:

$url = "https://api.ote-godaddy.com/v1/domains/purchase";

When i now try and do this on laravel and dd(http_status) i get a 404 error. I can provide more details on the $bodyContent but for now just know the same variable works fine in the godaddy environment. I am new to curl so something must be wrong in the above code snippet

1
can U show us $url, plz?Odin Thunder
use docs.guzzlephp.org/en/stable for curl request, Laravel have "guzzle" out of the boxOdin Thunder

1 Answers

0
votes

Try to use Guzzle, Laravel provides it out of the box. Your request will be like this (don't forget to paste your Api Keys):

// Initialise new Client
$client = new \GuzzleHttp\Client();

// Make headers
$headers = ['Authorization' => 'sso-key [API_KEY]:[API_SECRET]']

// Make body (without json_encode)
$body = ['name' => John, 'age' => '21'];

// Make request with your headers and body
$responce = $client->post('https://api.ote-godaddy.com/v1/domains/purchase', [
    'headers' => $headers,
    'form_params' => $body
]);

// Get Api responce content
$result = $responce->getBody()->getContents();

Notice! I`m use 'POST' reques, becouse for 'v1/domains/purchase' available only POST method