B
B
booogabooo2015-02-19 23:58:56
PHP
booogabooo, 2015-02-19 23:58:56

Why such an error or what am I doing wrong?

define("ZDAPIKEY", "мой токен");
define("ZDUSER", "почта");
define("ZDURL", "домен");
/* Note: do not put a trailing slash at the end of v2 */
function curlWrap($url, $json, $action)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt($ch, CURLOPT_URL, ZDURL.$url);
curl_setopt($ch, CURLOPT_USERPWD, ZDUSER."/token:".ZDAPIKEY);
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");
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);
return $decoded;
} 

$data = curlWrap("/users.json", null, "GET");
print_r($data);


$data = curlWrap("/groups.json", null, "GET");
print("First group = " . $data->groups[0]->name);

$data = curlWrap("/users.json", null, "GET");
print_r($data);

it doesn't output anything at all, but this:
$data = curlWrap("/groups.json", null, "GET");
print("First group = " . $data->groups[0]->name);

gives error
Notice: Trying to get property of non-object in C:\xampp\htdocs\zendesk\index.php on line 88
What's wrong?
The doc says so

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2015-02-20
@FanatPHP

json_last_error()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question