PHP SDK for Databox

Installs: 2 574

Dependents: 0

Stars: 3

Watchers: 2

Forks: 2

Open Issues: 1

Language: JavaScript

v1.4 2014-11-27 01:38 UTC


Build Status Latest Stable Version Total Downloads Latest Unstable Version License

The PHP SDK for interacting with the Databox Push API.


  • Follows PSR-0 conventions and coding standard: autoload friendly
  • Built on top of a solid and extensively tested framework - Guzzle
  • Tested and well-documented


  • PHP >= 5.3.3,
  • Guzzle PHP library,
  • (optional) PHPUnit to run tests.


databox-php-sdk uses Composer. The first step to use databox-php-sdk is to download composer, if we don't have it already:

$ curl -s | php

Then we can add databox-php-sdk as a dependency:

$ composer.phar require databox/databox-php-sdk:1.*

databox-php-sdk follows the PSR-0 convention for file structuring and class naming, which means you can easily integrate databox-php-sdk classloading in your own autoloader.

Basic usage


// This file is generated by Composer
require_once '../vendor/autoload.php';

use \Databox\DataboxClient;
use \Databox\DataboxClientBuilder;
use \Databox\DataboxException;
use \Databox\DataboxBuilder;
use \Guzzle\Common\Exception\RuntimeException;
use \Exception;
use \Databox\Widget as Widget;
use \Databox\Widget\Table as Table;
use \Databox\KPI as KPI;

// Read from Custom connection info in Databox WebApp (
$userAccessToken = 'YOUR-USER-ACCESS-TOKEN';
$sourceToken     = 'YOUR-SOURCE-TOKEN';

//Instantiate the client
$client = new DataboxClient($userAccessToken);

//Instantiate the builder
$builder = new DataboxBuilder();

//The addKpi method uses the accepts $key, $value, $date (in that order). Date should be a timestamp in the format Y-m-d\TH:i:s. Date may be NULL, in which case the current UTC time will be used.
$builder->addKpi(new KPI("testmain", mt_rand(1,600)));
$builder->addKpi(new KPI("testbignumber", mt_rand(1,600)));
$builder->addKpi(new KPI("testcompare", mt_rand(1,600)));
$builder->addKpi(new KPI("testcompare", mt_rand(1,600)));
$builder->addKpi(new KPI("testintervalvalues", mt_rand(1,600)));
$builder->addKpi(new KPI("testlinechart", mt_rand(1,600)));
$builder->addKpi(new KPI("testbarchart", mt_rand(1,600)));

$table = new Widget\Table("testtable");
$table->addColumn("KPI", "string");
$table->addColumn("Today", "float");
$table->addColumn("Yesterday", "float");
$table->addRow(new Table\ColumnData("Visitors"), new Table\ColumnData(1234, 567), new Table\ColumnData(9876, 123));

$progress = new Widget\Progress("testprogress");
$progress->setLabel("Life achievements");

$messages = new Widget\Messages("testmessages");
$messages->addMessage("I like pie!", "USD");
$messages->addMessage("Sweden", "USD");

$pie = new Widget\Pie("testpie");
$pie->addSlice("Pepperoni", 20);
$pie->addSlice("Salami", 50, -10);
$pie->addSlice("Tuna", 70, -30);

$funnel = new Widget\Funnel("testfunnel");
$funnel->addSlice("Cheese", 5);
$funnel->addSlice("Meat", 90, -10);
$funnel->addSlice("Apples", 10, -30);

$pipeline = new Widget\Pipeline("testpipeline");
$pipeline->addSlice("Mac", 20, 24);
$pipeline->addSlice("PC", 30, -10);
$pipeline->addSlice("Amiga", 10, -10);

//You must provide uniqueURL and payload parameters. Payload can be any JSON string, but we reccommend you use our builder class.
try {
    //If no Exception is raised everything went through as it should've :)
    $returnedResult = $client->pushData($builder);

        ? print_r($returnedResult)
        : print($returnedResult);
} catch (DataboxException $e) {
    echo $e->getType();
    echo $e->getWebMessage();
    echo $e->getMessage();
} catch (RuntimeException $e) {
    echo $e->getMessage();
    echo $e->getCode();
} catch (Exception $e) {
    echo $e->getMessage();

//Fetch the saved data log
$log = $client->getPushLog();

echo $log;


See the doc directory for more detailed documentation.


databox-php-sdk is licensed under the MIT License - see the LICENSE file for details