SlicingDice Documentation

SlicingDice API Docs

Welcome to the SlicingDice API documentation. You'll find comprehensive guides and documentation to help you start working with SlicingDice as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Guides

PHP

PHP client/SDK for SlicingDice

You can use the SlicingDice's PHP client/SDK to rapidly start inserting and querying your data, without having to handle with all the API HTTP requests yourself.

Installing the client

In order to install the PHP client, simply run the following command with composer to install the SlicingDice package .

composer require slicingdice/slicingdice

You can also add the following excerpt to your composer.json file.

{
  "require": {
    "simbiose/slicingdice": "*"
  }
}

Source code

SlicingDice's PHP client/SDK source code is available on Github .

Build Status: CircleCI


Tests and Examples

At the PHP client/SDK Github repository, you will find examples of data insertion and queries with their respective expected result messages. You take advantage of all these examples to test the client and also learn how to use it.


Using the client

SlicingDice class encapsulates logic for sending requests to the API.

<?php
user Slicer\SlicingDice;

// Configure the client
$client = new SlicingDice(array("masterKey" =>"API_KEY"));

// Creating a column
$columnData = array(
    'name' => 'Age',
    'api-name' => 'age',
    'description' => 'User age',
    'type' => 'integer',
    'storage' => 'latest-value');
$client->createColumn($columnData);

// Inserting data
$insertData = array(
    'user1@slicingdice.com' => array(
        'age' => 22
    )
);
$client->insert($insertData);

// Querying data
$queryData = array(
    'query-name' => 'users-between-20-and-40',
    'query' => array(
        array(
            'age' => array(
                'range' => array(20, 40)
            )
        )
    )
);
print_r($client->countEntity($queryData));
?>

Database Keys

Database keys are configured with the client constructor, as presented in the example below.

<?php
use Slicer\SlicingDice;

