APIs and books: Amazon, Google Books, ISBN and their open APIs

APIs & books: Amazon, Google Books, ISBN and their open APIs

Books also have a place in the world of APIs. In this article we analyze the details and features of Amazon, Google Books and ISBN's open APIs, and take a look at book identifiers. The ISBN, including their control digits, can be a headache, so the best idea is always to verify the validity of your code before calling any API.

BBVAOpen4U
|
24 Sep. 2018

If we're developing apps that deal with information on books, we're going to have to take a tour of several fairly powerful and relatively open APIs. Although this is not very complicated terrain, some aspects, such as identifiers, are not as simple as they might appear.

Some years ago the standard book identifier was created so that publishers could automatically classify the books they issued. The ISBN (International Standard Book Number) began as a 10-digit code, and was extended to 13 digits in 2007. Both formats –10 and 13 digits– coexist, and have internal verifications to validate their structure.

The ISBN, including their control digits, can be a headache, so the best idea is always to verify the validity of your code before calling any API. A simple verification could be this:

function codigo_ISBN_valido (isbn) {

  isbn = isbn.replace(/[^\dX]/gi, '');

  if(isbn.length != 10){

    return false;

  }

  var caracteres = isbn.split('');

  if(caracteres[9].toUpperCase() == 'X'){

    caracteres[9] = 10;

  }

  var suma = 0;

  for (var i = 0; i < caracteres.length; i++) {

    suma += ((10-i) * parseInt(caracteres[i]));

  };

  return ((suma % 11) == 0);

}

In addition to the ISBN, there is also the EAN (European Article Number) with which some publishers and commercial groups label their books. Then there is ASIN (Amazon Standard Identification Number) which the eCommerce giant uses as a unique identifier for every product in its catalog. Amazon also uses ISBN as ASIN, adding to the confusion of some novice developers.

Once we've learned the different standard identifications for books in the various APIs, we can begin to play with them. There are a wide range of free and corporate APIs with varying degrees of flexibility that will certainly allow us to find an application or book management for almost any need in our app.

ISBNdb: comparing prices

One of the oldest platforms, founded in 2002, has almost 8 million titles in its database. In addition to searching by identifier, its API offers the possibility of browsing by categories and obtaining the price of each title with different retailers.

If we look at this last aspect in more detail, according to the documentation we can make a request as follows:

http://isbndb.com/api/v2/json/$CLAVE_API/prices/$IDENTIFICADOR

This will return a historic list of prices and retailers where we can find this product, and is useful for tracking changes in price or comparing between suppliers. The result would be a response in JSON:

{

   "result_count" : "2",

   "page_count" : 1,

   "current_page" : 1,

   "index_searched" : "isbn",

   "min_time_unix" : 0,

   "max_time_unix" : 1368820663,

   "data" : [

      {

         "store_title" : "Principles of solid mechanics",

         "store_id" : "amazon",

         "currency_code" : "USD",

         "is_historic" : "1",

         "price_time_unix" : "1367763531",

         "is_new" : "0",

         "in_stock" : "0",

         "price" : "65.66"

      },

   ],

}

Google Books: see content

The Google Books API is incredibly powerful and requires us to authenticate ourselves through a OAuth 2 protocol, not very complex, if we've worked with this secure method before.

It has three different parts. The first part allows users to search for chains of text among the millions of books Google has scanned and indexed. With the second part, these books can be embedded in web apps. Finally, the last part of the API offers a way of managing our own digital library with our own titles.

The text search is certainly the most powerful and interesting part. Once authenticated it can be accessed as follows:

https://www.googleapis.com/books/v1/volumes?q=SEARCH PHRASE

If successful, it will return the traditional headers HTTP 200/OK with a list of titles containing the phrase:

{

 "kind": "books#volumes",

 "items": [

  {

   "kind": "books#volume",

   "id": "_ojXHRcCNuzg",

   "etag": "OTDqn42tB19",

   "selfLink": "https://www.googleapis.com/books/v1/volumes/_ojXNuzgHRcC",

   "volumeInfo": {

"title": "Libro de ejemplo",

"authors": [

 "BBVAOpen4U"

],

   ...

  },

  "totalItems": 3

}

It has programming libraries ready to use the API in almost any modern programming language.

Amazon Books

The vast catalog of Amazon APIs includes several related with the traditional book search that served as the basis for the service in its early years.

The eCommerce giant offers two related APIs in this category: ItemSearch and ItemLookUp. Both need an Amazon Web Services user account.

The first allows us to search and find books using multiple variables: title, author, publication date, ASIN/ISBN, publisher, etc.

http://webservices.amazon.com/onca/xml?service=AWSECommerceService&AWSAc...$AWS_KEY&

AssociateTag=$TAG_DE_AMAZON&Operation=ItemSearch&Keywords=$TERMINO_A_BUSCAR&SearchIndex=Books&Timestamp=[YYYY-MM-DDThh:mm:ssZ]&Signature=[Request Signature]

It will return an XML with the usual attributes of each book, in addition to a brief description:

<TotalResults>2849</TotalResults>

<TotalPages>285</TotalPages>

<MoreSearchResultsUrl>(...)</MoreSearchResultsUrl>

<Item>

    <ASIN>B08OE6I000</ASIN>

        (...)

    <ItemAttributes>

        <Author>BBVAOpen4U</Author>

        <Manufacturer>BBVA</Manufacturer>

        <ProductGroup>Book</ProductGroup>

        <Title>Título del libro</Title>

    </ItemAttributes>

</Item>

Once we've obtained these results, we can go to ItemLookup to see more data on the title or volumes selected. For example, the fictitious identifier B08OE6I000 would return the following result:

<Items>

  <Request>

  <IsValid>True</IsValid>

  <ItemLookupRequest>

    <ItemId>B08OE6I000</ItemId>

  </ItemLookupRequest>

  </Request>

  <Item>

    <ASIN>B08OE6I000</ASIN>

    <ItemAttributes>

    <Manufacturer>BBVAOpen4U</Manufacturer>

    <ProductGroup>Book</ProductGroup>

    <Title>Título del libro</Title>

   </ItemAttributes>

  </Item>

</Items> 

With this second Amazon API we can obtain and verify extra details on each book or catalog item when we need to refresh the data. But it will generally be sufficient with the ItemSearch API.

Are you interested in financial APIs? Discover all the APIs we can offer you at BBVA

Sign up!

Sign up to the BBVAOPEN4U newsletter and receive tips, tools and the most innovative events directly in your inbox.