SlicingDice API Docs

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

Go

Go client/SDK for SlicingDice

You can use the SlicingDice's Go 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 Go client, you only need to execute the go get command.

go get github.com/SlicingDice/slicingdice-go

Source code

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

Build Status: CircleCI


Tests and Examples

At the Go 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 interface{} objects with the same syntax as the API endpoints.

package main

import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)

func main() {
    // Configure client
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "mykey"
    client := slicingdice.New(keys, 60)

    // Creating a column
    column_data := make(map[string]interface{})
    column_data["name"] = "Age"
    column_data["api-name"] = "age"
    column_data["description"] = "User age"
    column_data["type"] = "integer"
    column_data["storage"] = "latest-value"
    client.CreateColumn(column_data)

    // Inserting data
    insert_data := make(map[string]interface{})
    insert_data["user1@slicingdice.com"] = map[string]int{
        "age": 22,
    }
    client.Insert(insert_data)

    // Querying data
    query_data := map[string]interface{}{
        "query-name": "users-between-20-and-40",
        "query": []map[string]interface{} {
            map[string]interface{}{
                "age": map[string][]int{
                    "range": []int{20, 40},
                },
            },
        },
    }
    result, _ := client.CountEntity(query_data)
    fmt.Println(result["status"])
}

API Keys

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

package main

import (
    "fmt"
    "github.com/slicingdice/slicingdice-go"
)

func main() {
    keys := new(slicingdice.APIKey)

    // Configure client with master API key
    keys.MasterKey = "MASTER_API_KEY"

    // Configure client with read API key
    keys.ReadKey = "READ_API_KEY"

    // Configure client with write API key
    keys.WriteKey = "WRITE_API_KEY"

    // Configure client with custom API key
    keys.CustomKey = "CUSTOM_API_KEY"

    sd := slicingdice.New(keys, 60)
}

Constructor

New(key *APIKey, timeout int) *SlicingDice
  • key (APIKey) - A struct containing API keys used to authenticate SlicingDice API requests. This object must have at least one of the following attributes:
    • MasterKey - Master API Key to used to authenticate requests on SlicingDice API.
    • WriteKey - Write API Key to used to authenticate requests on SlicingDice API.
    • ReadKey - Read API Key to used to authenticate requests on SlicingDice API.
    • CustomKey - Custom API Key to used to authenticate requests on SlicingDice API.
  • timeout (int) - Amount of time, in seconds, to wait for results for each request.

Methods

  • GetDatabase() - Get all created databases, both active and inactive ones. This method corresponds to a GET request at /database.
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)
    fmt.Println(slicingdice.GetDatabase())
}
  • GetColumns() - Get all created columns, both active and inactive ones organized by table. This method corresponds to a GET request at /column.
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)

    fmt.Println(slicingdice.getColumns())
}
  • CreateColumn(query interface{}) - Create a new column. This method corresponds to a POST request at /column.
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

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

    fmt.Println(slicingdice.createColumn(insertData))
}
  • Insert(query interface{}) - Insert data to existing entities or create new entities, if necessary. This method corresponds to a POST request at /insert.
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

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

    fmt.Println(slicingdice.Insert(insertData))
}
  • ExistsEntity(ids, table) - Verify which entities exist in a table (uses default table if not provided) given a list of entity IDs. This method corresponds to a POST request at /query/exists/entity.
tablepackage 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)

    table := "users"
    queryData := []string {
        "user1@slicingdice.com",
        "user2@slicingdice.com",
        "user3@slicingdice.com",
        "user4@slicingdice.com",
        "user5@slicingdice.com",
    }

    fmt.Println(slicingdice.ExistsEntity(queryData, table))
}
  • CountEntityTotal(...tables) - Count the number of stored entities in given tables (or in all tables by default). This method corresponds to a POST request at /query/count/entity/total.
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)

    fmt.Println(slicingdice.CountEntityTotal())
}
  • CountEntity(query interface{}) - Count the number of entities satisfying the given query. This method corresponds to a POST request at /query/count/entity.
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

    queryData := []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{}{
                            "2017-05-21T00:00:00Z",
                            "2017-06-04T00:00:00Z",
                        },
                    },
                },
            },
        },
    }

    fmt.Println(slicingdice.CountEntity(queryData))
}
  • CountEvent(query interface{}) - Count the number of occurrences for events satisfying the given query. This method corresponds to a POST request at /query/count/event.
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

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

    fmt.Println(slicingdice.CountEvent(queryData))
}
  • TopValues(query interface{}) - Return the top values for entities satisfying the given query. This method corresponds to a POST request at /query/top_values.
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

    queryData := map[string]interface{}{
        "name-contains-eff": map[string]interface{}{
            "table": "users",
            "contains": []interface{}{
                "eff",
            },
            "name": 3,
        },
    }

    fmt.Println(slicingdice.TopValues(queryData))
}
  • Aggregation(query interface{}) - Return the aggregation of all columns in the given query. This method corresponds to a POST request at /query/aggregation.
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

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

    fmt.Println(slicingdice.Aggregation(queryData))
}
  • GetSavedQueries() - Get all saved queries. This method corresponds to a GET request at /query/saved.
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)

    fmt.Println(slicingdice.GetSavedQueries())
}
  • CreateSavedQuery(queryName string, query interface{}) - Create a saved query at SlicingDice. This method corresponds to a POST request at /query/saved.
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

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

    fmt.Println(slicingdice.CreateSavedQuery(queryData))
}
  • UpdateSavedQuery(queryName string, query interface{}) - Update an existing saved query at SlicingDice. This method corresponds to a PUT request at /query/saved/:query_name.
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

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

    fmt.Println(slicingdice.UpdateSavedQuery("my-saved-query", queryData))
}
  • GetSavedQuery(queryName string) - Executed a saved query at SlicingDice. This method corresponds to a GET request at /query/saved/:query_name.
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)

    fmt.Println(slicingdice.GetSavedQuery("my-saved-query"))
}
  • DeleteSavedQuery(queryName string) - Delete a saved query at SlicingDice. This method corresponds to a DELETE request at /query/saved/:query_name.
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)

    fmt.Println(slicingdice.DeleteSavedQuery("my-saved-query"))
}
  • Result(query interface{}) - Retrieve stored values for entities satisfying the given query. This method corresponds to a POST request at /data_extraction/result.
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

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

    fmt.Println(slicingdice.Result(queryData))
}
  • Score(query interface{}) - 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.
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

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

    fmt.Println(slicingdice.Result(Score))
}
  • Sql(statement string) - Retrieve inserted values using a SQL syntax. This method corresponds to a POST request at /query/sql.

Query statement

package main

import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)

func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_OR_READ_API_KEY"
    client := slicingdice.New(keys, 60)

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

    fmt.Println(client.Sql(query))
}

Insert statement

package main

import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)

func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_OR_READ_API_KEY"
    client := slicingdice.New(keys, 60)

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

    fmt.Println(client.Sql(query))
}

Go

Go client/SDK for SlicingDice