// Configure client with master Database key
$slicingDice = new SlicingDice(array(
    "masterKey" => "MASTER_DATABASE_KEY");

// Configure client with read Database key
$slicingDice = new SlicingDice(array(
    "readKey" => "READ_DATABASE_KEY");

// Configure client with write Database key
$slicingDice = new SlicingDice(array(
    "writeKey" => "WRITE_DATABASE_KEY"
));

// Configure client with custom Database key
$slicingDice = new SlicingDice(array(
    "customKey" => "CUSTOM_DATABASE_KEY"
));
?>

Constructor

_construct($apiKeys, $timeout=60)
  • $apiKeys (array) - An array of Database keys to authenticate requests with the SlicingDice API, you can put many keys with different types on this array, the types can be: masterKey, customKey, writeKey or readKey.
  • $timeout (int) - Amount of time, in seconds, to wait for results for each request.

Methods

  • getDatabase() - Get current database, identified by the given Database key. This method corresponds to a GET request at /database.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
print_r($slicingdice->getDatabase());
?>
  • getColumns() - Get all created columns, both active and inactive ones organized by dimension. This method corresponds to a GET request at /column.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

print_r($slicingdice->getColumns());
?>
  • createColumn($data) - Create a new column. This method corresponds to a POST request at /column.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$insertData = array(
    array(
        "type" => "string",
        "storage" => "latest-value",
        "api-name" => "state",
        "name" => "User State",
        "description" => "State where the user lives"
    ), 
    array(
        "type" => "integer",
        "storage" => "latest-value",
        "api-name" => "age",
        "name" => "User Age"
    )
);

print_r($slicingdice->createColumn($insertData));
?>
  • insert($data) - Insert data to existing entities or create new entities, if necessary. This method corresponds to a POST request at /insert.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$insertData = array(
    "UUID-01" => array(
        "dimension" => "users",
        "age" => 25,
        "name" => "Jeff",
        "clicks" => array(
            array(
                "date" => "2017-05-26T12:54:12Z",
                "value" => "Add to Cart"
            ), 
            array(
                "date" => "2017-05-31T10:22:10Z",
                "value" => "Pay Now"
            ), 
            array(
                "date" => "2017-06-03T17:05:25Z",
                "value" => "Support"
            )
        )
    ),
    "auto-create" => array(
        "dimension", 
        "column"
    )
);

print_r($slicingdice->insert($insertData));
?>
  • existsEntity($ids, $dimension=NULL) - Verify which entities exist in a dimension (uses default dimension if not provided) given a list of entity IDs. This method corresponds to a POST request at /query/exists/entity.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$dimension = "users";
$queryData = array(
    "user1@slicingdice.com", 
    "user2@slicingdice.com", 
    "user3@slicingdice.com", 
    "user4@slicingdice.com", 
    "user5@slicingdice.com"
);

print_r($slicingdice->existsEntity($queryData, $dimension));
?>
  • countEntityTotal($dimensions=array()) - Count the number of stored entities in given $dimensions (or in all dimensions by default). This method corresponds to a POST request at /query/count/entity/total.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

print_r($slicingdice->countEntityTotal());
?>
  • countEntity($query) - Count the number of entities satisfying the given query. This method corresponds to a POST request at /query/count/entity.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$queryData = array(
    array(
        "dimension" => "users",
        "query-name" => "jeff-user-clicked-to-pay",
        "bypass-cache" => true,
        "query" => array(
            array(
                "name" => array(
                    "equals" => "Jeff"
                )
            ), 
            "and", 
            array(
                "clicks" => array(
                    "equals" => "Pay Now",
                    "between" => array(
                        "2017-05-21T00:00:00Z", 
                        "2017-06-04T00:00:00Z"
                    )
                )
            )
        )
    )
);

print_r($slicingdice->countEntity($queryData));
?>
  • countEvent($query) - Count the number of occurrences for events satisfying the given query. This method corresponds to a POST request at /query/count/event.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$queryData = array(
    array(
        "query" => array(
            array(
                "actions" => array(
                    "equals" => "visited-page",
                    "between" => array(
                        "2017-05-21T00:00:00Z", 
                        "2017-06-04T00:00:00Z"
                    )
                )
            )
        ),
        "query-name" => "visited-page-events"
    )
);

print_r($slicingdice->countEvent($queryData));
?>
  • topValues($query) - Return the top values for entities satisfying the given query. This method corresponds to a POST request at /query/top_values.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$queryData = array(
    "name-contains-eff" => array(
        "dimension" => "users",
        "contains" => array(
            "eff"
        ),
        "name" => 3
    )
);

print_r($slicingdice->topValues($queryData));
?>
  • aggregation($query) - Return the aggregation of all columns in the given query. This method corresponds to a POST request at /query/aggregation.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$queryData = array(
    "filter" => array(
        array(
            "country" => array(
                "equals" => "USA"
            )
        )
    ),
    "query" => array(
        array(
            "purchased-products" => 2,
            "between" => array(
                "2017-05-16T00:00:00Z", 
                "2017-06-04T00:00:00Z"
            )
        )
    )
);

print_r($slicingdice->aggregation($queryData));
?>
  • getSavedQueries() - Get all saved queries. This method corresponds to a GET request at /query/saved.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

print_r($slicingdice->getSavedQueries());
?>
  • createSavedQuery($query) - Create a saved query at SlicingDice. This method corresponds to a POST request at /query/saved.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$queryData = array(
    "query" => array(
        array(
            "state" => array(
                "equals" => "NY"
            )
        ), 
        "or", 
        array(
            "state" => array(
                "equals" => "CA"
            )
        )
    ),
    "type" => "count/entity",
    "name" => "my-saved-query",
    "dimension" => "users"
);

print_r($slicingdice->createSavedQuery($queryData));
?>
  • updateSavedQuery($queryName, $query) - Update an existing saved query at SlicingDice. This method corresponds to a PUT request at /query/saved/:query_name.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$queryData = array(
    "query" => array(
        array(
            "state" => array(
                "equals" => "NY"
            )
        ), 
        "or", 
        array(
            "state" => array(
                "equals" => "CA"
            )
        )
    ),
    "type" => "count/entity",
    "dimension" => "users"
);

print_r($slicingdice->updateSavedQuery("my-saved-query", $queryData));
?>
  • getSavedQuery($queryName, $query) - Executed a saved query at SlicingDice. This method corresponds to a GET request at /query/saved/:query_name.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

print_r($slicingdice->getSavedQuery("my-saved-query"));
?>
  • deleteSavedQuery($queryName) - Delete a saved query at SlicingDice. This method corresponds to a DELETE request at /query/saved/:query_name.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

print_r($slicingdice->deleteSavedQuery("my-saved-query"));
?>
  • result($query) - Retrieve stored values for entities satisfying the given query. This method corresponds to a POST request at /data_extraction/result.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$queryData = array(
    "query" => array(
        array(
            "state" => array(
                "equals" => "NY"
            )
        ), 
        "or", 
        array(
            "state" => array(
                "equals" => "CA"
            )
        )
    ),
    "limit" => 3,
    "columns" => array(
        "city", 
        "state"
    )
);

print_r($slicingdice->result($queryData));
?>
  • score($query) - Retrieve stored values as well as their relevance for entities satisfying the given query. This method corresponds to a POST request at /data_extraction/score.
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$queryData = array(
    "query" => array(
        array(
            "state" => array(
                "equals" => "NY"
            )
        ), 
        "or", 
        array(
            "state" => array(
                "equals" => "CA"
            )
        ), 
        "or", 
        array(
            "gender" => array(
                "equals" => "male"
            )
        ), 
        "or", 
        array(
            "age" => array(
                "range" => array(
                    18, 
                    25
                )
            )
        )
    ),
    "limit" => 3,
    "columns" => array(
        "city", 
        "state"
    )
);

print_r($slicingdice->score($queryData));
?>
  • sql($statement) - Retrieve inserted values using a SQL syntax. This method corresponds to a POST request at /query/sql.

Query statement

<?php
use Slicer\SlicingDice;

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$query = "SELECT COUNT(*) FROM default WHERE age BETWEEN 0 AND 49";
print_r($client->sql($query));
?>

Insert statement

<?php
use Slicer\SlicingDice;

$client = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));
$query = "INSERT INTO default([entity-id], name, age) VALUES(1, 'john', 10)";
print_r($client->sql($query));
?>

PHP

PHP client/SDK for SlicingDice