use Guzzle wit name.com api

21 Views Asked by At

use Guzzle wit name.com api

that is the Curl example

curl -u 'username:token' 'https://api.dev.name.com/v4/domains:checkAvailability' -X POST -H 'Content-Type: application/json' --data '{"domainNames":["example.org"]}'

php curl with Guzzle to do the previous request

$username='';
$token='';
$client = new GuzzleHttp\Client();
$url = $endpoint.'/v4/domains:checkAvailability';
$headers = ['Authorization' => "$username:$token",'Content-Type' => 'application/json'];
$data ='{"domainNames":["example.com"]}';
$data=json_decode($data,true);
$res = $client->post($url,['headers' => $headers ,'form_params' => $data  ]);

Questions :

1-Authorization is missing some thing like basic

2-name.com required --data as string but Guzzle required it as array

correct way to pass the data

thanks

0

There are 0 best solutions below