Recoms using Javascript SDK

Usage

To load any recommendations from Hello Retail you need to use the loadRecom method.

hrq = window.hrq || [];
hrq.push([
    "loadRecom",
    requests,
    callback
]);

The different arguments shown above are described below.

Argument Description
requests A list of RecomRequest for product recommendations. Each request will be processed, and the response will contain a list of responses in the same order as the given requests. Products will not be repeated within the responses to one API call
callback(result) A callback function that is called with the result of the request

The loadRecom method uses the recom REST API un under the hood. Each RecomRequest in the list must follow the structure that is documented in the documentation for the REST API. The method can be used to load both managed and unmanaged recoms

Examples

hrq = window.hrq || [];
hrq.push([
    "loadRecom",
    // requests:
    [
        {
            // Managed recom
            "key": "k6449296dbbc4cd233cac2276",
            "format":"html",
            "context": {
                "hierarchies":[["Clothing","Women"]],
                "brand": "Nike",
                "urls": ["https://mywebshop.com/"]
            }
        },
        // Unmanaged recom
        {
            "trackingKey":"frontpage-1",
            "fields":["title","url"],
            "hideAdditionalVariants":true,
            "count":8,
            "context":{
                "urls": ["https://mywebshop.com/"]
            },
            "sources":[
                {
                    "type":"RETARGETED",
                    "limit": 2
                },
                {
                    "type":"TOP",
                    "filters":{
                        "hierarchies":{"$in":[["Clothing", "Woman"]]}
                    }
                }
            ]
        }
    ]
    // Callback
    function(result) {
        // Do something with data here.
        if (!result.success) {
            console.error(result.message);
            return;
        } 
        for(let i = 0; i<result.results.length; i++) {
            console.log(result.results[i]);
        }
    }
]);

The returned result also follows the structure that is documented in the documentation for the REST API.