isbnlab / isbnlab-php
Official PHP client for the ISBNLab book metadata API: look up books by ISBN, authors, publishers, subjects, BISAC genres, covers and editions, and validate and convert ISBNs.
Requires
- php: ^8.1
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^7.3
- guzzlehttp/psr7: ^2.0
Requires (Dev)
- phpunit/phpunit: ^10.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The official PHP client for the ISBNLab book metadata API. Look up a book by ISBN and get its title, authors, publishers, series, BISAC genres, formats, page count, description and every other edition, from a catalog of more than 100 million editions. It also validates and converts ISBN-10, ISBN-13, EAN and Amazon ASIN.
Install
composer require isbnlab/isbnlab-php
PHP 8.1 or later, with the curl, json and mbstring extensions.
Get an API token
Create a free ISBNLab account and copy your API token from your profile. The Free plan includes 1,000 calls a day; see pricing for more.
Quick start
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use ISBNLab\Api\BooksApi; use ISBNLab\Configuration; $config = Configuration::getDefaultConfiguration() ->setAccessToken(getenv('ISBNLAB_API_TOKEN')); $books = new BooksApi(new Client(), $config); $book = $books->getBookByIsbn('9780765302304'); echo $book->getTitle(), "\n"; // The Gathering Storm echo $book->getAuthors()[0]->getName(), "\n"; // Robert Jordan echo $book->getPublishDate()?->format('Y'), "\n"; foreach ($book->getOtherEditions() ?? [] as $edition) { echo $edition->getIsbn13(), ' ', $edition->getTitle(), "\n"; }
Many fields are empty for some books, so every getter can return null.
Linked records carry ids you can look up directly (author, publisher, subject and genre lookups need a Standard or Pro plan):
use ISBNLab\Api\AuthorsApi; $authorId = $book->getAuthors()[0]->getId(); $author = (new AuthorsApi(new Client(), $config))->getAuthor((string) $authorId); echo $author->getBio(), "\n";
Errors
Any response other than 2xx throws ISBNLab\ApiException. Its code is the HTTP status:
use ISBNLab\ApiException; try { $book = $books->getBookByIsbn('9780000000000'); } catch (ApiException $e) { match ($e->getCode()) { 404 => print("Not in the catalog\n"), 429 => print("Daily limit reached\n"), 403 => print("Your plan does not include this endpoint\n"), default => throw $e, }; }
What you can call
| Class | Method | Plan |
|---|---|---|
BooksApi |
getBookByIsbn($isbn), getBookByAsin($asin), getBookById($id) |
Free |
IsbnApi |
parseIsbn, isbn10ToIsbn13, isbn13ToIsbn10, isbnToEan, eanToIsbn, isbnToAsin, asinToIsbn |
Free |
BooksApi |
getBookCoverByIsbn($isbn), getBookCoverByAsin($asin) |
Standard |
AuthorsApi |
getAuthor($id), findAuthor($name) |
Standard |
PublishersApi |
getPublisher($id), findPublisher($name), getPublishersByPrefix($prefix) |
Standard |
SubjectsApi |
getSubject($id), findSubject($name) |
Standard |
GenresApi |
getGenre($id), findGenre($nameOrBisacCode) |
Standard |
BooksApi |
searchBooks($query, $limit, $page, $maxResults) |
Pro |
BooksApi |
getEditionsByIsbn($isbn), getEditionsByAsin($asin) |
Pro |
Every method also has an ...Async() version that returns a Guzzle promise, and a ...WithHttpInfo() version that also returns the status code and headers (for example the rate-limit headers).
Reference for every method and model: docs/. Field-by-field documentation: API documentation.
Development
lib/ and docs/ are generated from the API's OpenAPI document with OpenAPI Generator, so changes to them are made in the generator and arrive with the next release; please open an issue rather than a pull request for those folders. README.md, composer.json and tests/ are maintained by hand.
composer install vendor/bin/phpunit
License
MIT. Maintained by ISBNLab, the book metadata API.