Search code examples
jqueryjsonpbest-buy-api

How can I query the Best Buy Remix API w/ jQuery?


Here's the code that I've been trying to work with:

$.getJSON("http://api.remix.bestbuy.com/v1/products(search=" + escape(searchCriteria) + ")?apiKey=" + hhApiKey + "&format=json&callback=?", 
function(data) {
    if(data.error) {
        alert("I'm sorry, there was an error processing your request.");
    } else {
        alert(data);
    }
});

However, the data that comes back has an error because it doesn't understand the requested URL. I looked at the net tab in Firebug and here's the URL it's trying to call out to:

http://api.remix.bestbuy.com/v1/products(search=digital%20camera)?apiKey=myapikey&format=json&callback=json1264868431&_1254866270659=

I think the problem lays in the bolded section which is being added on for no reason as far as I can tell. I think the Remix API sees it and thinks it's a botched parameter. Is there any way to stop that from being added?


Solution

  • When disabling the cache setting for jQuery ajax it will attempt to append a timestamp to the querystring. This may be the problem your experiencing. Try calling the function with caching explicitly enabled.

    $.ajax({
        type: "GET",
        url: "http://api.remix.bestbuy.com/v1/products(search=" + escape(searchCriteria) + ")?apiKey=" + hhApiKey + "&format=json&callback=?",
        cache: true,
        success: function() {
            alert('success');
        },
        dataType: 'json'
    });