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

Count entities

Count how many unique entities you have.


A SlicingDice count entities query is equivalent to a SQL query like this:

SELECT COUNT(DISTINCT User.UserID)
FROM User WHERE ...

Query purpose

You should use count entities to know how many unique entities you have in a particular table that satisfies the query conditions.

Count entities queries are ideal to answer this kind of questions:

  • How many male users from San Francisco there are on the table?
  • How many users accessed the page /online-demo or /platform more than 3 times in the last 7 days?
  • How many users are either male from San Francisco older than 25 or are female users from New York older than 24?

Query endpoint

In order to make a count entities query, you simply need to send a HTTPS POST request to https://api.slicingdice.com/v1/query/count/entity with an array of JSON objects (or a single JSON object) of queries identified by unique names (query-name), each containing a list of columns and conditions and operators, if any.

Pro Tip

Remember that you can also use the /test endpoint https://api.slicingdice.com/v1/test/insert to make data insertions and https://api.slicingdice.com/v1/test/query/count/entity to query before inserting real data to your production database.

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


Query syntax and structure

In this query below we will count how many unique entities there are on the table users, that have the name equals to Jeff and clicks equals to Pay Now between {% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %} and {% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}.

curl -X POST https://api.slicingdice.com/v1/query/count/entity \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
        {
            "query-name": "jeff-user-clicked-to-pay",
            "table": "users",
            "query": [
                {
                    "name": {
                        "equals": "Jeff"
                    }
                },
                "and",
                {
                    "clicks": {
                        "equals": "Pay Now",
                        "between": [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }
            ],
            "bypass-cache": true
        }
    ]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

query_data = [
    {
        "table": "users",
        "query-name": "jeff-user-clicked-to-pay",
        "bypass-cache": True,
        "query": [
            {
                "name": {
                    "equals": "Jeff"
                }
            }, 
            "and", 
            {
                "clicks": {
                    "equals": "Pay Now",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ]
    }
]

print(slicingdice.count_entity(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", true);

        JSONArray queryData = new JSONArray()
        .put(new JSONObject()
            .put("table", "users")
            .put("query-name", "jeff-user-clicked-to-pay")
            .put("bypass-cache", true)
            .put("query", new JSONArray()
                .put(new JSONObject()
                    .put("name", new JSONObject()
                        .put("equals", "Jeff")))
                .put("and")
                .put(new JSONObject()
                    .put("clicks", new JSONObject()
                        .put("equals", "Pay Now")
                        .put("between", new JSONArray()
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}")
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"))))));
        JSONObject result = slicingdice.countEntity(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

query_data = [
    {
        "table" => "users",
        "query-name" => "jeff-user-clicked-to-pay",
        "bypass-cache" => true,
        "query" => [
            {
                "name" => {
                    "equals" => "Jeff"
                }
            }, 
            "and", 
            {
                "clicks" => {
                    "equals" => "Pay Now",
                    "between" => [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ]
    }
]

puts slicingdice.count_entity(query_data)

const SlicingDice = require('slicerjs');

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

const queryData = [
    {
        "table": "users",
        "query-name": "jeff-user-clicked-to-pay",
        "bypass-cache": true,
        "query": [
            {
                "name": {
                    "equals": "Jeff"
                }
            }, 
            "and", 
            {
                "clicks": {
                    "equals": "Pay Now",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ]
    }
];

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

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

$queryData = array(
    array(
        "table" => "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(
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    )
                )
            )
        )
    )
);

print_r($slicingdice->countEntity($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", usesTestEndpoint: true);

            var queryData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"table", "users"},
                    {"query-name", "jeff-user-clicked-to-pay"},
                    {"bypass-cache", true},
                    {"query", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"name", new Dictionary<string, dynamic>{
                                {"equals", "Jeff"}
                            }}
                        }, 
                        "and", 
                        new Dictionary<string, dynamic>{
                            {"clicks", new Dictionary<string, dynamic>{
                                {"equals", "Pay Now"},
                                {"between", new List<dynamic>{
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                                }}
                            }}
                        }
                    }}
                }
            };

            var result = slicingdice.CountEntity(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)
    slicingdice.Test = true

    queryData := []interface{}{
        map[string]interface{}{
            "table": "users",
            "query-name": "jeff-user-clicked-to-pay",
            "bypass-cache": true,
            "query": []interface{}{
                map[string]interface{}{
                    "name": map[string]interface{}{
                        "equals": "Jeff",
                    },
                },
                "and",
                map[string]interface{}{
                    "clicks": map[string]interface{}{
                        "equals": "Pay Now",
                        "between": []interface{}{
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}",
                        },
                    },
                },
            },
        },
    }

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

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

{
    "status": "success",
    "result": {
        "jeff-user-clicked-to-pay": 1
    },
    "took": 0.103
}

Let's understand each component of the API response:

  • status - Indicating whether the request was successfully processed or not.
  • result - Query name (jeff-user-clicked-to-pay) and the total number of entities that matches all query conditions (1).
  • took - Time spent processing this request, in seconds.

Counting the entire table

In this query below we will count how many unique entities there are on the entire table users.
Note that the "query" parameter is not specified on json.

curl -X POST https://api.slicingdice.com/v1/query/count/entity \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
        {
            "query-name": "users-entities-total",
            "table": "users",
            "bypass-cache": true
        }
    ]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

query_data = [
    {
        "table": "users",
        "query-name": "users-entities-total",
        "bypass-cache": True
    }
]

print(slicingdice.count_entity(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", true);

        JSONArray queryData = new JSONArray()
        .put(new JSONObject()
            .put("table", "users")
            .put("query-name", "users-entities-total")
            .put("bypass-cache", true));
        JSONObject result = slicingdice.countEntity(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

query_data = [
    {
        "table" => "users",
        "query-name" => "users-entities-total",
        "bypass-cache" => true
    }
]

puts slicingdice.count_entity(query_data)

const SlicingDice = require('slicerjs');

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

const queryData = [
    {
        "table": "users",
        "query-name": "users-entities-total",
        "bypass-cache": true
    }
];

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

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

$queryData = array(
    array(
        "table" => "users",
        "query-name" => "users-entities-total",
        "bypass-cache" => true
    )
);

print_r($slicingdice->countEntity($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", usesTestEndpoint: true);

            var queryData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"table", "users"},
                    {"query-name", "users-entities-total"},
                    {"bypass-cache", true}
                }
            };

            var result = slicingdice.CountEntity(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)
    slicingdice.Test = true

    queryData := []interface{}{
        map[string]interface{}{
            "table": "users",
            "query-name": "users-entities-total",
            "bypass-cache": true,
        },
    }

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

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

{
	"status": "success",
	"result": {
		"users-entities-total": 1
	},
	"took": 0.035
}
  • status - Indicating whether the request was successfully processed or not.
  • result - Query name (users-entities-total) and the total number of entities on the table users.
  • took - Time spent processing this request, in seconds.

Query operators, predicates and parameters

Supported operators

This is the list of supported operators for the count entities query.

and

Usage example: How many entities have the name equal to Jeff and age equal to 18?

or

Usage example: How many entities have the name equal to Jeff or age equal to 18?

not

Usage example: How many entities name equal to Jeff by age not equal to 18?

freqgroup

Usage example: How many entities have the purchased in 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 predicates

This is the list of supported predicates for the count entities 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?".

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.

Supported parameters

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 parameters 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.

query-name (optional)

You can send multiple queries in a same request, so when you send more than one query, these queries must be identified by unique names.

table (optional)

In which the query should be performed over.

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


Query examples

Find below many count entities queries, using multiple data types, operators, predicates and parameters.

Ready-to-use examples

All SlicingDice's clients/SDK have many ready-to-use examples on their Github repositories.
Check the our client/SDK page to know more.

Complete example

Below you can find a complete count entities query example, using most of the supported operators and predicates.

Example: How many users that clicked at "Pay Now" or "Add to Cart" at least 3 times, are between 17 and 25 years old and have an income greater then $2,500 or are not inactive users?

curl -X POST https://api.slicingdice.com/v1/query/count/entity \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
        "query-name": "at-least-2-clicks",
        "table": "users",
        "query": [
            {
                "freqgroup": [
                    {
                        "clicks": {
                            "equals": "Pay Now",
                            "between": [
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                            ]
                        }
                    }, {
                        "clicks": {
                            "equals": "Add To Cart",
                            "between": [
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                            ]
                        }
                    }
                ],
                "minfreq": 3
            },
            "and",
            {
                "age": { "range": [17, 25] }
            },
            "and",
            [
                {
                    "status": { "not-equals": "inactive" }
                },
                "or",
                {
                    "income": { "greater-than": 2500 }
                }
            ]
        ]
    }'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

query_data = {
    "table": "users",
    "query-name": "at-least-2-clicks",
    "query": [
        {
            "minfreq": 3,
            "freqgroup": [
                {
                    "clicks": {
                        "equals": "Pay Now",
                        "between": [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }, 
                {
                    "clicks": {
                        "equals": "Add To Cart",
                        "between": [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }
            ]
        }, 
        "and", 
        {
            "age": {
                "range": [
                    17, 
                    25
                ]
            }
        }, 
        "and", 
        [
            {
                "status": {
                    "not-equals": "inactive"
                }
            }, 
            "or", 
            {
                "income": {
                    "greater-than": 2500
                }
            }
        ]
    ]
}

print(slicingdice.count_entity(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", true);

        JSONObject queryData = new JSONObject()
        .put("table", "users")
        .put("query-name", "at-least-2-clicks")
        .put("query", new JSONArray()
            .put(new JSONObject()
                .put("minfreq", 3)
                .put("freqgroup", new JSONArray()
                    .put(new JSONObject()
                        .put("clicks", new JSONObject()
                            .put("equals", "Pay Now")
                            .put("between", new JSONArray()
                                .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}")
                                .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"))))
                    .put(new JSONObject()
                        .put("clicks", new JSONObject()
                            .put("equals", "Add To Cart")
                            .put("between", new JSONArray()
                                .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}")
                                .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"))))))
            .put("and")
            .put(new JSONObject()
                .put("age", new JSONObject()
                    .put("range", new JSONArray()
                        .put(17)
                        .put(25))))
            .put("and")
            .put(new JSONArray()
                .put(new JSONObject()
                    .put("status", new JSONObject()
                        .put("not-equals", "inactive")))
                .put("or")
                .put(new JSONObject()
                    .put("income", new JSONObject()
                        .put("greater-than", 2500)))));
        JSONObject result = slicingdice.countEntity(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

query_data = {
    "table" => "users",
    "query-name" => "at-least-2-clicks",
    "query" => [
        {
            "minfreq" => 3,
            "freqgroup" => [
                {
                    "clicks" => {
                        "equals" => "Pay Now",
                        "between" => [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }, 
                {
                    "clicks" => {
                        "equals" => "Add To Cart",
                        "between" => [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }
            ]
        }, 
        "and", 
        {
            "age" => {
                "range" => [
                    17, 
                    25
                ]
            }
        }, 
        "and", 
        [
            {
                "status" => {
                    "not-equals" => "inactive"
                }
            }, 
            "or", 
            {
                "income" => {
                    "greater-than" => 2500
                }
            }
        ]
    ]
}

puts slicingdice.count_entity(query_data)

const SlicingDice = require('slicerjs');

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

const queryData = {
    "table": "users",
    "query-name": "at-least-2-clicks",
    "query": [
        {
            "minfreq": 3,
            "freqgroup": [
                {
                    "clicks": {
                        "equals": "Pay Now",
                        "between": [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }, 
                {
                    "clicks": {
                        "equals": "Add To Cart",
                        "between": [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }
            ]
        }, 
        "and", 
        {
            "age": {
                "range": [
                    17, 
                    25
                ]
            }
        }, 
        "and", 
        [
            {
                "status": {
                    "not-equals": "inactive"
                }
            }, 
            "or", 
            {
                "income": {
                    "greater-than": 2500
                }
            }
        ]
    ]
};

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

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

$queryData = array(
    "table" => "users",
    "query-name" => "at-least-2-clicks",
    "query" => array(
        array(
            "minfreq" => 3,
            "freqgroup" => array(
                array(
                    "clicks" => array(
                        "equals" => "Pay Now",
                        "between" => array(
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        )
                    )
                ), 
                array(
                    "clicks" => array(
                        "equals" => "Add To Cart",
                        "between" => array(
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        )
                    )
                )
            )
        ), 
        "and", 
        array(
            "age" => array(
                "range" => array(
                    17, 
                    25
                )
            )
        ), 
        "and", 
        array(
            array(
                "status" => array(
                    "not-equals" => "inactive"
                )
            ), 
            "or", 
            array(
                "income" => array(
                    "greater-than" => 2500
                )
            )
        )
    )
);

print_r($slicingdice->countEntity($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", usesTestEndpoint: true);

            var queryData = new Dictionary<string, dynamic>{
                {"table", "users"},
                {"query-name", "at-least-2-clicks"},
                {"query", new List<dynamic>{
                    new Dictionary<string, dynamic>{
                        {"minfreq", 3},
                        {"freqgroup", new List<dynamic>{
                            new Dictionary<string, dynamic>{
                                {"clicks", new Dictionary<string, dynamic>{
                                    {"equals", "Pay Now"},
                                    {"between", new List<dynamic>{
                                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                                    }}
                                }}
                            }, 
                            new Dictionary<string, dynamic>{
                                {"clicks", new Dictionary<string, dynamic>{
                                    {"equals", "Add To Cart"},
                                    {"between", new List<dynamic>{
                                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                                    }}
                                }}
                            }
                        }}
                    }, 
                    "and", 
                    new Dictionary<string, dynamic>{
                        {"age", new Dictionary<string, dynamic>{
                            {"range", new List<dynamic>{
                                17, 
                                25
                            }}
                        }}
                    }, 
                    "and", 
                    new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"status", new Dictionary<string, dynamic>{
                                {"not-equals", "inactive"}
                            }}
                        }, 
                        "or", 
                        new Dictionary<string, dynamic>{
                            {"income", new Dictionary<string, dynamic>{
                                {"greater-than", 2500}
                            }}
                        }
                    }
                }}
            };

            var result = slicingdice.CountEntity(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)
    slicingdice.Test = true

    queryData := map[string]interface{}{
        "table": "users",
        "query-name": "at-least-2-clicks",
        "query": []interface{}{
            map[string]interface{}{
                "minfreq": 3,
                "freqgroup": []interface{}{
                    map[string]interface{}{
                        "clicks": map[string]interface{}{
                            "equals": "Pay Now",
                            "between": []interface{}{
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}",
                            },
                        },
                    },
                    map[string]interface{}{
                        "clicks": map[string]interface{}{
                            "equals": "Add To Cart",
                            "between": []interface{}{
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}",
                            },
                        },
                    },
                },
            },
            "and",
            map[string]interface{}{
                "age": map[string]interface{}{
                    "range": []interface{}{
                        17,
                        25,
                    },
                },
            },
            "and",
            []interface{}{
                map[string]interface{}{
                    "status": map[string]interface{}{
                        "not-equals": "inactive",
                    },
                },
                "or",
                map[string]interface{}{
                    "income": map[string]interface{}{
                        "greater-than": 2500,
                    },
                },
            },
        },
    }

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

Example of multiple queries in a single request

It's possible to run several queries in the same API request by sending them as a JSON array of objects

Example:

  1. How many users clicked on "Pay Now"?
  2. How many users are called Jeff?
curl -X POST https://api.slicingdice.com/v1/query/count/entity \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
        {
            "query-name": "users-clicked-to-pay",
            "table": "users",
            "query": [
                {
                    "clicks": {
                        "equals": "Pay Now",
                        "between": [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }
            ],
            "bypass-cache": true
        }, {
            "query-name": "users-named-jeff",
            "table": "users",
            "query": [
                {
                    "name": { "equals": "Jeff" }
                }
            ],
            "bypass-cache": true
        }
    ]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

query_data = [
    {
        "table": "users",
        "query-name": "users-clicked-to-pay",
        "bypass-cache": True,
        "query": [
            {
                "clicks": {
                    "equals": "Pay Now",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ]
    }, 
    {
        "table": "users",
        "query-name": "users-named-jeff",
        "bypass-cache": True,
        "query": [
            {
                "name": {
                    "equals": "Jeff"
                }
            }
        ]
    }
]

print(slicingdice.count_entity(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", true);

        JSONArray queryData = new JSONArray()
        .put(new JSONObject()
            .put("table", "users")
            .put("query-name", "users-clicked-to-pay")
            .put("bypass-cache", true)
            .put("query", new JSONArray()
                .put(new JSONObject()
                    .put("clicks", new JSONObject()
                        .put("equals", "Pay Now")
                        .put("between", new JSONArray()
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}")
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"))))))
        .put(new JSONObject()
            .put("table", "users")
            .put("query-name", "users-named-jeff")
            .put("bypass-cache", true)
            .put("query", new JSONArray()
                .put(new JSONObject()
                    .put("name", new JSONObject()
                        .put("equals", "Jeff")))));
        JSONObject result = slicingdice.countEntity(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

query_data = [
    {
        "table" => "users",
        "query-name" => "users-clicked-to-pay",
        "bypass-cache" => true,
        "query" => [
            {
                "clicks" => {
                    "equals" => "Pay Now",
                    "between" => [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ]
    }, 
    {
        "table" => "users",
        "query-name" => "users-named-jeff",
        "bypass-cache" => true,
        "query" => [
            {
                "name" => {
                    "equals" => "Jeff"
                }
            }
        ]
    }
]

puts slicingdice.count_entity(query_data)

const SlicingDice = require('slicerjs');

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

const queryData = [
    {
        "table": "users",
        "query-name": "users-clicked-to-pay",
        "bypass-cache": true,
        "query": [
            {
                "clicks": {
                    "equals": "Pay Now",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ]
    }, 
    {
        "table": "users",
        "query-name": "users-named-jeff",
        "bypass-cache": true,
        "query": [
            {
                "name": {
                    "equals": "Jeff"
                }
            }
        ]
    }
];

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

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

$queryData = array(
    array(
        "table" => "users",
        "query-name" => "users-clicked-to-pay",
        "bypass-cache" => true,
        "query" => array(
            array(
                "clicks" => array(
                    "equals" => "Pay Now",
                    "between" => array(
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    )
                )
            )
        )
    ), 
    array(
        "table" => "users",
        "query-name" => "users-named-jeff",
        "bypass-cache" => true,
        "query" => array(
            array(
                "name" => array(
                    "equals" => "Jeff"
                )
            )
        )
    )
);

print_r($slicingdice->countEntity($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", usesTestEndpoint: true);

            var queryData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"table", "users"},
                    {"query-name", "users-clicked-to-pay"},
                    {"bypass-cache", true},
                    {"query", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"clicks", new Dictionary<string, dynamic>{
                                {"equals", "Pay Now"},
                                {"between", new List<dynamic>{
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                                }}
                            }}
                        }
                    }}
                }, 
                new Dictionary<string, dynamic>{
                    {"table", "users"},
                    {"query-name", "users-named-jeff"},
                    {"bypass-cache", true},
                    {"query", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"name", new Dictionary<string, dynamic>{
                                {"equals", "Jeff"}
                            }}
                        }
                    }}
                }
            };

            var result = slicingdice.CountEntity(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)
    slicingdice.Test = true

    queryData := []interface{}{
        map[string]interface{}{
            "table": "users",
            "query-name": "users-clicked-to-pay",
            "bypass-cache": true,
            "query": []interface{}{
                map[string]interface{}{
                    "clicks": map[string]interface{}{
                        "equals": "Pay Now",
                        "between": []interface{}{
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}",
                        },
                    },
                },
            },
        },
        map[string]interface{}{
            "table": "users",
            "query-name": "users-named-jeff",
            "bypass-cache": true,
            "query": []interface{}{
                map[string]interface{}{
                    "name": map[string]interface{}{
                        "equals": "Jeff",
                    },
                },
            },
        },
    }

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

Minfreq example

Use minfreq to filter users based on the frequency certain event happened.

Example: How many users added at least 5 products to their cart?

curl -X POST https://api.slicingdice.com/v1/query/count/entity \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
        {
            "query-name": "shopaholic-users",
            "table": "users",
            "query": [
                {
                    "clicks": {
                        "equals": "Add To Cart",
                        "between": [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ],
                        "minfreq": 5
                    }
                }
            ],
            "bypass-cache": true
        }
    ]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

query_data = [
    {
        "table": "users",
        "query-name": "shopaholic-users",
        "bypass-cache": True,
        "query": [
            {
                "clicks": {
                    "minfreq": 5,
                    "equals": "Add To Cart",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ]
    }
]

print(slicingdice.count_entity(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", true);

        JSONArray queryData = new JSONArray()
        .put(new JSONObject()
            .put("table", "users")
            .put("query-name", "shopaholic-users")
            .put("bypass-cache", true)
            .put("query", new JSONArray()
                .put(new JSONObject()
                    .put("clicks", new JSONObject()
                        .put("minfreq", 5)
                        .put("equals", "Add To Cart")
                        .put("between", new JSONArray()
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}")
                            .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"))))));
        JSONObject result = slicingdice.countEntity(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

query_data = [
    {
        "table" => "users",
        "query-name" => "shopaholic-users",
        "bypass-cache" => true,
        "query" => [
            {
                "clicks" => {
                    "minfreq" => 5,
                    "equals" => "Add To Cart",
                    "between" => [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ]
    }
]

puts slicingdice.count_entity(query_data)

const SlicingDice = require('slicerjs');

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

const queryData = [
    {
        "table": "users",
        "query-name": "shopaholic-users",
        "bypass-cache": true,
        "query": [
            {
                "clicks": {
                    "minfreq": 5,
                    "equals": "Add To Cart",
                    "between": [
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    ]
                }
            }
        ]
    }
];

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

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

$queryData = array(
    array(
        "table" => "users",
        "query-name" => "shopaholic-users",
        "bypass-cache" => true,
        "query" => array(
            array(
                "clicks" => array(
                    "minfreq" => 5,
                    "equals" => "Add To Cart",
                    "between" => array(
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                    )
                )
            )
        )
    )
);

print_r($slicingdice->countEntity($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", usesTestEndpoint: true);

            var queryData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"table", "users"},
                    {"query-name", "shopaholic-users"},
                    {"bypass-cache", true},
                    {"query", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"clicks", new Dictionary<string, dynamic>{
                                {"minfreq", 5},
                                {"equals", "Add To Cart"},
                                {"between", new List<dynamic>{
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                                    "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                                }}
                            }}
                        }
                    }}
                }
            };

            var result = slicingdice.CountEntity(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)
    slicingdice.Test = true

    queryData := []interface{}{
        map[string]interface{}{
            "table": "users",
            "query-name": "shopaholic-users",
            "bypass-cache": true,
            "query": []interface{}{
                map[string]interface{}{
                    "clicks": map[string]interface{}{
                        "minfreq": 5,
                        "equals": "Add To Cart",
                        "between": []interface{}{
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}",
                        },
                    },
                },
            },
        },
    }

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

Range example

Example: How many users are under 18 years old?

curl -X POST https://api.slicingdice.com/v1/query/count/entity \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
        {
            "query-name": "under-18-years-old-users",
            "table": "users",
            "query": [
                {
                    "age": { "range": [0, 18] }
                }
            ],
            "bypass-cache": true
        }
    ]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

query_data = [
    {
        "table": "users",
        "query-name": "under-18-years-old-users",
        "bypass-cache": True,
        "query": [
            {
                "age": {
                    "range": [
                        0, 
                        18
                    ]
                }
            }
        ]
    }
]

print(slicingdice.count_entity(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", true);

        JSONArray queryData = new JSONArray()
        .put(new JSONObject()
            .put("table", "users")
            .put("query-name", "under-18-years-old-users")
            .put("bypass-cache", true)
            .put("query", new JSONArray()
                .put(new JSONObject()
                    .put("age", new JSONObject()
                        .put("range", new JSONArray()
                            .put(0)
                            .put(18))))));
        JSONObject result = slicingdice.countEntity(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

query_data = [
    {
        "table" => "users",
        "query-name" => "under-18-years-old-users",
        "bypass-cache" => true,
        "query" => [
            {
                "age" => {
                    "range" => [
                        0, 
                        18
                    ]
                }
            }
        ]
    }
]

puts slicingdice.count_entity(query_data)

const SlicingDice = require('slicerjs');

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

const queryData = [
    {
        "table": "users",
        "query-name": "under-18-years-old-users",
        "bypass-cache": true,
        "query": [
            {
                "age": {
                    "range": [
                        0, 
                        18
                    ]
                }
            }
        ]
    }
];

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

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

$queryData = array(
    array(
        "table" => "users",
        "query-name" => "under-18-years-old-users",
        "bypass-cache" => true,
        "query" => array(
            array(
                "age" => array(
                    "range" => array(
                        0, 
                        18
                    )
                )
            )
        )
    )
);

print_r($slicingdice->countEntity($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", usesTestEndpoint: true);

            var queryData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"table", "users"},
                    {"query-name", "under-18-years-old-users"},
                    {"bypass-cache", true},
                    {"query", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"age", new Dictionary<string, dynamic>{
                                {"range", new List<dynamic>{
                                    0, 
                                    18
                                }}
                            }}
                        }
                    }}
                }
            };

            var result = slicingdice.CountEntity(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)
    slicingdice.Test = true

    queryData := []interface{}{
        map[string]interface{}{
            "table": "users",
            "query-name": "under-18-years-old-users",
            "bypass-cache": true,
            "query": []interface{}{
                map[string]interface{}{
                    "age": map[string]interface{}{
                        "range": []interface{}{
                            0,
                            18,
                        },
                    },
                },
            },
        },
    }

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

Freqgroup example

Example: How many users clicked at "Pay Now" or "Add To Cart" at least 2 times?

curl -X POST https://api.slicingdice.com/v1/query/count/entity \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
        "query-name": "at-least-2-clicks",
        "table": "users",
        "query": [
            {
                "freqgroup": [
                    {
                        "clicks": {
                            "equals": "Pay Now",
                            "between": [
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                            ]
                        }
                    }, {
                        "clicks": {
                            "equals": "Add To Cart",
                            "between": [
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                            ]
                        }
                    }
                ],
                "minfreq": 2
            }
        ]
    }'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

query_data = {
    "table": "users",
    "query-name": "at-least-2-clicks",
    "query": [
        {
            "minfreq": 2,
            "freqgroup": [
                {
                    "clicks": {
                        "equals": "Pay Now",
                        "between": [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }, 
                {
                    "clicks": {
                        "equals": "Add To Cart",
                        "between": [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }
            ]
        }
    ]
}

print(slicingdice.count_entity(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", true);

        JSONObject queryData = new JSONObject()
        .put("table", "users")
        .put("query-name", "at-least-2-clicks")
        .put("query", new JSONArray()
            .put(new JSONObject()
                .put("minfreq", 2)
                .put("freqgroup", new JSONArray()
                    .put(new JSONObject()
                        .put("clicks", new JSONObject()
                            .put("equals", "Pay Now")
                            .put("between", new JSONArray()
                                .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}")
                                .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"))))
                    .put(new JSONObject()
                        .put("clicks", new JSONObject()
                            .put("equals", "Add To Cart")
                            .put("between", new JSONArray()
                                .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}")
                                .put("{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}")))))));
        JSONObject result = slicingdice.countEntity(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

query_data = {
    "table" => "users",
    "query-name" => "at-least-2-clicks",
    "query" => [
        {
            "minfreq" => 2,
            "freqgroup" => [
                {
                    "clicks" => {
                        "equals" => "Pay Now",
                        "between" => [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }, 
                {
                    "clicks" => {
                        "equals" => "Add To Cart",
                        "between" => [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }
            ]
        }
    ]
}

puts slicingdice.count_entity(query_data)

const SlicingDice = require('slicerjs');

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

const queryData = {
    "table": "users",
    "query-name": "at-least-2-clicks",
    "query": [
        {
            "minfreq": 2,
            "freqgroup": [
                {
                    "clicks": {
                        "equals": "Pay Now",
                        "between": [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }, 
                {
                    "clicks": {
                        "equals": "Add To Cart",
                        "between": [
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        ]
                    }
                }
            ]
        }
    ]
};

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

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

$queryData = array(
    "table" => "users",
    "query-name" => "at-least-2-clicks",
    "query" => array(
        array(
            "minfreq" => 2,
            "freqgroup" => array(
                array(
                    "clicks" => array(
                        "equals" => "Pay Now",
                        "between" => array(
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        )
                    )
                ), 
                array(
                    "clicks" => array(
                        "equals" => "Add To Cart",
                        "between" => array(
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                            "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                        )
                    )
                )
            )
        )
    )
);

print_r($slicingdice->countEntity($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", usesTestEndpoint: true);

            var queryData = new Dictionary<string, dynamic>{
                {"table", "users"},
                {"query-name", "at-least-2-clicks"},
                {"query", new List<dynamic>{
                    new Dictionary<string, dynamic>{
                        {"minfreq", 2},
                        {"freqgroup", new List<dynamic>{
                            new Dictionary<string, dynamic>{
                                {"clicks", new Dictionary<string, dynamic>{
                                    {"equals", "Pay Now"},
                                    {"between", new List<dynamic>{
                                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                                    }}
                                }}
                            }, 
                            new Dictionary<string, dynamic>{
                                {"clicks", new Dictionary<string, dynamic>{
                                    {"equals", "Add To Cart"},
                                    {"between", new List<dynamic>{
                                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}", 
                                        "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}"
                                    }}
                                }}
                            }
                        }}
                    }
                }}
            };

            var result = slicingdice.CountEntity(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)
    slicingdice.Test = true

    queryData := map[string]interface{}{
        "table": "users",
        "query-name": "at-least-2-clicks",
        "query": []interface{}{
            map[string]interface{}{
                "minfreq": 2,
                "freqgroup": []interface{}{
                    map[string]interface{}{
                        "clicks": map[string]interface{}{
                            "equals": "Pay Now",
                            "between": []interface{}{
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}",
                            },
                        },
                    },
                    map[string]interface{}{
                        "clicks": map[string]interface{}{
                            "equals": "Add To Cart",
                            "between": []interface{}{
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-15d' %}",
                                "{% convert_date 'YYYY-MM-DDT00:00:00Z' '-1d' %}",
                            },
                        },
                    },
                },
            },
        },
    }

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

Contains example

Example: How many cities contains "new" on the name?

curl -X POST https://api.slicingdice.com/v1/query/count/entity \
    -H 'Authorization: MASTER_OR_READ_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
        {
            "query-name": "cities-contains-new",
            "query": [
                {
                    "city": {
                        "contains": "new"
                    }
                }
            ],
            "bypass-cache": true
        }
    ]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

query_data = [
    {
        "query": [
            {
                "city": {
                    "contains": "new"
                }
            }
        ],
        "query-name": "cities-contains-new",
        "bypass-cache": True
    }
]

print(slicingdice.count_entity(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", true);

        JSONArray queryData = new JSONArray()
        .put(new JSONObject()
            .put("query", new JSONArray()
                .put(new JSONObject()
                    .put("city", new JSONObject()
                        .put("contains", "new"))))
            .put("query-name", "cities-contains-new")
            .put("bypass-cache", true));
        JSONObject result = slicingdice.countEntity(queryData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

query_data = [
    {
        "query" => [
            {
                "city" => {
                    "contains" => "new"
                }
            }
        ],
        "query-name" => "cities-contains-new",
        "bypass-cache" => true
    }
]

puts slicingdice.count_entity(query_data)
const SlicingDice = require('slicerjs');

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

const queryData = [
    {
        "query": [
            {
                "city": {
                    "contains": "new"
                }
            }
        ],
        "query-name": "cities-contains-new",
        "bypass-cache": true
    }
];

slicingdice.countEntity(queryData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$queryData = array(
    array(
        "query" => array(
            array(
                "city" => array(
                    "contains" => "new"
                )
            )
        ),
        "query-name" => "cities-contains-new",
        "bypass-cache" => true
    )
);

print_r($slicingdice->countEntity($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", usesTestEndpoint: true);

            var queryData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"query", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"city", new Dictionary<string, dynamic>{
                                {"contains", "new"}
                            }}
                        }
                    }},
                    {"query-name", "cities-contains-new"},
                    {"bypass-cache", true}
                }
            };

            var result = slicingdice.CountEntity(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)
    slicingdice.Test = true

    queryData := []interface{}{
        map[string]interface{}{
            "query": []interface{}{
                map[string]interface{}{
                    "city": map[string]interface{}{
                        "contains": "new",
                    },
                },
            },
            "query-name": "cities-contains-new",
            "bypass-cache": true,
        },
    }

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

What's Next

Count events

Count entities

Count how many unique entities you have.