Search code examples
apiisbn

How do you get category info of a book from ISBNdb.com?


I am able to easily get book info:

http://isbndb.com/api/books.xml?access_key=THEKEY&results=details&index1=isbn&value1=9781849152990

And I can easily look up categories:

http://isbndb.com/api/categories.xml?access_key=Z&index1=category_id&value1=science.mathematics.geometry 

But how do you get a certain book's category? I want to provide the ISBN code, and in return I want to get the category?


Solution

  • Looking at their API docs and playing around with it a bit, it appears that the best you can do is get a list of the book's subjects, and then get the categories for those.

    So, to take their example, given an ISBN of 0061031321, you first call

    http://isbndb.com/api/books.xml?access_key=$Z&results=subjects&index1=isbn&value1=0061031321

    which returns

    <BookData book_id="thief_of_time" isbn="0061031321" isbn13="9780061031328">
    <Title>Thief of time</Title>
    <TitleLong>Thief of time: a novel of Discworld</TitleLong>
    <AuthorsText>Terry Pratchett</AuthorsText>
    <PublisherText publisher_id="harpertorch">New York, N.Y. : HarperTorch, [2002], c2001.</PublisherText>
    <Subjects>
    <Subject subject_id="discworld_imaginary_place_fiction">Discworld (Imaginary place) -- Fiction</Subject>
    <Subject subject_id="fantasy_fiction_aaaa0">Fantasy fiction</Subject>
    </Subjects>
    </BookData>
    

    and then you iterate through the subjects, getting their categories:

    http://isbndb.com/api/subjects.xml?access_key=$Z&results=categories&index1=subject_id&value1=discworld_imaginary_place_fiction

    <...snip...>
    <Categories>
    <Category category_id="imaginary_places">Imaginary Places</Category>
    <Category category_id="imaginary_places.discworld">Discworld</Category>
    </Categories>
    <...snip...>
    

    http://isbndb.com/api/subjects.xml?access_key=$Z&results=categories&index1=subject_id&value1=fantasy_fiction_aaaa0

    <...snip...>
    <Categories>
    <Category category_id="genres.fantasy">Fantasy</Category>
    </Categories>
    <...snip...>
    

    So the categories for ISBN 0061031321 are:

    • Imaginary Places
    • Discworld
    • Fantasy

    and those can be traced up via the categories.xml api if you want to get the entire category hierarchy.