JavaScript SDK

Note: As stated in the introduction, it is important that you bundle the product recommendations to ensure no duplicates.

Get Product Recommendations
Example
Response
Get Product Recommendations

Do a JavaScript based function call, to get recommendations data to work with in your frontend.

ADDWISH_PARTNER_NS.api.recom.load(boxes, options, callback(id, content, tag), error_callback(product_box_id, tag, error_code));

Argument

Description

boxes

A dictionary with recommendations box ids as keys and a `filter dictionary as values.

options

A options Object.

callback

A callback function that will be called once for every box that loaded successfully.

error_callback

An error callback function that will be called for every box that failed loading.

Example

ADDWISH_PARTNER_NS.api.recom.load(
// boxes:
{
"1234567890abcdef12345678": { // This is the recommendation box ID, which is unique to your API call. Contact Hello Retail support to get your own ID.
// Here, you can specify filter values, and other options for this specific recommendation box.
// For example, you can specify the url of another product to get recommendations for:
url: "http://www.example.com/jeans/extra-fancy-jeans-004.html",
// You can specify filter values like this:
hierarchies: [["Shoes", "Woman"]], // If needed you can specify multiple hierarchies, like for instance [["Shoes", "Woman"], ["On sale", "Woman"]]
brand: "Nike"
},
"abc4567890abcdef12345432": {} // You can leave the options empty, to use the default url (the current page)
},
// options:
{
format: "json", // You can specify either "json" or "html" as format (default is html)
tag: "this can be anything" // The tag is optional.
},
// The following function will be called once for each set of boxes requested above.
// The value of "id" will correspond to the recommendation box ID requested.
// Data will contain ether rendered html or a list of products.
function(id, data, tag) {
// Do something with data here.
// 'tag' will be "this can be anything" from above.
}
);
Response

JSON:

[
{
"title": "Product 1",
"url": "https://example.org/product-1",
"currency": "EUR",
"imageUrl": "https://example.org/images/product-1.jpg",
"oldPrice": 0,
"onSale": false,
"price": 79.0,
"productNumber": "prod-1",
// ...
},
{
"title": "Product 2",
"url": "https://example.org/product-2",
"currency": "EUR",
"imageUrl": "https://example.org/images/product-2.jpg",
"oldPrice": 150.0,
"onSale": true,
"price": 59.0,
"productNumber": "prod-2",
// ...
}
// ...
]

HTML:

<div>
<div class="product">
<a href="https://example.org/product-1">
<h1>Product 1<h1>
<img src="https://example.org/images/product-1.jpg">
<span class="price">EUR 79</span>
</a>
</div>
<div class="product">
<a href="https://example.org/product-2">
<h1>Product 2<h1>
<img src="https://example.org/images/product-2.jpg">
<span class="price">EUR 59</span>
<span class="old-price">EUR 150</span>
</a>
</div>
</div>