Auto Fill HTML Form With Data Using ISBNdb API

Martin Cotterill
Martin Cotterill used Ask the Experts™
We have a small library of slightly less than 1,000 books at this time but new books are added occasionaly. At the moment, all the details are held on an OpenOffice database but the data is a mess so we've refined the data and created a MySQL database and an online HTML form to enter relevant details. To make sure the data is always entered the same way, we want to use the API from to fill in the form.

The record fields are for ISBN, Book Title, Author(s), Publisher and Date of Publication.

We have search buttons for the ISBN and Book Title inputs to use either to retrieve the data from ISBNdb.

How do we attach the API to the search buttons that will retireve the relevant data and put it in the correct input fields of the form but still be able to hand fill if necessary?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018

There are a few moving parts to this, but the basic idea is that your Search button would submit your terms to your PHP server-side script. That script would then make a CURL request to one of the API endpoints using your search terms and your API Key (you'll need to register to get that). The CURL request would then return the results in JSON format.

You would then parse the results to extract the information you needed, and insert them into your database.

From their API docs, a CURL request for an ISBN looks like this:

$url = '';  
$restKey = 'YOUR_API_KEY';  
$headers = array(
    "Content-Type: application/json",  
    "X-API-Key: " . $restKey  
$rest = curl_init();  
curl_setopt($rest, CURLOPT_URL, $url);  
curl_setopt($rest, CURLOPT_HTTPHEADER, $headers);  
curl_setopt($rest, CURLOPT_RETURNTRANSFER, true);  

$response = curl_exec($rest);
$info = json_decode($response);

Open in new window

$Info would then be an array containing the book info for that given ISBN, and you can use that data to insert into your DB:

$info['authors'] -- this is likely to be an array that would need to be looped through.

Here's the link to their API docs:

You can use mysqli or PDO to insert your records into your DB.

Come back if you have further question


Hi there

Thanks for the reply.

I saw this in the documation but couldn't understand how it would work in our situation. Is the code above php?

To get it to work the way we have at the moment, would we split the current HTML form in to two separate forms? The first part would have the search for, say, the ISBN number and the second part would have the <input value="isbn"...> and so on?

We know how to 'manually' add records to the database using an HTML form but not how to populate it using the data from the API. How would we do that?
Most Valuable Expert 2018
Distinguished Expert 2018

Hey Martin,

Depending on your needs, there are several ways to do this. For example, you could have a single Search form with one text field, and maybe a couple of radio buttons to choose whether the search query is for ISBN or Book Title. The submit button could then send that info to your server-side script (yes - it's in PHP) which would do the request to the API and insert the data directly into the database.

Alternatively, if you want to give the users a little more control, you could do it in couple of steps. Have the Seearch form I've just mentioned that makes the same request to the API, but instead of automatically inserting into the database, it would return the results back to your HTML page. You could lay these results out however you liked, fo example in a table, and allow the users to select which ones needed inserting into the database. You would then push that data back to the server to be inserted in the database. A few more moving parts if you go this route, but probably a better experience for your users. You would effectively need to write your HTML page, the server-side scripts, and probably tie them both together with some AJAX calls written in Javascript (jQuery).

Once you know what you want, it's fairly straight forward to code.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial