Web API returning null results in JSON

Hi, I’m a new Thunkable user and am having trouble with the results I’m getting in a Web API call.

The property is “WeatherText” and I thought it was setup correctly, but it’s not. I’ve read similar questions here and watched your YouTube videos, but no luck yet.

My block, the JSON results, and the web preview are below. Any ideas what I’m doing wrong?

Thanks,
Dean…

Screen Shot 2022-09-01 at 4.11.19 PM

2 Likes

This is returning a list. You need to get the object at the #1 position of the “get object from response” list.

4 Likes

It looks like the JSON response might be a list/array. Can you post the full json response as text? Use the </> button in the forum toolbar to format it properly.

4 Likes

Sure, here’s the raw data. Apologies for the sloppy formatting. This is how it was returned.

[
 {
  "LocalObservationDateTime":"2022-09-01T20:29:00-04:00",
  "EpochTime":1662078540,
  "WeatherText":"Mostly clear",
  "WeatherIcon":34,
  "HasPrecipitation":false,
  "PrecipitationType":null,
  "IsDayTime":false,
  "Temperature":{
   "Metric":{
    "Value":28.9,
    "Unit":"C",
    "UnitType":17
   },
   "Imperial":{
    "Value":84.0,
    "Unit":"F",
    "UnitType":18
   }
  },
  "MobileLink":"http://www.accuweather.com/en/us/sugar-hill-ga/30518/current-weather/2192707?lang=en-us",
  "Link":"http://www.accuweather.com/en/us/sugar-hill-ga/30518/current-weather/2192707?lang=en-us"
}
]
1 Like

Thanks for cleaning up the data, @jared. It’s actually readable now.

And I’ll try the “get object” solution tomorrow. Cheers!!

Hey @jared, I couldn’t wait until tomorrow.

I tried getting the object in the #1 position, but I’m still seeing a null value. Here’s what I tried in the Property Name field, based on the Web API docs. Can you see what I’m doing wrong, by chance?

I think what Jared and Tatian were suggesting is that this API can return forecasts for multiple locations.

Each locale is its own item in a list of locations.

If you use the list blocks to get the first item you can then get the corresponding forecast, temperature etc for that location.

Hope that helps

1 Like

use this technique for getting the weather info for the first location (see …get # 1…below)

i hope this works for you

4 Likes

Thanks @domhnallohanlon. The URL I’m calling includes the lon and lat for that specific location. I included it in my initial post, but Askimet flagged it.

1 Like

I used your API response in a variable and made the following code

When clicking the button I get the following

Hope this makes it easier for you to get the results.

3 Likes

@muneer, may I get the full init string you’re using for the APIResponse, please? I can’t see the end and am unfamiliar with the syntax normally used to close it.

1 Like

It’s your string.

You will get it from the API. I used it to demonstrate how the blocks work.

Perfect, thank you, @muneer. It’s working when I paste the full JSON result, but how will it be able to present current and live data?

1 Like

Hey @deanmachine Based on the feedback from @muneer , what are your blocks looking like now?

1 Like

Thanks for checking, @jared. I just figured it out after following the OpenWeather Web API tutorial on YouTube, switching to that API, and going through a lot of trial and error.

The only thing that’s different in that block was changing the Opens to Starts in my when do block. And to make it even more strange, they both work now. I have no idea why or what happened, but things are working and I’m flying high!! Thanks again.

Screen Shot 2022-09-03 at 7.09.15 PM

3 Likes