Web API not work

Hi Guy,

I try to learn API in thunkable and sample api is book. i am not sure why is not return anything.

Here the url and my block.
url : https://api.alquran.cloud/v1/ayah/262

block
image

you have to drill downa few more levels:
see the additional (nested) blocks i’ve used:

here is my output

you could also use this notation (my preferred):

note that you don’t have to nest blocks - one level is needed but the full “path” in the the json tree needs to be provided - concatenated by dot. if an array is involved,it could be coded, for example data.book[1].number

2 Likes

Hi @manyone

thank you for your guidance. so most important i have to understand how the json is formatted right? i try to use json formatter and it make sense.

Hi @manyone

if i want to get following text does not seem work. if you can advice me how the block look like.
image

my block

url :http://api.alquran.cloud/v1/surah/114

instead of get property “ayahs”, you should try get_property “ayahs[1]” (because ayahs is an array (you can tell because it starts with “[”

i f you want to handle arrays dynamically so you don’t have to pre-count how many elements in an array,
use the method used here:

study the way the ‘for each item’ block is used to loop thru the array. you will have to do a similar thing.

I try to simulate same block but not work.

Block
image

web api url: http://api.alquran.cloud/v1/surah/114

note the level of nesting for ayah

here’s the result

here’s another way of handing the json structure by using a count block - note how blocks nest

this time, using a short cut notation

finally, here is the first version (at the top) expressed in short cut notation (note “data.ayahs”, compare to the first version)

all of these produce the same output

here’s the link to the toy project (refer to screen 3)
https://x.thunkable.com/copy/93ec9cf50be75dcefd5986ab596bf439

It worked for me. thank you for your help.

I have curiosity about your method, why not using url instead of using json format in the block?

it’s just a debugging technique.

i knew i was going to do a lot of trial and error so i copied the results of the first call and saved it - and used it every time i tested my changes.

if i had used the api call in my block - i would have been calling the api every single time and most likely it woud have returned the same value. also if the api call had a price - i would be charged for every call.

it’s just a way of saving time. after i’m done i could restore the “get data” portion back to the usual get-api call.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.