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

Result extraction

Result data extraction query type.


A SlicingDice result data extraction query is equivalent to SQL queries like these:

SELECT UserID, 
       ColumnName1, 
       ColumnName2 
FROM   User; 
SELECT UserID, 
       Name, 
       AVG(Age), 
       Email 
FROM   User 
WHERE  User.City = 'San Francisco' 
       AND UserEvents.Action = 'Add to Cart' 
       AND UserEvents.Timestamp BETWEEN 
           '{% convert_date "YYYY-MM-DDT00:00:00Z" "-15d" %}' 
           AND 
           '{% convert_date "YYYY-MM-DDT00:00:00Z" "-1d" %}'; 

Query purpose

SlicingDice result data extraction allows you to retrieve data from columns you have stored. You can use it to answer many questions, like the ones mentioned below.

When using the result query, you select the entities that will be retrieved with the query parameter, exactly the same as a count entities query. Next, you define which columns you want to retrieve data from with the columns parameter.

Result data extraction queries are ideal to answer this kind of questions:

  • What is the email of the users that accessed /online-demo or /platform more than 3 times in the last 7 days?
  • What is the name, email and the sum of all purchase value from orders between {% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %} and {% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}?

Query endpoint

In order to make a result data extraction query, you simply need to send a POST request to https://api.slicingdice.com/v1/data_extraction/result with a single JSON object containing your query and columns you want to retrieve from SlicingDice.

Pro Tip

Remember that you can also use test databases to query before inserting real data to your production database.

Consider generating a free demo database key for yourself to use in all examples below, as indicated on the try before you buy page.


Query syntax and structure

The result endpoint expects a JSON object containing a single query element with a list of columns and conditions, as well as operators if applicable (just like on count entities queries). SlicingDice will only return data from the columns specified in the optional columns list. If columns is not present in the query, it will only return the existing entity IDs.

The optional limit parameter reduces the number of retrieved entities for any number. However, the page parameter is used when pagination applies. In this case, at most 1,024 entities will be returned for each page.

Suppose we have the following data stored on SlicingDice:

User
Gender
State
City
Age

user1@slicingdice.com

female

NY

New York

19

user2@slicingdice.com

female

CA

San Diego

31

user3@slicingdice.com

female

FL

Orlando

27

user4@slicingdice.com

male

WA

Seattle

22

user5@slicingdice.com

female

CA

Los Angeles

21

INSERT INTO default ([entity-id], gender, state, city, age) VALUES ("user1@slicingdice.com", "female", "NY", "New York", 19);
INSERT INTO default ([entity-id], gender, state, city, age) VALUES ("user2@slicingdice.com", "female", "CA", "San Diego", 31);
INSERT INTO default ([entity-id], gender, state, city, age) VALUES ("user3@slicingdice.com", "female", "FL", "Orlando", 27);
INSERT INTO default ([entity-id], gender, state, city, age) VALUES ("user4@slicingdice.com", "male", "WA", "Seattle", 22);
INSERT INTO default ([entity-id], gender, state, city, age) VALUES ("user5@slicingdice.com", "female", "CA", "Los Angeles", 21);
$ curl -X POST https://api.slicingdice.com/v1/sql \
    -H 'Authorization: MASTER_OR_WRITE_API_KEY' \
    -H 'Content-Type: application/sql' \
    -d 'INSERT INTO default ([entity-id], gender, state, city, age) VALUES ("user1@slicingdice.com", "female", "NY", "New York", 19); INSERT INTO default ([entity-id], gender, state, city, age) VALUES ("user2@slicingdice.com", "female", "CA", "San Diego", 31); INSERT INTO default ([entity-id], gender, state, city, age) VALUES ("user3@slicingdice.com", "female", "FL", "Orlando", 27); INSERT INTO default ([entity-id], gender, state, city, age) VALUES ("user4@slicingdice.com", "male", "WA", "Seattle", 22); INSERT INTO default ([entity-id], gender, state, city, age) VALUES ("user5@slicingdice.com", "female", "CA", "Los Angeles", 21);'
