2014-07-23 79 views
0

我們正在使用Geckoboard.com和Zendesk。zendesk geckoboard自定義小部件

我正在爲Geckoboard創建一個自定義小部件來獲取一些信息(最佳票務解決方案)並列出它們。

現在,我只是試圖將一些虛擬/硬編碼的信息推送到小部件。

我的代碼如下:

<?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); 

?> 

所有CAPS的數據是我自己的信息。

的消息時,我執行該文件獲得:

{「消息」:「屬性‘文本’沒有定義」}

任何幫助將不勝感激。

對不起我還是比較新的JSON &捲曲

回答

0

我設法解決這個問題。以下工作代碼:

<?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); 
*/ 

?>