Foreach in variable that receives tickets from the Zendesk api

Asked

Viewed 43 times

1

I’m getting tickets through the Zendesk api, but I don’t know how to foreach the result giving an echo in the indexes.

$subdomain = "meusubdominio";
$username  = "[email protected]";
$token     = "xxx";
$client = new ZendeskAPI($subdomain);
$client->setAuth('basic', ['username' => $username, 'token' => $token]);
$getTickets = $client->tickets()->findAll();

How do I give a foreach on $getTickets, to echo the contents ? For example, I want to echo all indexes ["url"].

I know the example below is wrong, but it is to exemplify what I would like to do with the results.

I imagine I have to do some treatment at $getTickets before I get that result. I just don’t know what should be done.

Ex: 
foreach($getTickets as $Tct):
echo "<p>{$Tct['url']}</p>";
endforeach;

If I var_dump her, I have the results as:

object(stdClass)#53 (4) { ["tickets"]=> array(11) { [0]=> object(stdClass)#45 (31) { ["url"]=> string(50) "https://......
  • So it seems that the foreach must be in $getTickets->tickets

  • Thank you very much, that’s right. Solved!

1 answer

0


Although I’m not familiar with the Zendesk API, by the structure of the object you output on var_dump, maybe this will work:

foreach ($getTickets->tickets as $ticket) {
   echo "<p>{$ticket->url}</p>";
};

Check if this way works. Otherwise paste here the complete output of a print_r($getTickets), to better understand the structure of the object.

  • Thank you very much, that’s right. Solved!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.