curl -X POST https://api.slicingdice.com/v1/insert \
    -H 'Authorization: MASTER_OR_WRITE_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
        "user1@slicingdice.com": {
            "dimension": "default",
            "gender": "female",
            "state": "NY",
            "city": "New York",
            "age": 19
        },
        "user2@slicingdice.com": {
            "dimension": "default",
            "gender": "female",
            "state": "CA",
            "city": "San Diego",
            "age": 31
        },
        "user3@slicingdice.com": {
            "dimension": "default",
            "gender": "female",
            "state": "FL",
            "city": "Orlando",
            "age": 27
        },
        "user4@slicingdice.com": {
            "dimension": "default",
            "gender": "male",
            "state": "WA",
            "city": "Seattle",
            "age": 22
        },
        "user5@slicingdice.com": {
            "dimension": "default",
            "gender": "female",
            "state": "CA",
            "city": "Los Angeles",
            "age": 21
        },
        "auto-create": ["dimension", "column"]
    }'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

insert_data = {
    "user1@slicingdice.com": {
    		"dimension": "default",
        "gender": "female",
        "state": "NY",
        "age": 19,
        "city": "New York"
    },
    "user5@slicingdice.com": {
    		"dimension": "default",
        "gender": "female",
        "state": "CA",
        "age": 21,
        "city": "Los Angeles"
    },
    "user3@slicingdice.com": {
    		"dimension": "default",
        "gender": "female",
        "state": "FL",
        "age": 27,
        "city": "Orlando"
    },
    "auto-create": [
        "dimension", 
        "column"
    ],
    "user4@slicingdice.com": {
    		"dimension": "default",
        "gender": "male",
        "state": "WA",
        "age": 22,
        "city": "Seattle"
    },
    "user2@slicingdice.com": {
    		"dimension": "default",
        "gender": "female",
        "state": "CA",
        "age": 31,
        "city": "San Diego"
    }
}

print(slicingdice.insert(insert_data))

import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");

        JSONObject insertData = new JSONObject()
        .put("user1@slicingdice.com", new JSONObject()
            .put("dimension", "default")
            .put("gender", "female")
            .put("state", "NY")
            .put("age", 19)
            .put("city", "New York"))
        .put("user5@slicingdice.com", new JSONObject()
            .put("dimension", "default")
            .put("gender", "female")
            .put("state", "CA")
            .put("age", 21)
            .put("city", "Los Angeles"))
        .put("user3@slicingdice.com", new JSONObject()
            .put("dimension", "default")
            .put("gender", "female")
            .put("state", "FL")
            .put("age", 27)
            .put("city", "Orlando"))
        .put("auto-create", new JSONArray()
            .put("dimension")
            .put("column"))
        .put("user4@slicingdice.com", new JSONObject()
            .put("dimension", "default")
            .put("gender", "male")
            .put("state", "WA")
            .put("age", 22)
            .put("city", "Seattle"))
        .put("user2@slicingdice.com", new JSONObject()
            .put("dimension", "default")
            .put("gender", "female")
            .put("state", "CA")
            .put("age", 31)
            .put("city", "San Diego"));

        JSONObject result = slicingdice.insert(insertData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

insert_data = {
    "user1@slicingdice.com" => {
        "dimension" => "default",
        "gender" => "female",
        "state" => "NY",
        "age" => 19,
        "city" => "New York"
    },
    "user5@slicingdice.com" => {
        "dimension" => "default",
        "gender" => "female",
        "state" => "CA",
        "age" => 21,
        "city" => "Los Angeles"
    },
    "user3@slicingdice.com" => {
        "dimension" => "default",
        "gender" => "female",
        "state" => "FL",
        "age" => 27,
        "city" => "Orlando"
    },
    "auto-create" => [
        "dimension", 
        "column"
    ],
    "user4@slicingdice.com" => {
        "dimension" => "default",
        "gender" => "male",
        "state" => "WA",
        "age" => 22,
        "city" => "Seattle"
    },
    "user2@slicingdice.com" => {
        "dimension" => "default",
        "gender" => "female",
        "state" => "CA",
        "age" => 31,
        "city" => "San Diego"
    }
}

puts slicingdice.insert(insert_data)

const SlicingDice = require('slicerjs');

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

const insertData = {
    "user1@slicingdice.com": {
        "dimension": "default",
        "gender": "female",
        "state": "NY",
        "age": 19,
        "city": "New York"
    },
    "user5@slicingdice.com": {
        "dimension": "default",
        "gender": "female",
        "state": "CA",
        "age": 21,
        "city": "Los Angeles"
    },
    "user3@slicingdice.com": {
        "dimension": "default",
        "gender": "female",
        "state": "FL",
        "age": 27,
        "city": "Orlando"
    },
    "auto-create": [
        "dimension", 
        "column"
    ],
    "user4@slicingdice.com": {
        "dimension": "default",
        "gender": "male",
        "state": "WA",
        "age": 22,
        "city": "Seattle"
    },
    "user2@slicingdice.com": {
        "dimension": "default",
        "gender": "female",
        "state": "CA",
        "age": 31,
        "city": "San Diego"
    }
};

slicingdice.insert(insertData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});

