This is the reference for Triton API client object, methods, and types. If your business needs demand mondifications to this API, let us know!

The Triton API has 4 suites of methods:

Triton Client Object

Constructor for the main Triton Client class which stores your api-key and contains all methods.

Arguments
Name type description
api-key uuid The api-key provided by www.triton.cloud
Example Code

<html> 
  <head> 
    <script src="https://triton.cloud/cdn/triton.min.js">
    </script> 
    ... 
  </head> 
  ... 
</html>

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")

Schema

set-schema

Tell Triton what metadata properties and associated types to expect for each object being uploaded. This is an optional but recommended first step. You will almost always be uploading metadata on each item and user. If any user/item parameters reference a foreign table, set up a schema for that table too!

Arguments
Name type description
name string The name of the schema to be created
parameters dictionary A parameter-map of parameter names to their corresponding types. Exclude the primary key column, as this will be added automatically.

You must use one of the Triton.types. If a parameter is an ID-type referencing another schema, you may pass the name of that schema in as an argument i.e. triton.IDType("other-schema")
Example Code

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 

client.setSchema("users", {"name":triton.StringType()});

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")

client.set_schema("users", {"name":triton.StringType()})

set-item-schema

Suggested alias for the triton.set-schema method above when setting your items schema. If you have any metadata on the items in your catalog to upload, declare the types of each metadata parameter here.

Arguments
Name type description
parameters dictionary A parameter-map of parameter names to their corresponding types. Exclude the primary key column, as this will be added automatically.
Example Code

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 

client.setItemSchema({"location":triton.StringType()});

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")
    
client.set_item_schema({"location":triton.StringType()})

set-user-schema

Suggested alias for the triton.set-schema method above when setting your users schema. If you have any metadata on your users, declare the types of each metadata parameter here.

Arguments
Name type description
parameters dictionary A parameter-map of parameter names to their corresponding types. Exclude the primary key column, as this will be added automatically.
Example Code

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 

client.setUserSchema({"location": triton.StringType()});

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")
    
client.set_user_schema({"location": triton.StringType()})
  

Upload Catalog

upload

In order to maximize our recommendation, we want to know a bit about each item and user. Before getting started, upload all existing users and items to Triton with metadata you deem helpful for recommendations. Additionally, when new items/users/properties are added to your catalog, make sure Triton is informed.

Arguments
Name type description
schema string The name of the schema you are uploading your data to (if you are uploading items or users, see aliases below.)
id ID The ID of the object being uploaded.
metadata dictionary A parameter-map of parameter names to their corresponding values.

If you do not previously declare the parameter-types with the schema-endpoint, you must use a Triton type-wrapper for your parameter-value.
Sample Code

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 

client.upload("users", "ID-440", {"name": triton.String("Curtis Bagginz")});

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")

client.upload("users", id="ID-440", metadata={"name": triton.String("Curtis Bagginz")});

upload-item

Suggested alias for the triton.upload method above when uploading new items.

Arguments
Name type description
id ID The ID of the object being uploaded.
parameters dictionary A dictionary mapping parameter names to their corresponding values for this row of data.
JS Example

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 

client.uploadItem("ID-099", {"name": triton.String("New Shirt!")});

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")

client.upload_item(id="ID-099", metadata={"name": triton.String("New Shirt!")})

upload-user

Suggested alias for the triton.upload method above when uploading new users.

Arguments
Name type description
id ID The ID of the object being uploaded.
parameters dictionary A dictionary mapping parameter names to their corresponding values for this row of data.
Sample Code

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 

client.uploadUser("ID-440", {"name": triton.String("Curtis Bagginz")});

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")

client.upload_user(id="ID-440", metadata={"name": triton.String("Curtis Bagginz")})

Collect User Behavior

This is where we learn about how each user interacts with your application. Knowing what they click and when, what they purchase or share, and what they search for will help us generate recommendations specific for them.

item-click

Notify Triton when a user clicks on an item.

Arguments
Name type description
user ID The ID of the user.
item ID The ID of the item.
timestamp timestamp (optional) A string of format "yyyy-mm-dd hh:mm:ss"
Sample Code

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 
client.itemClick("userID-440", "itemID-099");

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")
client.item_click(user="userID-440", item="itemID-099")

item-action

Notify Triton when a user stars, likes, saves, books, or buys an item.

Arguments
Name type description
action string A word describing the action taken by the user.
user ID The ID of the user.
item ID The ID of the item.
metadata dictionary (optional) A dictionary of metadata where each value is wrapped by a triton.Type. Include a timestamp by mapping "timestamp" to a triton.Date of format "yyyy-mm-dd hh:mm:ss"

For example, if the item-action is a listing reservation, you can include the dates of reservation and number of occupants as metadata.
Sample Code

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 
client.itemAction("like", "userID-440", "itemID-099");

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")
client.item_action(action="like", user="userID-440", item="ID-099")

Notify Triton when a user makes a search.

