Beste Allen,

Ik probeer data van tickets uit zendesk te halen. Dit is gelukt echter krijg ik af en toe en Warning wanneer hij data probeert op te halen waardoor hij het soms wel doet en soms niet.

Dit is mijn code:

(index document: <?php ticketsTellen($wizportaaltickets);?> )


(api document)
<?php
/*header('Content-Type: application/json');*/


ini_set('display_errors', 'On');

define("ZDAPIKEY", "XXXXXXXXXXXXXXXX");
define("ZDUSER", "[email protected]");
define("ZDURL", "https://xxxxxxx.zendesk.com/api/v2");

/* Note: do not put a trailing slash at the end of v2 */
function curlWrap($url, $json, $action)
{
$ZDAPIKEY = "";
$ZDUSER = "";
$ZDURL = "";


$ch = curl_init();

curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt($ch, CURLOPT_URL, ZDURL.$url);
curl_setopt($ch, CURLOPT_USERPWD, ZDUSER."/token:".ZDAPIKEY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);


switch($action){

case "POST":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
break;
case "GET":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
/*echo "</br></br>get"; */

break;
case "PUT":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);

break;
case "DELETE":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
default:
break;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

$output = curl_exec($ch);

curl_close($ch);
$decoded = json_decode($output,true);

return $decoded;

}

/*ICT NIM tickets*/
$nimtickets = curlWrap('/views/62811451/execute', null, "GET");



function ticketsTellen($dataView)
{
$totalCount = 0;
$statusNieuw = 0;
$statusOpen = 0;
$statusinAfwachting = 0;
$statusGeparkeerd = 0;
$count = 0;
/*totaal tickets*/
foreach ($dataView['rows'] as $ticket )
{
if ($ticket > null)
{
$totalCount = $totalCount + 1;
}


$status = $ticket['ticket']['status'];

switch ($status)
{
case "new":
$statusNieuw++;
break;
case "open":
$statusOpen++;
break;
case "pending":
$statusinAfwachting++;
break;
case "hold":
$statusGeparkeerd++;
break;
default:
echo "Check count method ticketstellen";
}


}
echo "<p>Totaal: ".$totalCount."</br>";
echo "Nieuw: ".$statusNieuw."</br>";
echo "Open: ".$statusOpen."</br>";
echo "In afwachting: ".$statusinAfwachting."</br>";
echo "Geparkeerd: ".$statusGeparkeerd."</br>";
echo "</br></p>";
}
M B op 09/01/2017 16:53:35

echter krijg ik af en toe en Warning wanneer hij data probeert op te halen


Welke?
Warning: Invalid argument supplied for foreach() in C:\Users\NIM\Desktop\WEBSITE zendesk api\root\apiconnect.php

[size=xsmall]Toevoeging op 11/01/2017 09:41:49:[/size]

- SanThe - op 09/01/2017 17:00:21

[quote="M B op 09/01/2017 16:53:35"]
echter krijg ik af en toe en Warning wanneer hij data probeert op te halen


Welke?
[/quote]


Warning: Invalid argument supplied for foreach() in C:\Users\NIM\Desktop\WEBSITE zendesk api\root\apiconnect.php
Gokje: $wizportaaltickets is niet altijd een array. Controleer daarop met is_array().
- Ariën - op 11/01/2017 09:46:33

Gokje: $wizportaaltickets is niet altijd een array. Controleer daarop met is_array().


Thanks het heeft gewerkt!
Ik heb bij het ophalen van de data. Na het decode een check laten doen of het een array is als het niet is doet hij het ophalen nog een keer.

Bedankt!

Reageren