<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$insertData = array(
    "user1@slicingdice.com" => array(
        "dimension" => "default",
        "gender" => "female",
        "state" => "NY",
        "age" => 19,
        "city" => "New York"
    ),
    "user5@slicingdice.com" => array(
        "dimension" => "default",
        "gender" => "female",
        "state" => "CA",
        "age" => 21,
        "city" => "Los Angeles"
    ),
    "user3@slicingdice.com" => array(
        "dimension" => "default",
        "gender" => "female",
        "state" => "FL",
        "age" => 27,
        "city" => "Orlando"
    ),
    "auto-create" => array(
        "dimension", 
        "column"
    ),
    "user4@slicingdice.com" => array(
        "dimension" => "default",
        "gender" => "male",
        "state" => "WA",
        "age" => 22,
        "city" => "Seattle"
    ),
    "user2@slicingdice.com" => array(
        "dimension" => "default",
        "gender" => "female",
        "state" => "CA",
        "age" => 31,
        "city" => "San Diego"
    )
);

print_r($slicingdice->insert($insertData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");

            var insertData = new Dictionary<string, dynamic>{
                {"user1@slicingdice.com", new Dictionary<string, dynamic>{
                    {"dimension", "default"},
                    {"gender", "female"},
                    {"state", "NY"},
                    {"age", 19},
                    {"city", "New York"}
                }},
                {"user5@slicingdice.com", new Dictionary<string, dynamic>{
                    {"dimension", "default"},
                    {"gender", "female"},
                    {"state", "CA"},
                    {"age", 21},
                    {"city", "Los Angeles"}
                }},
                {"user3@slicingdice.com", new Dictionary<string, dynamic>{
                    {"dimension", "default"},
                    {"gender", "female"},
                    {"state", "FL"},
                    {"age", 27},
                    {"city", "Orlando"}
                }},
                {"auto-create", new List<dynamic>{
                    "dimension", 
                    "column"
                }},
                {"user4@slicingdice.com", new Dictionary<string, dynamic>{
                    {"dimension", "default"},
                    {"gender", "male"},
                    {"state", "WA"},
                    {"age", 22},
                    {"city", "Seattle"}
                }},
                {"user2@slicingdice.com", new Dictionary<string, dynamic>{
                    {"dimension", "default"},
                    {"gender", "female"},
                    {"state", "CA"},
                    {"age", 31},
                    {"city", "San Diego"}
                }}
            };

            var result = slicingdice.Insert(insertData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

    insertData := map[string]interface{}{
        "user1@slicingdice.com": map[string]interface{}{
            "dimension": "default",
            "gender": "female",
            "state": "NY",
            "age": 19,
            "city": "New York",
        },
        "user5@slicingdice.com": map[string]interface{}{
            "dimension": "default",
            "gender": "female",
            "state": "CA",
            "age": 21,
            "city": "Los Angeles",
        },
        "user3@slicingdice.com": map[string]interface{}{
            "dimension": "default",
            "gender": "female",
            "state": "FL",
            "age": 27,
            "city": "Orlando",
        },
        "auto-create": []interface{}{
            "dimension",
            "column",
        },
        "user4@slicingdice.com": map[string]interface{}{
            "dimension": "default",
            "gender": "male",
            "state": "WA",
            "age": 22,
            "city": "Seattle",
        },
        "user2@slicingdice.com": map[string]interface{}{
            "dimension": "default",
            "gender": "female",
            "state": "CA",
            "age": 31,
            "city": "San Diego",
        },
    }

    fmt.Println(slicingdice.Insert(insertData))
}

In this query below we will retrieve the city and state from users that are either from NYor CA.

SELECT city, state FROM default WHERE state = 'NY' or state = 'CA';
$ curl -X POST https://api.slicingdice.com/v1/sql \
    -H 'Authorization: MASTER_OR_WRITE_API_KEY' \
    -H 'Content-Type: application/sql' \
    -d 'SELECT city, state FROM default WHERE state = 'NY' or state = 'CA';'
curl -X POST https://api.slicingdice.com/v1/data_extraction/result \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
        "query": [
            {
                "state": { "equals": "NY" }
            },
            "or",
            {
                "state": { "equals": "CA" }
            }
        ],
        "columns": [
            "city",
            "state"
        ],
        "limit": 3
    }'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

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

print(slicingdice.result(query_data))

import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");

        JSONObject queryData = new JSONObject()
        .put("query", new JSONArray()
            .put(new JSONObject()
                .put("state", new JSONObject()
                    .put("equals", "NY")))
            .put("or")
            .put(new JSONObject()
                .put("state", new JSONObject()
                    .put("equals", "CA"))))
        .put("limit", 3)
        .put("columns", new JSONArray()
            .put("city")
            .put("state"));
        JSONObject result = slicingdice.result(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = {
    "query" => [
        {
            "state" => {
                "equals" => "NY"
            }
        }, 
        "or", 
        {
            "state" => {
                "equals" => "CA"
            }
        }
    ],
    "limit" => 3,
    "columns" => [
        "city", 
        "state"
    ]
}

puts slicingdice.result(query_data)

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);
});

