zendesk geckoboard自定义小部件

时间:2014-07-23 11:35:54

标签: php json curl zendesk geckoboard

我们正在使用Geckoboard.com和Zendesk。

我正在为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中的所有数据都是我自己的信息。

执行文件时收到的消息:

{&#34; message&#34;:&#34; the property&#39; text&#39;未定义&#34;}

非常感谢任何帮助。

对不起,我对JSON&amp; CURL

1 个答案:

答案 0 :(得分: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);
*/

?>