Arguments
Name type description
user ID The ID of the user making the search
parameters dictionary A map of search parameters to their values.

Each parameter value must be wrapped with a Triton type-wrapper.
timestamp timestamp (optional) A string of format "yyyy-mm-dd hh:mm:ss"
Sample Code

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 
client.userSearch("ID-440", {"date":"2018-01-01", "location": "Laramie, WY"});

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")
client.user_search(user="ID-440", parameters={"date":"2018-01-01", "location": "Laramie, WY"})

Recommender

recommend

Get personalized recommendations for the user to show them what we know they'll love.

Arguments
Name type description
user ID The ID of the user.
num integer The number of recommendations Triton should return
Sample Code

                      triton.recommend("userID-440", 10 );
                    

                        triton.recommend( user="userID-440", num=10 )
                  

similar

While a user views a certain item, generate a list of similar items for the user to check out next.

Arguments
Name type description
user ID The ID of the user.
item ID The ID of the item.
num integer number of recommendations Triton should return
Sample Code

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 

client.similar("userID-440", "itemID-099", 10)

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")

client.similar(user="userID-440", item="itemID-099", num=10)

tailored-similar

When recommending similar content to a viewed item, customize that list of recommendations for each user.

Arguments
Name type description
user ID The ID of the user.
item ID The ID of the item.
num integer number of recommendations Triton should return
Code Sample

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 

client.tailoredSimilar("userID-440", "itemID-099", 10);

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")
    
client.tailored_similar(user="userID-440", item="itemID-099", num=10)

Datatypes

You must use Triton.type's in 1 of 2 circumstances:

  1. In triton.set-schema, informing the Triton.type of each parameter.
  2. In triton.upload, to type-cast each data cell being uploaded in a row.
If you declare the types using the set-schema method, there is no need to type-cast each element while uploading. If you do not set the schema, you must type-cast each element while uploading.

Schema Types

For use in set-schema.

Options
type description examples
StringType() A triton.StringType is a short string that will be wrapped as an EnumType behind the scenes. name, title, month, size, or genre.
TextType() Text type is a much longer string that likely own't be repeated again. Message, description, or document.
NumberType() Any float, integer, or other scalar number. 0, 1, 4.45, or 499999.79797979
DateType() A date string of the format "yyyy-mm-dd hh:mm:ss" "2018-01-04 17-23-02" or "2018-01-04"
EnumType() An element in an enumerated set of constants month, color, or city/state/country
IDType(<string> foreign-schema) An ID field. The foreign-schema (optional) argument is only needed if the ID references another schema; in which case, clarify the foreign-schema name as a string i.e. triton.IDType("schema-name") "ID-440", "fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f", or "12004"
ArrayType(<triton.Type> type) type is the triton.Type of each parameter in the array. If your item has a list of sizes or options.
Code Sample

var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 

client.setSchema("States", {"name":triton.StringType(), "region": triton.StringType()} );
client.setSchema("Cities", {"name":triton.StringType(), "zip":triton.EnumType(), "state":triton.IDType("States")} );

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")
    
client.set_schema("States", {"name":triton.StringType(), "region": triton.StringType()} )
client.set_schema("Cities", {"name":triton.StringType(), "zip":triton.EnumType(), "state":triton.IDType("States")} )

Type-cast Methods for Uploading

For use in triton.upload.

Options
type description examples
String(<string> arg) A triton.String is a short string that will be wrapped as an enum. name, title, month, size, or genre.
Text(<string> arg) Arg is a long string of inputted text, like a description or an article. Message, description, or document.
Number(<number> arg) The arg can be a number represented as an int, float, or string. 0, 1, 4.45, or 499999.79797979
Date(<date-string> arg) arg is a date-string of the format "yyyy-mm-dd hh:mm:ss" "2018-01-04 17-23-02" or "2018-01-04"
Enum(<string/int> arg) arg can be a string or int representating an enum, such as month, color, city/state/country month, color, or city/state/country
ID(<string> arg, <string> foreign-schema) The arg is the ID value as a string, int, or uuid. If this ID references another schema, specify that schema name as a string with foreign-schema (optional). "ID-440", "fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f", or "12004"
Array(<triton.Type> type, <list> arg) The type is the triton.Type of each element in the array. arg is the list to be uploaded. If your item has a list of sizes or options.
Sample Code
var client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f"); 

client.upload("States", "NJ", {"name":triton.String("New Jersey"), "region": triton.String("NE")} );
client.upload("Cities", "ID-559", {"name"=triton.String("Scotch Plains"), zip:triton.Enum(07076), state: triton.ID("NJ", "States") );

import triton
client = triton.Client("fa2a8d96-4ba9-4dbc-9bce-41a7e4ad782f")

client.upload("States", "NJ", {"name":triton.String("New Jersey"), "region": triton.String("NE")} )
client.upload("Cities", "ID-559", {"name"=triton.String("Scotch Plains"), zip:triton.Enum(07076), state: triton.ID("NJ", "States") )