<?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));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");

            var queryData = new Dictionary<string, dynamic>{
                {"query", new List<dynamic>{
                    new Dictionary<string, dynamic>{
                        {"state", new Dictionary<string, dynamic>{
                            {"equals", "NY"}
                        }}
                    }, 
                    "or", 
                    new Dictionary<string, dynamic>{
                        {"state", new Dictionary<string, dynamic>{
                            {"equals", "CA"}
                        }}
                    }
                }},
                {"limit", 3},
                {"columns", new List<dynamic>{
                    "city", 
                    "state"
                }}
            };

            var result = slicingdice.Result(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

    queryData := map[string]interface{}{
        "query": []interface{}{
            map[string]interface{}{
                "state": map[string]interface{}{
                    "equals": "NY",
                },
            },
            "or",
            map[string]interface{}{
                "state": map[string]interface{}{
                    "equals": "CA",
                },
            },
        },
        "limit": 3,
        "columns": []interface{}{
            "city",
            "state",
        },
    }

    fmt.Println(slicingdice.Result(queryData))
}

The API response for this query above will be in the format below:

{
    "status": "success",
    "data": {
        "customer1@mycustomer.com": {
            "city": "New York",
            "state": "NY"
        },
        "customer2@mycustomer.com": {
            "city": "San Diego",
            "state": "CA"
        },
        "customer5@mycustomer.com": {
            "city": "Los Angeles",
            "state": "CA"
        }
    },
    "page": 1,
    "next-page": 2,
    "page-token": "5bD37Hbv56cHHfbWx68N",
    "took": 0.232
}

Let's understand each component of the API response:

  • status - Indicating whether the request was successfully processed or not.
  • data - Retrieved data as inserted.
  • page - Current retrieved page - only applies when more than 1,024 entities were retrieved.
  • next-page - Next page for retrieval - only applies when more than 1,024 entities were retrieved.
  • page-token - Token to retrieve the next page - only applies when more than 1,024 entities were retrieved.
  • took - Time spent processing this request, in seconds.

Retrieving all the data

If you simply want to see all the data you have stored without filtering out any entities or choosing which columns you want on the result you can use the query types and parameters listed below.

Retrieving all entities

To retrieve all the entities you don't need to specify the query parameter on your json, the SlicingDice will automatically get all the entities for you.

Result total entities has a limit of 100 entities

To optimize the all entities operation, SlicingDice limits the total result to 100 entities. You still can specify the limit, but it should be lower than or equal to 100.

SELECT city, state FROM default;
$ curl -X POST https://api.slicingdice.com/v1/sql \
    -H 'Authorization: MASTER_OR_WRITE_API_KEY' \
    -H 'Content-Type: application/sql' \
    -d 'SELECT city, state FROM default;'
curl -X POST https://api.slicingdice.com/v1/data_extraction/result \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
        "columns": [
            "city",
            "state"
        ]
    }'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

query_data = {
    "columns": [
        "city", 
        "state"
    ]
}

print(slicingdice.result(query_data))

import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");

        JSONObject queryData = new JSONObject()
        .put("columns", new JSONArray()
            .put("city")
            .put("state"));
        JSONObject result = slicingdice.result(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = {
    "columns" => [
        "city", 
        "state"
    ]
}

puts slicingdice.result(query_data)

const SlicingDice = require('slicerjs');

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

const queryData = {
    "columns": [
        "city", 
        "state"
    ]
};

slicingdice.result(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});

<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$queryData = array(
    "columns" => array(
        "city", 
        "state"
    )
);

print_r($slicingdice->result($queryData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");

            var queryData = new Dictionary<string, dynamic>{
                {"columns", new List<dynamic>{
                    "city", 
                    "state"
                }}
            };

            var result = slicingdice.Result(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

    queryData := map[string]interface{}{
        "columns": []interface{}{
            "city",
            "state",
        },
    }

    fmt.Println(slicingdice.Result(queryData))
}

Retrieving all columns

To retrieve all the columns you simply need to specify the value all on the columns parameter, with this parameter SlicingDice will automatically retrieve all the columns (except the event columns) on your data extraction result.

SELECT * FROM default WHERE state = 'NY' OR state = 'CA';
$ curl -X POST https://api.slicingdice.com/v1/sql \
    -H 'Authorization: MASTER_OR_WRITE_API_KEY' \
    -H 'Content-Type: application/sql' \
    -d 'SELECT * FROM default WHERE state = 'NY' OR state = 'CA';'
curl -X POST https://api.slicingdice.com/v1/data_extraction/result \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
        "query": [
            {
                "state": { "equals": "NY" }
            },
            "or",
            {
                "state": { "equals": "CA" }
            }
        ],
        "columns": "all",
        "limit": 3
    }'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

query_data = {
    "query": [
        {
            "state": {
                "equals": "NY"
            }
        }, 
        "or", 
        {
            "state": {
                "equals": "CA"
            }
        }
    ],
    "limit": 3,
    "columns": "all"
}

print(slicingdice.result(query_data))

import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");

        JSONObject queryData = new JSONObject()
        .put("query", new JSONArray()
            .put(new JSONObject()
                .put("state", new JSONObject()
                    .put("equals", "NY")))
            .put("or")
            .put(new JSONObject()
                .put("state", new JSONObject()
                    .put("equals", "CA"))))
        .put("limit", 3)
        .put("columns", "all");
        JSONObject result = slicingdice.result(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = {
    "query" => [
        {
            "state" => {
                "equals" => "NY"
            }
        }, 
        "or", 
        {
            "state" => {
                "equals" => "CA"
            }
        }
    ],
    "limit" => 3,
    "columns" => "all"
}

puts slicingdice.result(query_data)

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": "all"
};

slicingdice.result(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});

<?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" => "all"
);

