We help IT Professionals succeed at work.
Get Started

PHP Curl Json issues

qvfps
qvfps asked
on
74 Views
Last Modified: 2020-03-19
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()
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2020
Most Valuable Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE