The New York Times has started offering a set of APIs for their various data services. On January 27th they released the API for their Best-Seller list. According to NYTimes :
Like many organizations, we hope to encourage innovation through collaboration. When you build applications, create mashups and otherwise reveal the potential of our data, we learn more about what our readers want and gain insight into how news and information can be reimagined. We’re hoping you’ll show us what’s next for The Times.
Currently the list offers every weekly list since June 2008 which will eventually go back to the 1930s. According to their blog, the API offers details about specific best sellers, including historical rank information and links to New York Times reviews and excerpts. I created a short class to access the api using CURL. To access the api you need to sign up for an API key here. The api returns data in xml, json or sphp (serialized php).
A sample code using the class is shown below:
$books = new nyTimesBooks("your api key here"); $books = $books->format("xml") // Set return format to xml ->listDate("2008-10-01") // publication date (YYYY-MM-DD) ->listType("Series-Books"); // List type echo $books->get_bestsellers();
The list type can be any of the following:
Or you can get the list as follows:
$books = new nyTimesBooks("your api key here"); echo $books->get_list_names();
You can also use the class without any options which will return the current list in xml format with the list type of ‘Mass-Market-Paperback’.
$books = new nyTimesBooks("your api key here"); echo $books->get_bestsellers();
A sample xml output is shown below:
OK Copyright (c) 2009 The New York Times Company. All Rights Reserved. 20 1 Paperback Nonfiction 2008-09-21 2008-10-05 86 0 0 0 THREE CUPS OF TEA A former climber builds schools in villages in Pakistan and Afghanistan. by Greg Mortenson and David Oliver Relin Greg Mortenson and David Oliver Relin 15 Penguin 9780143038252 0143038257 9780670034826 0670034827 9781597226240 159 . . .
The code still needs to implement the following requests:
1. search best-seller lists
2. history of a best seller