I've created this code to show me data from a URL GET, putting the url alone, show me details in ARRAY. But when i insert the url in the script to get data, dont show me nothing, and when i put the Foreach, show me an error.
***I cannot give the API key (Client information Protection)
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://retail.yclient.com/yclientapi/v2/KEY/GetClients",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
$data = json_decode($response, false);
foreach($data as $ckey => $client) {
echo $client['Name']."<br/>";
echo $client['Email']."<br/>";
echo $client['CellPhone']."<br/>";
}
curl_close($curl);
ERROR
Warning: Invalid argument supplied for foreach() in /home/cloudiu/www/assets/api_request_clients.php on line 34
Can someone tell me the reason for not showing results...
If I access the same URL from my browser, it returns
[{"RID":1,"ClientSalesRID":null,"AccountID":1,"TaxID":"","IdCard":"13731415","Name":"Pedro Pestana","Address":"","PostalCode":"","PostalCodeLastDigits":"","City":"Funchal","Country":"Portugal","CellPhone":"931314712","Phone":"","Email":"pdrpstn@gmail.
Debugging:
var_dump($response)
returns string(0) ""
var_dump($err)
returns string(0) ""
Response Header from cURL shows
HTTP/1.1 401 Unauthorized
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 29 Sep 2021 13:49:08 GMT
Content-Length: 0