Geckoboard Developer Community

cURL update from PHP


Hi there,
I signed up to a trial of Geckoboard yesterday and have been trying to customise it for our company. At the moment, we have a wallboard which is used to display how many agents are logged in to our Asterisk phone system, and how many calls are waiting. It’s very basic. I am looking for a solution like Geckoboard so we can incorporate sales data but we absolutely must retain knowledge of who is logged in to take calls, and how many are waiting. This data must also be ‘live’ within a range of no more than 5 seconds since it’s no use knowing that there was a call waiting 10 minutes ago (so Google Sheets is out).

I have considered a few options, and I have got the sales data side of things working great. However, I am now at the stage where I need to update our custom text widgets with the names of people logged in. I am able to get this from our phone system in a suitable format but I am struggling with sending it to our widget using cURL. I am totally new to cURL and have been able to update our widget with demo text from the command line - just not with PHP. I have done 4-5 hours of Googling and come up with the code below, which I have tried to make fit but have failed. My thought process is that, if I can get the PHP to cURL working, I will set up a web page to automatically refresh every x seconds hence updating the data in Geckoboard.

I would appreciate any help in getting this to work as this really is a dealbreaker, we can’t switch to Geckoboard and lose our call stats.

Here is what I am working with at the moment:


$data = array(
  "api_key" => "apikeygoeshere",
  "text" => "Agents logged in: Amy, Anthony, Carl",
  "type" => 0,

$url_send ="";
$str_data = json_encode($data);

function sendPostData($url, $post){
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
  $result = curl_exec($ch);
  return $result;

echo " " . sendPostData($url_send, $str_data);


Any help you can offer would be gratefully received.


Hi Anthony,

I appreciate you reaching out here and your detailed explanation of what you’d like to accomplish, and what you’ve tried so far. I’m afraid I don’t have much experience with PHP but I do see an issue with your $data value – once ‘stringified’ into JSON, should be like:

  "api_key": "",
  "data": {
    "item": [
        "text": "Agents logged in: Amy, Anthony, Carl",
        "type": 0

So roughly, it should be in PHP as:

$data = array(
  "item" => array(
    "text" => "Agents logged in: Amy, Anthony, Carl",
    "type" => 0,

$body = array(
  "api_key" => "apikeygoeshere",
  "data" => $data,

$str_data = json_encode($body);

You may need to adjust the $data value further as I’m not :100: sure that’s valid PHP, but you can check your work by echoing the value and see if it matches the above JSON format. If in doubt you can see here:

If the above isn’t helpful, can you further describe the problem you’ve run into? That is, given the above code is there e.g. an error output?

Otherwise, are you perhaps open to doing this with Node.js? Here’s an example. To use this you’d want to run npm install request-promise@3.0.0 If you give it a try and need help further let me know!

const request = require('request-promise');

const api_key = '';
const widget_key = '';

const data = {
  item: [
      text: 'Agents logged in: Amy, Anthony, Carl',
      type: 0,

function send() {
  return request({
    url: `${widget_key}`,
    method: 'POST',
    body: JSON.stringify({
  .catch(e => console.log(e.message));

function loop() {
  setTimeout(loop, 1000*2); // 1000 * 5 => 5 seconds