JavaScript SDK

Setup

To use the HelloRetail JavaScript SDK you need to add the awAddGift.js script has to be present and initialized. When the script has been initialized the SDK will be attached to window and accessible through the variable name ADDWISH_PARTNER_NS like the following: window.ADDWISH_PARTNER_NS. For the rest of this guide, we will only use ADDWISH_PARTNER_NS to mean the SDK.

Usage

To load any recommendations from Hello Retail you need to use the load function on the recom object, which is found inside the api object. This makes any call look like this ADDWISH_PARTNER_NS.api.recom.load.
1
ADDWISH_PARTNER_NS.api.recom.load(boxes, options, callback, error_callback);
The different arguments shown above are described below.
It is important to note that the API by default respond with HTML, which you can use directly on your site to show the Hello Retail recom boxes. If you wish to control the experience even further you can specify in the options object you wish to have JSON returned instead.
It is important that you bundle the product recommendations to ensure no duplicates
Argument
Description
Example
boxes
A dictionary with recommendations box IDs as keys and an object where you can add filters. The object can be empty, but needs to be added, see the example to the right.
{
<box_id1>: {},
<box_id2>:
{
brand: <somebrand>"
}
}
options
An options Object. It is only possible to specify a format which is either HTML or JSON, if nothing is specified HTML is returned.
Additionally, you can specify a tag which you can optionally use to keep track of your requests.
{
format: "json",
tag: "some tag"
}`
callback(id, data, tag)
A callback function that will be called once for every box that loaded successfully. It returns the id of the box, the data (either JSON or HTML) and the tag if you specified one.
function (id, data, tag){
console.log(id, data, tag);
}
error_callback(id, tag, error)
An error callback function that will be called for every box that failed to load. It returns the id of the box, the tag you optionally specified and the error message.
function (id, tag, error){
console.log(key, tag,
error);
}

Examples

General example
Example for Upsell recommendation boxes
1
ADDWISH_PARTNER_NS.api.recom.load(
2
// boxes:
3
{
4
"1234567890abcdef12345678": { // This is the recommendation box ID, which is unique to your API call. Contact Hello Retail support to get your own ID.
5
// Here, you can specify filter values, and other options for this specific recommendation box.
6
// For example, you can specify the url of another product to get recommendations for:
7
url: "http://www.example.com/jeans/extra-fancy-jeans-004.html",
8
9
// You can specify filter values like this:
10
hierarchies: [["Shoes", "Woman"]], // If needed you can specify multiple hierarchies, like for instance [["Shoes", "Woman"], ["On sale", "Woman"]]
11
brand: "Nike"
12
13
},
14
"abc4567890abcdef12345432": {} // You can leave the options empty, to use the default url (the current page)
15
},
16
17
// options:
18
{
19
format: "json", // You can specify either "json" or "html" as format
20
(default is html)
21
tag: "this can be anything" // The tag is optional.
22
},
23
24
// The following function will be called once for each set of boxes requested above.
25
// The value of "id" will correspond to the recommendation box ID requested.
26
// Data will contain ether rendered html or a list of products.
27
function(id, data, tag) {
28
// Do something with data here.
29
// 'tag' will be the value specified on line 20 - "this can be anything"
30
},
31
32
// The following function will be called if there is an error.
33
// If the error is at the "box level" the id will be the id of the box
34
// If it is a general error, the id will be undefined
35
function(id, tag, error){
36
//Do something with the error here
37
// 'tag' will be the value specified on line 20 - "this can be anything"
38
}
39
);
For Upsell recommendation boxes, we will need the information from the cart. In the example below, you will need to send a list of URLs for the urls parameter (note the plural version compared to the example above). If you would like to state to the customer how much they need to buy to get free shipping, you should also pass the price as an argument.
1
ADDWISH_PARTNER_NS.api.recom.load(
2
// boxes:
3
{
4
"1234567890abcdef12345678": { // This is the recommendation box ID, which is unique to your API call. Contact Hello Retail support to get your own ID.
5
// Here, you can specify filter values, and other options for this specific recommendation box.
6
// For example, you can specify the url of another product to get recommendations for:
7
urls: ["http://www.example.com/jeans/extra-fancy-jeans-004.html", "http://www.example.com/dress/pretty-dress-001.html"],
8
price: 13213.33,
9
// You can specify filter values like this:
10
hierarchies: [["Shoes", "Woman"]], // If needed you can specify multiple hierarchies, like for instance [["Shoes", "Woman"], ["On sale", "Woman"]]
11
brand: "Nike"
12
13
},
14
"abc4567890abcdef12345432": {} // You can leave the options empty, to use the default url (the current page)
15
},
16
17
// options:
18
{
19
format: "json", // You can specify either "json" or "html" as format (default is html)
20
tag: "this can be anything" // The tag is optional.
21
},
22
23
// The following function will be called once for each set of boxes requested above.
24
// The value of "id" will correspond to the recommendation box ID requested.
25
// Data will contain ether rendered html or a list of products.
26
function(id, data, tag) {
27
// Do something with data here.
28
// 'tag' will be "this can be anything" from above.
29
},
30
31
// The following function will be called if there is an error.
32
// If the error is at the "box level" the id will be the id of the box
33
// If it is a general error, the id will be undefined
34
function(id, tag, error){
35
//Do something with the error here
36
// 'tag' will be the value specified on line 20 - "this can be anything"
37
}
38
);

Example "data" values in callback

We send a data object which either contains HTML (default) or JSON if you specified this in the options object. The data object looks like following depending on what you specified.
HTML
JSON
1
<div>
2
<div class="product">
3
<a href="https://example.org/product-1">
4
<h1>Product 1<h1>
5
<img src="https://example.org/images/product-1.jpg">
6
<span class="price">EUR 79</span>
7
</a>
8
</div>
9
<div class="product">
10
<a href="https://example.org/product-2">
11
<h1>Product 2<h1>
12
<img src="https://example.org/images/product-2.jpg">
13
<span class="price">EUR 59</span>
14
<span class="old-price">EUR 150</span>
15
</a>
16
</div>
17
</div>
1
[
2
{
3
"title": "Product 1",
4
"url": "https://example.org/product-1",
5
"currency": "EUR",
6
"imageUrl": "https://example.org/images/product-1.jpg",
7
"oldPrice": 0,
8
"onSale": false,
9
"price": 79.0,
10
"productNumber": "prod-1",
11
// ...
12
},
13
{
14
"title": "Product 2",
15
"url": "https://example.org/product-2",
16
"currency": "EUR",
17
"imageUrl": "https://example.org/images/product-2.jpg",
18
"oldPrice": 150.0,
19
"onSale": true,
20
"price": 59.0,
21
"productNumber": "prod-2",
22
// ...
23
}
24
// ...
25
]