I built a VBA code in order to obtain data from Google Books API by entering the ISBN code of a book that I scanned previously with a bar scanner app by using my mobile phone. With VBA-JSON library everything seems ok, but I have still one object that I cannot import.
The JSON file that I use to check if the code works is this:
https://www.googleapis.com/books/v1/volumes?q=isbn:9780553897852
And this is the code I use now to pick the data:
Public Sub exceljson()
'Error message if active cell is empty
If ActiveCell.Value = 0 Then
MsgBox "Select cell with ISBN", vbExclamation
Exit Sub
End If
'Error message if there is no match
On Error GoTo ErrMsg
Dim http As Object, JSON As Object, i As Integer, subitem As Object
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", "https://www.googleapis.com/books/v1/volumes?q=isbn:" & ActiveCell.Value, False
http.send
Set JSON = ParseJson(http.responseText)
i = ActiveCell.Row
For Each Item In JSON("items")
Set subitem = Item("volumeInfo")
Sheets(1).Cells(i, ActiveCell.Column + 1).Value = subitem("publishedDate")
Sheets(1).Cells(i, ActiveCell.Column + 2).Value = subitem("title")
Sheets(1).Cells(i, ActiveCell.Column + 3).Value = subitem("subtitle")
Sheets(1).Cells(i, ActiveCell.Column + 4).Value = subitem("pageCount")
'To obtain ISBN-10 and ISBN-13
j = 5
For Each Child In subitem("industryIdentifiers")
Sheets(1).Cells(i, ActiveCell.Column + j).Value = Child("identifier")
j = j + 1
Next
i = i + 1
'To end with success
Next
MsgBox ("Process complete"), vbInformation
Exit Sub
'To en with an error message
ErrMsg:
MsgBox ("No match obtained"), vbCritical
End Sub
This is the resulted EXCEL sheet I made
Actually I have the fields: year of publication, title, subtitle, pages, ISBN-10, ISBN-13 presented in the subsequent cells of the ActiveCell I write the ISBN. However I have no idea of how to collect data from "authors" array. Is the only field I miss of the data so I really appreciate if you could help me. Thanks in advance.