Search code examples
phpjsonzendesk

Zendesk - Invalid argument supplied for foreach()


I'm using the recent tickets JSON feed in Zendesk with the following line of PHP:

$data = curlWrap("/tickets/recent.json", null, "GET");

When I use a foreach function as below, I get the error message "Invalid argument supplied for foreach()".

foreach ( $data->tickets as $ticket )

What am I doing wrong?


Solution

  • It needs to be an array. You can use the json_decode() to turn it into an array, eg

    $json = curlWrap("/tickets/recent.json", null, "GET");
    $data = json_decode($data);
    

    And then you can proceed with the foreach array.