Javascript Client Specification v1.1
If you were looking for the legacy 1.0 documentation, you will find it here.

Javascript Client Specification

Once the Gravity javascript is loaded, you will have access to a sannsyn object through the browser's javascript. This object handles some automation, and is available for your own javascripts, so you get a programming-like interface to the Gravity recommender system. If the vocabulary in these schemas is unknown, please refer to the --verbose section of the documentation.

The Sannsyn Object

The sannsyn object is always accessible once the javascript is loaded. These are its functions:
Function
Return type
sannsyn.reportProductBrowsing(Item ID: String)
void
sannsyn.reportProductsToWishlist(Item IDs: vararg String)
void
sannsyn.setCustomer(customer ID: String)
void
sannsyn.sha1Hash(input: String)
sannsyn.version()
void

And these are the available constructors:
Constructor
Return type
new sannsyn.OrderLineItemBuilder(Item ID: String)
OrderLineItemBuilder
new sannsyn.PurchaseReportBuilder(products: vararg OrderLineItem)
Purchase Report Builder
new sannsyn.RecReqBuilder(recommender: String)
Recommendation Request Builder

The OrderLineItem Builder

Use this builder object to obtain OrderLineItem objects for your purchase reports.
Function
Return type
setNum(num: int)
this
setUnitPrice(price: int)
this
setOrderLineId(id: string)
this
build()
OrderLineItem object

The OrderLineItem

OrderLineItem objects are used when building purchase report updates. Once built, they aren't interacted with, but simply used as input to a PurchaseReport objects.

The PurchaseReport Builder

This builder produces PurchaseReport objects.
Function
Return type
setInvoiceId(id: string)
this
addItem(item: OrderLineItem)
this
setCallback(f: function)
this
build()
void

The PurchaseReport Object

Th PurchaseReport object serves to send a detailed purchase report update to the Gravity system.
Function
Return type
send()
void

The RecommendationRequest Builder

Use this builder to easily construct Gravity recommendation requests.
Function
Return type
setNum(num: int)
this
setInput(input: string array)
this
setTimeout(milliseconds: int)
this
setCallback(f: function)
this

The RecommendationRequest Object

Once you have a RecommendationRequest object, you can get recommendations directly using execSync() or to your callback function using exec().
Function
Return type
exec()
void
execSync()
(json) object