print_r($slicingdice->result($queryData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");

            var queryData = new Dictionary<string, dynamic>{
                {"query", new List<dynamic>{
                    new Dictionary<string, dynamic>{
                        {"state", new Dictionary<string, dynamic>{
                            {"equals", "NY"}
                        }}
                    }, 
                    "or", 
                    new Dictionary<string, dynamic>{
                        {"state", new Dictionary<string, dynamic>{
                            {"equals", "CA"}
                        }}
                    }
                }},
                {"limit", 3},
                {"columns", "all"}
            };

            var result = slicingdice.Result(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

    queryData := map[string]interface{}{
        "query": []interface{}{
            map[string]interface{}{
                "state": map[string]interface{}{
                    "equals": "NY",
                },
            },
            "or",
            map[string]interface{}{
                "state": map[string]interface{}{
                    "equals": "CA",
                },
            },
        },
        "limit": 3,
        "columns": "all",
    }

    fmt.Println(slicingdice.Result(queryData))
}

Retrieving all entities with all columns

You can use this two techniques above together so you will be able to retrieve all the entities and all the columns at the same time.

SELECT * FROM default;
$ curl -X POST https://api.slicingdice.com/v1/sql \
    -H 'Authorization: MASTER_OR_WRITE_API_KEY' \
    -H 'Content-Type: application/sql' \
    -d 'SELECT * FROM default;'
curl -X POST https://api.slicingdice.com/v1/data_extraction/result \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
        "columns": "all"
    }'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

query_data = {
    "columns": "all"
}

print(slicingdice.result(query_data))

import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");

        JSONObject queryData = new JSONObject()
        .put("columns", "all");
        JSONObject result = slicingdice.result(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = {
    "columns" => "all"
}

puts slicingdice.result(query_data)

const SlicingDice = require('slicerjs');

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

const queryData = {
    "columns": "all"
};

slicingdice.result(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});

<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$queryData = array(
    "columns" => "all"
);

print_r($slicingdice->result($queryData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");

            var queryData = new Dictionary<string, dynamic>{
                {"columns", "all"}
            };

            var result = slicingdice.Result(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

    queryData := map[string]interface{}{
        "columns": "all",
    }

    fmt.Println(slicingdice.Result(queryData))
}

Retrieving metrics

You're able to ask SlicingDice for some metrics about your entities on data extraction result queries, imagine that you want to know the average of clicks per user on your system, you can do that simply passing average metric on columns parameter, as you can see on the example below.

SELECT city, state, AVG([clicks.value]) FROM default WHERE (state = 'NY' OR state = 'CA') AND [clicks.date] BETWEEN '{% convert_date 'YYYY-MM-DDT00:00:00Z' '-5d' %}' AND '{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}';
$ curl -X POST https://api.slicingdice.com/v1/sql \
    -H 'Authorization: MASTER_OR_WRITE_API_KEY' \
    -H 'Content-Type: application/sql' \
    -d 'SELECT city, state, AVG([clicks.value]) FROM default WHERE (state = 'NY' OR state = 'CA') AND [clicks.date] BETWEEN '{% convert_date 'YYYY-MM-DDT00:00:00Z' '-5d' %}' AND '{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}';'
curl -X POST https://api.slicingdice.com/v1/data_extraction/result \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
        "query": [
            {
                "state": { "equals": "NY" }
            },
            "or",
            {
                "state": { "equals": "CA" }
            }
        ],
        "columns": [
            "city",
            "state",
            {
            	"avg": "clicks",
            	"between": ["-5 days", "now"]
            }
        ],
        "limit": 3
    }'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

query_data = {
    "query": [
        {
            "state": {
                "equals": "NY"
            }
        }, 
        "or", 
        {
            "state": {
                "equals": "CA"
            }
        }
    ],
    "limit": 3,
    "columns": [
        "city", 
        "state", 
        {
            "avg": "clicks",
            "between": [
                "-5 days", 
                "now"
            ]
        }
    ]
}

print(slicingdice.result(query_data))

import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");

        JSONObject queryData = new JSONObject()
        .put("query", new JSONArray()
            .put(new JSONObject()
                .put("state", new JSONObject()
                    .put("equals", "NY")))
            .put("or")
            .put(new JSONObject()
                .put("state", new JSONObject()
                    .put("equals", "CA"))))
        .put("limit", 3)
        .put("columns", new JSONArray()
            .put("city")
            .put("state")
            .put(new JSONObject()
                .put("avg", "clicks")
                .put("between", new JSONArray()
                    .put("-5 days")
                    .put("now"))));
        JSONObject result = slicingdice.result(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

query_data = {
    "query" => [
        {
            "state" => {
                "equals" => "NY"
            }
        }, 
        "or", 
        {
            "state" => {
                "equals" => "CA"
            }
        }
    ],
    "limit" => 3,
    "columns" => [
        "city", 
        "state", 
        {
            "avg" => "clicks",
            "between" => [
                "-5 days", 
                "now"
            ]
        }
    ]
}

puts slicingdice.result(query_data)

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", 
        {
            "avg": "clicks",
            "between": [
                "-5 days", 
                "now"
            ]
        }
    ]
};

slicingdice.result(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});

<?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", 
        array(
            "avg" => "clicks",
            "between" => array(
                "-5 days", 
                "now"
            )
        )
    )
);

