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

.NET/C#

.NET/C# client/SDK for SlicingDice

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

Installing the client

In order to install the .NET/C# client, you only need to install our package SlicingDice through the Package Manager from Visual Studio.

Install-Package SlicingDice

You can also install our client through the following nuget command.

nuget install SlicingDice

Source code

SlicingDice's .NET/C# client/SDK source code is available on Github.


Tests and Examples

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


Using the client

SlicingDice class encapsulates logic for sending requests to the API. Its methods are thin layers around the API endpoints, so their parameters and return values are JSON-like Dictionary<string, dynamic> objects with the same syntax as the API endpoints.

using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace Slicer.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            // Configure the client
            var client = new SlicingDice(masterKey: "API_KEY");

            // Creating a column
            var columnData = new Dictionary<string, dynamic>()
            {
                {"name", "Age"},
                {"api-name", "age"},
                {"description", "User age"},
                {"type", "integer"},
                {"storage", "latest-value"}
            };
            client.CreateColumn(columnData);

            // Inserting data
            var insertData = new Dictionary<string, dynamic>()
            {
                {"user1@slicingdice.com", new Dictionary<string, int>(){
                    {"age", 2}
                }}
            };
            client.Insert(insertData);

            // Querying data
            var queryData = new Dictionary<string, dynamic>()
            {
                {"query-name", "users-between-20-and-40"},
                {"query",
                    new List<Dictionary<string, dynamic>>()
                    {
                        new Dictionary<string, dynamic>(){
                            {"age", new Dictionary<string, dynamic>(){
                                    {"range", new List<int>(){ 20, 40 }}
                                }
                            }
                        }
                    }
                }
            };
            
            var result = client.CountEntity(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}

Database Keys

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

using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace Slicer.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            // Configure client with master Database key
            var client = new SlicingDice(masterKey: "MASTER_DATABASE_KEY");

            // Configure client with read Database key
            var client = new SlicingDice(readKey: "READ_DATABASE_KEY");

            // Configure client with write Database key
            var client = new SlicingDice(writeKey: "WRITE_DATABASE_KEY");

            // Configure client with custom Database key
            var client = new SlicingDice(customKey: "CUSTOM_DATABASE_KEY");
        }
    }
}

Constructor

SlicingDice(string masterKey=null, 
       string customKey=null, 
       string writeKey=null, 
       string readKey=null, 
       int timeout=60)
  • masterKey (string) - Master Database Key to used to authenticate requests on SlicingDice API.
  • customKey (string) - Custom Database Key to used to authenticate requests on SlicingDice API.
  • writeKey (string) - Write Database Key to used to authenticate requests on SlicingDice API.
  • readKey (string) - Read Database Key to used to authenticate requests on SlicingDice API.
  • timeout (int) - Amount of time, in seconds, to wait for results for each request.

