Getting an image src from a website using thunkable API

I’m using the Google custom search API to display a website’s games through an app. I’m able to retrieve the links on the website, but when I try to retrieve data within a pice of data I run into trouble.

I’m trying to retrieve an image URL that is inside pagemap > cse_thumbnail > src

Here is how I’ve set up my block code:

but it returns null and I’m unsure why I retrieved a youtube video’s thumbnail with the same block code structure but I’ve had no luck in retrieving an image from a website.

Any help would be appreciated!

Can you back out a bit more and show the whole api call including the loop you seem To have this in. Not sure this code fits your need but I’d need more context to comment fully.

I see two problems:

  1. You need to convert the JSON response to an object before you can get the properties of that object. Maybe you’re already doing this but it’s not clear from your screenshot.
  2. You are parsing the JSON data in reverse. The first/outer property in the JSON tree is “pagemap” but you’re starting by getting the property “src” of the object. So while your parsing looks like this: src–>cse_thumbnail–>pagemail, you actually want it to be pagemap–>cse_thumbnail–>src. If that’s confusing, consider that the innermost get property of object block is going to run first in your code.

@tatiang and @jared

Thanks for your help so far!

I think I did what you recommend to do Tatiang, but it’s still returning null. Here’s a closer look at the function

Screen Shot 2021-08-20 at 4.45.16 PM

you should try this block:
Screenshot 2021-08-21 114139

You’re making things complicated before you have the JSON parsing working properly. Right now, you’re converting the JSON response to an object and then getting the “items” property from that and then looping through that list and attempting to get the property of object “j” which is now a list, not an object.

Simplify things greatly and just see if you can get one correct value from the “src” property without using a loop.