print_r($slicingdice->result($queryData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");

            var queryData = new Dictionary<string, dynamic>{
                {"query", new List<dynamic>{
                    new Dictionary<string, dynamic>{
                        {"state", new Dictionary<string, dynamic>{
                            {"equals", "NY"}
                        }}
                    }, 
                    "or", 
                    new Dictionary<string, dynamic>{
                        {"state", new Dictionary<string, dynamic>{
                            {"equals", "CA"}
                        }}
                    }
                }},
                {"limit", 3},
                {"columns", new List<dynamic>{
                    "city", 
                    "state", 
                    new Dictionary<string, dynamic>{
                        {"avg", "clicks"},
                        {"between", new List<dynamic>{
                            "-5 days", 
                            "now"
                        }}
                    }
                }}
            };

            var result = slicingdice.Result(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

    queryData := map[string]interface{}{
        "query": []interface{}{
            map[string]interface{}{
                "state": map[string]interface{}{
                    "equals": "NY",
                },
            },
            "or",
            map[string]interface{}{
                "state": map[string]interface{}{
                    "equals": "CA",
                },
            },
        },
        "limit": 3,
        "columns": []interface{}{
            "city",
            "state",
            map[string]interface{}{
                "avg": "clicks",
                "between": []interface{}{
                    "-5 days",
                    "now",
                },
            },
        },
    }

    fmt.Println(slicingdice.Result(queryData))
}

You can see more details about this on columns query parameters section.


Query operators, predicates and parameters

This section is focused on API-based JSON endpoint if you're using SQL to make your queries feel free to skip this part.

Supported operators

This is the list of supported operators to be used exclusively in the query part of the result data extraction query. As you can see, the list of operators is the same supported for the count-entities query type.

and

Usage example: Filter all entities that have the name equal to "Jeff" and age equal to 18.

or

Usage example: Filter all entities that have the name equal to "Jeff" or age equal to 18.

not

Usage example: Filter all entities that name equal to "Jeff" by age not equal to 18.

freqgroup

Usage example: Filter all entities that have the purchased on "NY" or on "CA" at least two times when summing up both occurrences.

Note that minfreq parameter is required to define a minimum frequency when evaluating the summed up frequencies.

Supported parameters

This is the list of supported parameters for the result data extraction query.

columns (optional)

Define which columns must be retrieved in the query. If not present, the query only returns entity IDs.

If "columns": "all" all the columns will be retrieved.

limit (optional)

Define the maximum number of entities that can be retrieved.

page-token (optional)

Fetch the next page of results when pagination occurred.

order (optional)

Order values by ascending or descending order.

Supported metrics predicates

The list below contains all the supported metrics predicates that can be applied for the following data types while retrieving its values:

1 . Requires the use of between predicates.

min

Answers the question: What is the minimum stored value in the age column?

max

Answers the question: What is the maximum stored value in the age column?

sum

Answers the question: What is the sum of all stored values in the purchases column?

avg

Answers the question: What is the average of all stored values in the age column?

between

Selects only data stored within given between time range

Note that this predicate is required for all event column.

Supported query predicates

The list below contains all the supported predicates that can be used in the query part of the result data extraction query.

equals

Usage example: How many entities have the column name equals to Jeff?

not-equals

Usage example: How many entities have the column name not-equals to Jeff?

range

Usage example: How many entities have the column age in the range from 0 to 18?

Note that range includes the beginning but not the ending in the results.

gt or greater-than

Usage example: How many entities have the column age greater than 50?"

gte or greater-than-or-equal

Usage example: How many entities have the column age greater than or equal to 18?".

lt or less-than

Usage example: How many entities have the column age less than 50?"

lte or less-than-or-equal

Usage example: How many entities have the column age less than or equal to 21?".

starts-with

Selects only values that start with the requested substring.

Usage example: What users have a name that starts with j?

ends-with

Selects only values that end with the requested substring.

Usage example: What products have a name that ends with ona?

contains

Selects only values that contain the requested substring.

Usage example: What countries contain m?

not-contains

Selects only values that do not contain the requested substring.

Usage example: What countries does not containm?

between

Usage example: How many entities have the column clicks equal to "pay now" between the dates {% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %} and {% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}?

Note that this predicate is required for all event column. In count queries, it must be used with the equals predicate. between includes both the beginning and the ending in the results.

minfreq

Usage example: How many entities have the column clicks equal to "pay now" at least 2 times between the dates {% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %} and {% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}?

Note that the minfreq parameter must be used with the equals and between predicates in the same query.

bypass-cache (optional)

Boolean value defining to bypass or not the cache mechanism. Use "bypass-cache": true to ignore cached data. bypass-cache is false by default, meaning that all queries will be cached.

dimension (optional)

In which the query should be performed over.

If you do not provide a value to dimension, the query will be performed over the default dimension.


Query examples

You can check the Result query examples to see a lot of result queries examples.