Methods

  • Dictionary<string, dynamic> GetDatabase() - Get current database, identified by the given Database key. This method corresponds to a GET request at /database.
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 result = slicingdice.GetDatabase();
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> GetColumns() - Get all created columns, both active and inactive ones organized by dimension. This method corresponds to a GET request at /column.
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 result = slicingdice.getColumns();
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> CreateColumn(Dictionary<string, dynamic> query) - Create a new column. This method corresponds to a POST request at /column.
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 List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"type", "string"},
                    {"storage", "latest-value"},
                    {"api-name", "state"},
                    {"name", "User State"},
                    {"description", "State where the user lives"}
                }, 
                new Dictionary<string, dynamic>{
                    {"type", "integer"},
                    {"storage", "latest-value"},
                    {"api-name", "age"},
                    {"name", "User Age"}
                }
            };

            var result = slicingdice.createColumn(insertData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> Insert(Dictionary<string, dynamic> query) - Insert data to existing entities or create new entities, if necessary. This method corresponds to a POST request at /insert.
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>{
                {"UUID-01", new Dictionary<string, dynamic>{
                    {"dimension", "users"},
                    {"age", 25},
                    {"name", "Jeff"},
                    {"clicks", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"date", "2017-05-26T12:54:12Z"},
                            {"value", "Add to Cart"}
                        }, 
                        new Dictionary<string, dynamic>{
                            {"date", "2017-05-31T10:22:10Z"},
                            {"value", "Pay Now"}
                        }, 
                        new Dictionary<string, dynamic>{
                            {"date", "2017-06-03T17:05:25Z"},
                            {"value", "Support"}
                        }
                    }}
                }},
                {"auto-create", new List<dynamic>{
                    "dimension", 
                    "column"
                }}
            };

            var result = slicingdice.Insert(insertData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> ExistsEntity(List<string> ids, string dimension = null) - Verify which entities exist in a dimension (uses default dimension if not provided) given a list of entity IDs. This method corresponds to a POST request at /query/exists/entity.
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");

            string dimension = "users";
            var queryData = new List<string>{
                "user1@slicingdice.com", 
                "user2@slicingdice.com", 
                "user3@slicingdice.com", 
                "user4@slicingdice.com", 
                "user5@slicingdice.com"
            };

            var result = slicingdice.ExistsEntity(queryData, dimension);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> CountEntityTotal([List<string> dimensions]) - Count the number of stored entities in given dimensions (or in all dimensions by default). This method corresponds to a POST request at /query/count/entity/total.
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 result = slicingdice.CountEntityTotal();
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> CountEntity(Dictionary<string, dynamic> query) - Count the number of entities satisfying the given query. This method corresponds to a POST request at /query/count/entity.
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 List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"dimension", "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>{
                                    "2017-05-21T00:00:00Z", 
                                    "2017-06-04T00:00:00Z"
                                }}
                            }}
                        }
                    }}
                }
            };

            var result = slicingdice.CountEntity(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> CountEvent(Dictionary<string, dynamic> query) - Count the number of occurrences for events satisfying the given query. This method corresponds to a POST request at /query/count/event.
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 List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"query", new List<dynamic>{
                        new Dictionary<string, dynamic>{
                            {"actions", new Dictionary<string, dynamic>{
                                {"equals", "visited-page"},
                                {"between", new List<dynamic>{
                                    "2017-05-21T00:00:00Z", 
                                    "2017-06-04T00:00:00Z"
                                }}
                            }}
                        }
                    }},
                    {"query-name", "visited-page-events"}
                }
            };

            var result = slicingdice.CountEvent(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> TopValues(Dictionary<string, dynamic> query) - Return the top values for entities satisfying the given query. This method corresponds to a POST request at /query/top_values.
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>{
                {"name-contains-eff", new Dictionary<string, dynamic>{
                    {"dimension", "users"},
                    {"contains", new List<dynamic>{
                        "eff"
                    }},
                    {"name", 3}
                }}
            };

            var result = slicingdice.TopValues(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> Aggregation(Dictionary<string, dynamic> query) - Return the aggregation of all columns in the given query. This method corresponds to a POST request at /query/aggregation.
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>{
                {"filter", new List<dynamic>{
                    new Dictionary<string, dynamic>{
                        {"country", new Dictionary<string, dynamic>{
                            {"equals", "USA"}
                        }}
                    }
                }},
                {"query", new List<dynamic>{
                    new Dictionary<string, dynamic>{
                        {"purchased-products", 2},
                        {"between", new List<dynamic>{
                            "2017-05-16T00:00:00Z", 
                            "2017-06-04T00:00:00Z"
                        }}
                    }
                }}
            };

            var result = slicingdice.Aggregation(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> GetSavedQueries() - Get all saved queries. This method corresponds to a GET request at /query/saved.
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 result = slicingdice.GetSavedQueries();
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> CreateSavedQuery(Dictionary<string, dynamic> query) - Create a saved query at SlicingDice. This method corresponds to a POST request at /query/saved.
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"}
                        }}
                    }
                }},
                {"type", "count/entity"},
                {"name", "my-saved-query"},
                {"dimension", "users"}
            };

            var result = slicingdice.CreateSavedQuery(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> UpdateSavedQuery(string queryName, Dictionary<string, dynamic> query) - Update an existing saved query at SlicingDice. This method corresponds to a PUT request at /query/saved/:query_name.
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"}
                        }}
                    }
                }},
                {"type", "count/entity"},
                {"dimension", "users"}
            };

            var result = slicingdice.UpdateSavedQuery("my-saved-query", queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> GetSavedQuery(string queryName) - Executed a saved query at SlicingDice. This method corresponds to a GET request at /query/saved/:query_name.
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 result = slicingdice.GetSavedQuery("my-saved-query");
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> DeleteSavedQuery(string queryName) - Delete a saved query at SlicingDice. This method corresponds to a DELETE request at /query/saved/:query_name.
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 result = slicingdice.DeleteSavedQuery("my-saved-query");
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> Result(Dictionary<string, dynamic> query) - Retrieve stored values for entities satisfying the given query. This method corresponds to a POST request at /data_extraction/result.
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());
        }
    }
}
  • Dictionary<string, dynamic> Score(Dictionary<string, dynamic> query) - Retrieve stored values as well as their relevance for entities satisfying the given query. This method corresponds to a POST request at /data_extraction/score.
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"}
                        }}
                    }, 
                    "or", 
                    new Dictionary<string, dynamic>{
                        {"gender", new Dictionary<string, dynamic>{
                            {"equals", "male"}
                        }}
                    }, 
                    "or", 
                    new Dictionary<string, dynamic>{
                        {"age", new Dictionary<string, dynamic>{
                            {"range", new List<dynamic>{
                                18, 
                                25
                            }}
                        }}
                    }
                }},
                {"limit", 3},
                {"columns", new List<dynamic>{
                    "city", 
                    "state"
                }}
            };

            var result = slicingdice.Score(queryData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
  • Dictionary<string, dynamic> Sql(string statement) - Retrieve inserted values using a SQL syntax. This method corresponds to a POST request at /query/sql.

Query statement

using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new SlicingDice(masterKey: "MASTER_OR_READ_API_KEY");
            var query = "SELECT COUNT(*) FROM default WHERE age BETWEEN 0 AND 49";

            var result = client.Sql(query);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}

Insert statement

using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new SlicingDice(masterKey: "MASTER_OR_READ_API_KEY");
            var query = "SINSERT INTO default([entity-id], name, age) VALUES(1, 'john', 10)";

            var result = client.Sql(query);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}