[Solved] How to Access Property in Object from WEBAPI

Hey there,

I’m getting “undefined” when trying to access the property of an Object in the API response when setting the text value of a label, if I don’t use a List component. If I use a List component, I cannot get the text to change at all. Either way, I cannot access the property value. Please can someone help?

So far I’ve watched the YT tutorials, read this: Can't get properties from list object and this JSON to List Help - #11 by Mark but without success as I’m not sure what I’m doing wrong.

Here’s how it looks:

This is the URL being called: https://jsonplaceholder.typicode.com/comments?id=1
And this is the response:
[
{
“postId”: 1,
“id”: 1,
“name”: “id labore ex et quam laborum”,
“email”: “Eliseo@gardner.biz”,
“body”: “laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium”
}
]

I know the URL works as I can set the text of the label to just be the raw response and this works every time. Screenshot of response in app and blocks if I just sent the label text to be the response

But…

When the blocks are like this, the text of the label becomes “undefined”

When the blocks are like this, the text of the label does not change

I’ve tried replacing the get property “email” with a string block and typing in ‘email’, changing the list number/counter to 0 and 2 (in case there is an index issue) and a few other variations but I do not know how to access the property of an object.

Please could you advise what I’ve done wrong and how I can debug this (to help myself) so that I can get the object property value and use lists correctly with the API call?

Thanks in advance

PS. Full disclosure, I did originally open a topic on this here WebAPI Cannot access property which was marked as resolved but this was down to the API itself not working. Now the API is definitely up, I still cannot get the code to work hence the new thread. Thanks

Hi,

First you need to get the list item, and then the object, and not Vice versa as you do.

1 Like

This “[ ]” in the responds means that is a list ! and an advice you can always use “get object properties of” to help you wich objects to request

Thanks @actech and @Daniel_Coglitore. Your responses helped me to fix it! For anyone else struggling, here are the working blocks to set the label text to be the value of the email property :raised_hands:

1 Like

I tried for this api link

https://api.coinlore.net/api/ticker/?id=1

to take price_usd

not working. any idea why???

Daniel please help me with this API https://exmarkets.com/api/trade/v1/market/ticker/DDK-usdc
show on browser like this: {“last”:“2.16500000”,“high”:“2.19000000”,“low”:“1.75710000”,“volume”:“148.82300000”,“bid”:“1.80200000”,“ask”:“2.15990000”}

I tried already with your metode above but failed. I need to pick the “last” price

Take a look at this more recent topic @alekdrajatf

@eoinparkinson and @jared have done a great job explaining how to parse a JSON response.

If you can’t get it working, please create a new topic, as the issue might be specific to the Coinlore API.

Thanks

1 Like

Thanks. I’ll go there

1 Like