How To Get a Book’s Info From Its ISBN

I recommend you know  How To Parse XML for this tutorial. The second thing we are going to need is an API key from the free ISBN database.

Now that you have the access key let’s set up the url we’ll call to give us the book info.

The base url is

For the purposes of this tutorial we are going to have to pass three paramaters, “access_key” (api key), “results” and “index1”.


Replace “API_Key” with the api key you got.


The value “details” just means that we want the book’s detailed information. There are different types of results such as “prices” that will give you any books prize on different stores.


Tells the ISBN database that we will be searching by ISBN. Replacing the value “isbn” with “title” will search by title but replacing it with “author” or “publisher” will not work, I will show you how to search by those and more on another post, and also how to use different result sets.


The search query, in this case “xxxxxxxxxx”, is an ISBN number of your choice, it can be either an ISBN10 or 13 and it can include dashes.

Now that we know the structure of this API’s URL let’s see how it looks when put together. Remember to replace the value of access key with your API key and use the same ISBN I use just so we can be on the same page.

We don’t need a script to see the response we’ll get from this url, simply put it in your browser’s address bar. If you are using Chrome I recommend you use FireFox or even IE8 *gasp* for this part of the tutorial.

Response in FireFox 3.5 for ISBN 0596007736

Response in FireFox 3.5 for ISBN 0596007736

Now it’s just a matter of parsing the response using the function “simplexml_load_file”, but before we do that let’s talk about a few things you have to know from the response.

The first thing you should notice is the “total_results” attribute for the BookList tag, as you might guess if the value of this attribute is zero it means that no book was found. The second thing is the two title tags <Title> and <TitleLong>. It’s important to know that the response you get might have one, the other, or sometimes both types of titles. I prefer to use TitleLong when it’s avaible because from what I’ve seen it’s more descriptive, and can include other media that comes with the book such as CD’s and/or DVD’s , but nothing keeps you from using both tags however you wish.

Let’s build a simple script that will call the API and shows you the results after they have been formated. Am going to create three files “find-book.html”, “find-book.js” and “find-book.php” , the file you should pay attention to the most is “find-book.php” , if you don’t know what’s going on in “find-book.js”  I invite you to read my tutorial PHP AJAX Contact Form , find-book.js (javascript) will be used to pass the paramater “isbn” to the php file and get the response using AJAX so this file (find-book.js) is not necessary but it makes things look nicer.

find-book.html contents.

We just need a text field, a button and a division where we will see the book’s information response from find-book.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<label>Type an ISBN and click the button to get the information</label><br/>
<input type="text" id="isbn" /><br/>
<button id="getBook">Get Info</button>
<div id="bookInfo">

<!-- Include Jquery-->
<script src="" type="text/javascript"></script>
<!-- Include find-book.js -->
<script type="text/javascript" src="find-book.js"></script>

find-book.js contents

var isbn;
  $("#getBook").click(function(){ // when you click the button
    // fade out bookinfo div
	// assign isbn value to var isbn
	// send isbn value as POST variable "isbn" and load result in bookinfo div
	    // fade in bookinfo div

find-book.php contents

We need to get the variable from find-book.html we sent with find-book.js and assign it to $isbn.

// get isbn
// create url
// load url into $response

// check if we got at least one result
 // we got at least one result

// assign each book to $book
 foreach($response->BookList->BookData as $book)
   echo "Short Title: {$book->Title}<br/>
   Long Title: {$book->TitleLong}<br/>
   Author(s): {$book->AuthorsText}<br />
   Publisher: {$book->PublisherText}<br/>
   ISBN10: {$book['isbn']}<br/>
   ISBN13: {$book['isbn13']}<br/>
   Edition Information: {$book->Details['edition_info']}<br/>
   Language: {$book->Details['language']}<br/>
   Physical Description: {$book->Details['physical_description_text']}
echo 'No book was found with ISBN: '.$isbn;


That’s all I’ve got for this tutorial, check out the working example and leave a comment below.