Wednesday, December 30, 2009

Best Buy Remix API - AJAX and JSON

Best Buy has released an API for its product catalog, store finder, and search. There are some other features offered too. The API is nice and simple. It's REST based to keep things easy to understand and offers two formats, XML or JSON. (I need to note this right away. I don't have a public page for viewing since I've slacked on getting my new domain setup.)

Step 1, get yourself an API key.
Step 2, get jQuery.

I used the AJAX option in jQuery. It's easy to setup and you can specify a return type.

Here is the ajax call I setup that grabs page 1 of the results.
Make a call to jquery, I have 1.3.2.
Setup a document.ready function and in there setup your ajax call. specify the type, url, I set the cache to true and the success: option. DataType will either be xml or json. This will match the format you choose in the URL you pass to Remix.

$(document).ready(function(){
$.ajax({
type: "GET",
url: ""http://api.remix.bestbuy.com/v1/products?page=1&apiKey=YOURKEYHERE&format=json&callback=?,
cache: true,
success: function(data) {
alert('test');
},
The simple thing for testing is just put an alert right here. If successful, the alert fires.
dataType: 'json"
)};
)};

Once you have everything working, just put jQuery's version of a "for" loop in. $.each

$.each(data.products, function(i,products) {
your formatting here. here's mine
$('
').html("SKU: " + this.sku).appendTo('#results');
});

Results is my main div that I just add stuff too for testing. You'll want some formatting here.