OpenLibrary API issues

I’m trying to get data from the OpenLibrary API into a Bootstrap Generated table. I have a database query which returns a list of ISBN numbers and then a repeat which gets the information for each book. That runs fine and returns results like this…

"repeat1": [
{
"ISBN": "0142001805",
"api2": {
"status": 200,
"headers": {
"0": "HTTP/1.1 200 OK",
"Server": "nginx/1.4.6 (Ubuntu)",
"Date": "Sat, 08 Aug 2020 23:29:24 GMT",
"Content-Type": "application/json",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Method": "GET, OPTIONS",
"Access-Control-Max-Age": "86400",
"X-OL-Stats": "\"IB 1 0.025 MC 5 0.003 TT 0 0.031\""
},
"data": {
"ISBN:0142001805": {
"publishers": [
{
"name": "Penguin Books"
}
],
"pagination": "vii, 374 p. ;",
"identifiers": {
"openlibrary": [
"OL17090757M"
],
"isbn_10": [
"0142001805"
],
"librarything": [
"4921"
],
"goodreads": [
"27003"
]
},
"subtitle": "a novel",
"title": "The Eyre affair",
"url": "https://openlibrary.org/books/OL17090757M/The_Eyre_affair",
"classifications": {
"lc_classifications": [
"PR6106.F67 E97 2003"
]
},
"notes": "Originally published in the United Kingdom in 2001.",
"number_of_pages": 374,
"cover": {
"small": "https://covers.openlibrary.org/b/id/6499696-S.jpg",
"large": "https://covers.openlibrary.org/b/id/6499696-L.jpg",
"medium": "https://covers.openlibrary.org/b/id/6499696-M.jpg"
},
"subject_places": [
{
"url": "https://openlibrary.org/subjects/place:wales",
"name": "Wales"
}
],
"subjects": [
{
"url": "https://openlibrary.org/subjects/books_and_reading",
"name": "Books and reading"
},
{
"url": "https://openlibrary.org/subjects/thursday_next_(fictitious_character)",
"name": "Thursday Next (Fictitious character)"
},
{
"url": "https://openlibrary.org/subjects/crimean_war,_1853-1856",
"name": "Crimean War, 1853-1856"
},
{
"url": "https://openlibrary.org/subjects/women_detectives",
"name": "Women detectives"
},
{
"url": "https://openlibrary.org/subjects/fiction",
"name": "Fiction"
},
{
"url": "https://openlibrary.org/subjects/fathers_and_daughters",
"name": "Fathers and daughters"
},
{
"url": "https://openlibrary.org/subjects/censorship",
"name": "Censorship"
},
{
"url": "https://openlibrary.org/subjects/characters_and_characteristics_in_literature",
"name": "Characters and characteristics in literature"
}
],
"subject_people": [
{
"url": "https://openlibrary.org/subjects/person:thursday_next",
"name": "Thursday Next"
}
],
"key": "/books/OL17090757M",
"authors": [
{
"url": "https://openlibrary.org/authors/OL1393212A/Jasper_Fforde",
"name": "Jasper Fforde"
}
],
"publish_date": "2003",
"by_statement": "Jasper Fforde",
"publish_places": [
{
"name": "New York, N.Y., U.S.A"
}
],
"ebooks": [
{
"checkedout": false,
"formats": {},
"preview_url": "https://archive.org/details/eyreaffairnovel00ffor",
"borrow_url": "https://openlibrary.org/books/OL17090757M/The_Eyre_affair/borrow",
"availability": "borrow"
}
]
}
}
}
},
{
"ISBN": "0143123270",
"api2": {
"status": 200, ETC...

I then have a server connect on my page which grabs that info and a table which I was trying to grab just the basic info from, but the table only shows the headers.

<table class="table"> <thead> <tr> <th>Title</th> <th>Url</th> </tr> </thead> <tbody is="dmx-repeat" dmx-generator="bs4table" dmx-bind:repeat="serverconnect1.data.repeat1[0].api2.data.ISBN" id="tableRepeat1"> <tr> <td dmx-text="title"></td> <td dmx-text="url"></td> </tr> </tbody> </table>

There are no errors on the page.

If anyone can steer me in the right direction that would be great! Thanks.

I hate it when api architects use this type of structure – using values where there should be a key.

The problem is right at the beginning of what is return:

"data": {
"ISBN:0142001805": {
"publishers": [
{
"name": "Penguin Books"
}
],

...

The ISBN:0142001805 is really a dynamic value, but the architect uses it as a key. Someday, somebody will help me understand why this is done!

Anyhow…we have a way to get it using Wappler.

On the server side, you can use a Set Value action right after your api action to grab the elements you need:

Sometimes the UI is a bit challenged in dealing with indexed items, so you might have to copy/paste this in:

api2.data.values()[0].title
api2.data.values()[0].url

This says, give me the title/url from the first value that is in the api2.data object. Just tick output on each action to make sure it is sent to the client.

Hopefully I’ve deciphered your json correctly!

1 Like

Awesome!!! Thanks so much for your help.