Welcome to the Kelkoo Group Customer Service

Signing URL – Node.js

Please, be careful, this javascript code is designed to run on server side for security reasons. Otherwise, you would have to expose your confidential access key. So don’t use it on client side !

In order to access the service, you’ll need first to “sign” your URLs. In Node.js, you need to load a md5 library first (example). Here is an example of code :

Variables

Name Type Summary
urlDomain string (required) URL of the service (ex: http://uk.shoppingapis.kelkoo.com)
urlPath string (required) Path and query for the service (ex: /V3/productSearch?query=ipod)
id string (required) Affiliate Id
key string (required) Affiliate secret key

Sample Class

 
    var pack = function (str) {
        var result = ''
        var quantifier = str.length;

        for (i = 0; i < quantifier; i += 2) { word = str[i]; if (((i + 1) >= quantifier) || typeof str[i + 1] === 'undefined') {
                word += '0';
            } else {
                word += str[i + 1];
            }

            result += String.fromCharCode(parseInt(word, 16));
        }

        return result;
    };

    var signUrl = function (urlDomain, urlPath, id, key) {
        var time = Math.round(new Date().getTime() / 1000);
        var firstParam = (urlPath.indexOf("?") >= 0) ? "&" : "?";

        var urlTmp = urlPath.replace(" ", "+") +
            firstParam +
	    "aid=" + id +
            "&timestamp=" + time;

        var s = urlTmp + key;
        var t = btoa(this.pack(md5(s)));
        var tokken = t.replace(/\+/g, ".").replace(/\//g,"_").replace(/=/g,"-");

        return urlDomain + urlTmp + "&hash=" + tokken;
    };

Simply call the function to generate the appropriate URL:

 signUrl('http://uk.shoppingapis.kelkoo.com', '/V3/productSearch?query=ipod&sort=default_ranking&start=1&results=20&show_products=1&show_subcategories=1&show_refinements=1','myId', 'myKey');