troubleshooting Question

PHP Curl Json issues

Avatar of qvfps
qvfps asked on
PHPJSON
2 Comments1 Solution81 ViewsLast Modified:
I am trying to write a small application in PHP do download some content using curl in json format and process it.     Below is the data returned via curl and the error message I get when trying to walk through it.   I am sure it is something small I have done wrong I just cant see it.  

I appreciate any suggestions.  

<?php
$url = "https://website/records";
$apikey = '11111111111111111111111';
$ch = curl_init( $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-API-KEY: ' .$apikey, 'Content-Type: application/json' , 'Accept: application/json'));
$myout = curl_exec($ch);
curl_close($ch);


//$result = json_decode(json_decode($myout,true));
$result = json_decode($myout);
echo $myout;
$myResult = $result;

foreach($myResult as $value){
       echo $value->name . ",  " , $value->gender . "<br>\n";
}

?>

{"items":[{"TicketID":41,"WorkHoursID":53,"StartWorkHour":"2019-09-16T13:33:11Z","EndWorkHour":"2019-09-16T13:33:13Z","TechnicianContactID":2,"Billiable":true,"OnCustomerSite":false,"Description":null,"TechnicianFullName":"Tech1","TechnicianEmail":"Tech1@support.com"},{"TicketID":41,"WorkHoursID":82,"StartWorkHour":"2019-08-05T15:23:21Z","EndWorkHour":"2019-08-05T15:26:33Z","TechnicianContactID":7,"Billiable":true,"OnCustomerSite":false,"Description":null,"TechnicianFullName":"Tech2","TechnicianEmail":"Tech2@support.com"}],"totalItemCount":2,"page":1,"itemsInPage":10,"totalPages":1,"prevLink":"","nextLink":""}


Invalid argument supplied for foreach()
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros