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    Documentation

JavaScript

JavaScript client/SDK for SlicingDice

You can use the SlicingDice's JavaScript 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 JavaScript client, you only need to install our npm package .

npm install slicerjs

Source code

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

Build Status: CircleCI


Tests and Examples

At the JavaScript 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. Its methods are thin layers around the API endpoints, so their parameters and return values are the same JSON objects and arrays you would send to the API endpoints.

var SlicingDice = require('slicerjs'); // only required for Node.js

// Configure the client
var client = new SlicingDice({
  masterKey: 'MASTER_API_KEY',
  writeKey: 'WRITE_API_KEY',
  readKey: 'READ_API_KEY'
});

// Creating a column
var columnData = {
    "name": "Age",
    "api-name": "age",
    "description": "User age",
    "type": "integer",
    "storage": "latest-value"
};
client.createColumn(columnData)
  .then(response => console.log(response))
  .catch(response => console.error(response));

// Inserting data
var insertData = {
    "user1@slicingdice.com": {
        "age": 22
    }
};
client.insert(insertData)
  .then(response => console.log(response))
  .catch(response => console.error(response));

// Querying data
var queryData = {
    "query-name": "users-between-20-and-40",
    "query": [
        {
            "age": {
                "range": [
                    20,
                    40
                ]
            }
        }
    ]
};
client.countEntity(queryData)
  .then(response => console.log(response))
  .catch(response => console.error(response));

API Keys

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

var SlicingDice = require('slicerjs'); // only required for Node.js

// Configure client with master API key
var slicer = new SlicingDice({ masterKey: 'MASTER_API_KEY' });

// Configure client with read API key
var slicer = new SlicingDice({ readKey: 'READ_API_KEY' });

// Configure client with write API key
var slicer = new SlicingDice({ writeKey: 'WRITE_API_KEY' });

// Configure client with custom API key
var slicer = new SlicingDice({ customKey: 'CUSTOM_API_KEY' });

Constructor

SlicingDice(keys)
  • keys (object) - A JSON object containing API keys used to authenticate SlicingDice API requests. This object must have at least one of the following attributes:
    • masterKey - Master API Key to used to authenticate requests on SlicingDice API.
    • writeKey - Write API Key to used to authenticate requests on SlicingDice API.
    • readKey - Read API Key to used to authenticate requests on SlicingDice API.
    • customKey - Custom API Key to used to authenticate requests on SlicingDice API.

Methods

  • getDatabase() - Get current database, identified by the given API key. This method corresponds to a GET request at /database.
const SlicingDice = require('slicerjs');
const slicingdice = new SlicingDice({
  masterKey: 'MASTER_API_KEY'
});

slicingdice.getDatabase().then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • getColumns() - Get all created columns, both active and inactive ones organized by table. This method corresponds to a GET request at /column.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

slicingdice.getColumns().then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • createColumn(jsonData) - Create a new column. This method corresponds to a POST request at /column.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

const insertData = [
    {
        "type": "string",
        "storage": "latest-value",
        "api-name": "state",
        "name": "User State",
        "description": "State where the user lives"
    }, 
    {
        "type": "integer",
        "storage": "latest-value",
        "api-name": "age",
        "name": "User Age"
    }
];

slicingdice.createColumn(insertData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • insert(jsonData) - Insert data to existing entities or create new entities, if necessary. This method corresponds to a POST request at /insert.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

const insertData = {
    "UUID-01": {
        "table": "users",
        "age": 25,
        "name": "Jeff",
        "clicks": [
            {
                "date": "2017-05-26T12:54:12Z",
                "value": "Add to Cart"
            }, 
            {
                "date": "2017-05-31T10:22:10Z",
                "value": "Pay Now"
            }, 
            {
                "date": "2017-06-03T17:05:25Z",
                "value": "Support"
            }
        ]
    },
    "auto-create": [
        "table", 
        "column"
    ]
};

slicingdice.insert(insertData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • existsEntity(ids, table = null) - Verify which entities exist in a table (uses default table if not provided) given a list of entity IDs. This method corresponds to a POST request at /query/exists/entity.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

const table = "users";
const queryData = [
    "user1@slicingdice.com", 
    "user2@slicingdice.com", 
    "user3@slicingdice.com", 
    "user4@slicingdice.com", 
    "user5@slicingdice.com"
];

slicingdice.existsEntity(queryData, table).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • countEntityTotal(tables = []) - Count the number of stored entities in given tables (or in all tables by default). This method corresponds to a POST request at /query/count/entity/total.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

slicingdice.countEntityTotal().then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • countEntity(jsonData) - Count the number of entities satisfying the given query. This method corresponds to a POST request at /query/count/entity.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

const queryData = [
    {
        "table": "users",
        "query-name": "jeff-user-clicked-to-pay",
        "bypass-cache": true,
        "query": [
            {
                "name": {
                    "equals": "Jeff"
                }
            }, 
            "and", 
            {
                "clicks": {
                    "equals": "Pay Now",
                    "between": [
                        "2017-05-21T00:00:00Z", 
                        "2017-06-04T00:00:00Z"
                    ]
                }
            }
        ]
    }
];

slicingdice.countEntity(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • countEvent(jsonData) - Count the number of occurrences for events satisfying the given query. This method corresponds to a POST request at /query/count/event.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

const queryData = [
    {
        "query": [
            {
                "actions": {
                    "equals": "visited-page",
                    "between": [
                        "2017-05-21T00:00:00Z", 
                        "2017-06-04T00:00:00Z"
                    ]
                }
            }
        ],
        "query-name": "visited-page-events"
    }
];

slicingdice.countEvent(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • topValues(jsonData) - Return the top values for entities satisfying the given query. This method corresponds to a POST request at /query/top_values.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

const queryData = {
    "name-contains-eff": {
        "table": "users",
        "contains": [
            "eff"
        ],
        "name": 3
    }
};

slicingdice.topValues(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • aggregation(jsonData) - Return the aggregation of all columns in the given query. This method corresponds to a POST request at /query/aggregation.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

const queryData = {
    "filter": [
        {
            "country": {
                "equals": "USA"
            }
        }
    ],
    "query": [
        {
            "purchased-products": 2,
            "between": [
                "2017-05-16T00:00:00Z", 
                "2017-06-04T00:00:00Z"
            ]
        }
    ]
};

slicingdice.aggregation(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • getSavedQueries() - Get all saved queries. This method corresponds to a GET request at /query/saved.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

slicingdice.getSavedQueries().then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • createSavedQuery(jsonData) - Create a saved query at SlicingDice. This method corresponds to a POST request at /query/saved.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

const queryData = {
    "query": [
        {
            "state": {
                "equals": "NY"
            }
        }, 
        "or", 
        {
            "state": {
                "equals": "CA"
            }
        }
    ],
    "type": "count/entity",
    "name": "my-saved-query",
    "table": "users"
};

slicingdice.createSavedQuery(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • updateSavedQuery(queryName, jsonData) - Update an existing saved query at SlicingDice. This method corresponds to a PUT request at /query/saved/:query_name.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

const queryData = {
    "query": [
        {
            "state": {
                "equals": "NY"
            }
        }, 
        "or", 
        {
            "state": {
                "equals": "CA"
            }
        }
    ],
    "type": "count/entity",
    "table": "users"
};

slicingdice.updateSavedQuery("my-saved-query", queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • getSavedQuery(queryName, jsonData) - Execute a saved query at SlicingDice. This method corresponds to a GET request at /query/saved/:query_name.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

slicingdice.getSavedQueries("my-saved-query").then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • deleteSavedQuery(queryName) - Delete a saved query at SlicingDice. This method corresponds to a DELETE request at /query/saved/:query_name.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

slicingdice.deleteSavedQuery("my-saved-query").then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • result(jsonData) - Retrieve stored values for entities satisfying the given query. This method corresponds to a POST request at /data_extraction/result.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

const queryData = {
    "query": [
        {
            "state": {
                "equals": "NY"
            }
        }, 
        "or", 
        {
            "state": {
                "equals": "CA"
            }
        }
    ],
    "limit": 3,
    "columns": [
        "city", 
        "state"
    ]
};

slicingdice.result(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • score(jsonData) - 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.
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

const queryData = {
    "query": [
        {
            "state": {
                "equals": "NY"
            }
        }, 
        "or", 
        {
            "state": {
                "equals": "CA"
            }
        }, 
        "or", 
        {
            "gender": {
                "equals": "male"
            }
        }, 
        "or", 
        {
            "age": {
                "range": [
                    18, 
                    25
                ]
            }
        }
    ],
    "limit": 3,
    "columns": [
        "city", 
        "state"
    ]
};

slicingdice.score(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
  • sql(statement) - Retrieve inserted values using a SQL syntax. This method corresponds to a POST request at /query/sql.

Query statement

let SlicingDice = require('slicerjs');

const client = new SlicingDice({
    masterKey: 'MASTER_KEY',
    readKey: 'READ_KEY'
});

query = "SELECT COUNT(*) FROM default WHERE age BETWEEN 0 AND 49";

client.sql(query).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});

Insert statement

let SlicingDice = require('slicerjs');

const client = new SlicingDice({
    masterKey: 'MASTER_KEY',
    readKey: 'READ_KEY'
});

query = "INSERT INTO default([entity-id], name, age) VALUES(1, 'john', 10)";

client.sql(query).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});

This client is fully asynchronous

It means that you can call any of these methods and don't need to wait for their response. For this, we use standard Javascript Promises. In order to get the results of your queries, you may write code like this:

var query = // Your query here;
client.countEntity(query).then(function(response) {
    // In case of successful request
    console.log(response);
}).catch(function(response) {
    // In case of errors
    console.error(response);
});

JavaScript

JavaScript client/SDK for SlicingDice