Reputation: 137
We are making use of Geckoboard.com and Zendesk.
I am in the process of creating a custom widget for Geckoboard to get some info (The top ticket solvers) and list them.
For now, I am just trying to push some dummy/hard-coded info to the widget.
My code is as follows:
<?php
$curl = curl_init('https://COMPANY_SUBDOMAIN.zendesk.com/api/v2/views/MY_ZD_VIEW_ID/execute.json');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, 'USER_EMAIL/token:MY_UNIQUE_KEY');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$values = array(
"api_key" => "MY_UNIQUE_KEY",
"data" => array(
"item" => array(
"title" => "hello",
"text" => "Some text here"
)
)
);
$v = json_encode($values);
curl_setopt_array($ch = curl_init(), array(
CURLOPT_URL => "https://push.geckoboard.com/v1/send/MY_WIDGET_ID",
CURLOPT_POSTFIELDS => $v,
)
);
curl_exec($ch);
curl_close($ch);
?>
All the data in CAPS is my own info.
The message I get when I execute the file:
{"message":"The property 'text' is not defined "}
Any help will be greatly appreciated.
Sorry I am still relatively new to JSON & CURL
Upvotes: 0
Views: 543
Reputation: 137
I have managed to solve this. Working code below:
<?php
$curl = curl_init('https://{YOUR ZENDESK SUBDOMAIN}.zendesk.com/api/v2/views/{VIEW ID}/execute.json');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, '{EMAIL}/token:{TOKEN}');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$responseToday = curl_exec($curl);
$resultsToday = json_decode($responseToday, true);
$values = array(
"item" => array(
"type" => 1,
"text" => "Some text here"
)
);
$v = json_encode($values);
//Simply print this out for the client to consume
echo $v;
/* We don't need this if we're not pushing the widget
curl_setopt_array($ch = curl_init(), array(
CURLOPT_URL => "https://push.geckoboard.com/v1/send/{UNIQUE ID}",
CURLOPT_POSTFIELDS => $v
));
curl_exec($ch);
curl_close($ch);
*/
?>
Upvotes: 0