API calls in Ninox
Hi there all.
I have been spending a few days TRYING to get my head around API calls in Ninox. I can get a result if I hard code in the url and parameters, but am unsure how to structure the query using variables. For example: I am trying to get weather information. If I hard code "London" into the query, I get the results back for London. But if I get the user to enter their location into a box and then try use that I can't.
Now, when I get my data back, I can pull the entire response into a text box in JSON format. How do I then access the individual fields please? I have been searching all over and cannot find the answer.This is my code that I currently have in a button:
let response := http("GET", "https://api.weatherapi.com/v1/current.json?q=London&key=77037*******************101");
'Json Response' := formatJSON(response.result);
I'd like to be able to put, for example: let location:=London, then put location into the query.
And the response: {"location":{"name":"London","region":"City of London, Greater London","country":"United Kingdom","lat":51.52,"lon":-0.11,"tz_id":"Europe/London","localtime_epoch":1706513221,"localtime":"2024-01-29 7:27"},"current":{"temp_c":9,"temp_f":48.2,"is_day":0,"condition":{"text":"Fog","icon":"//cdn.weatherapi.com/weather/64x64/night/248.png","code":1135},"wind_mph":10.5,"wind_degree":170,"wind_dir":"S","pressure_mb":1023,"precip_mm":0,"humidity":93,"cloud":0,"feelslike_c":8.2,"vis_miles":0,"uv":1,"gust_mph":15}}
I hope my 2 questions make sense. I don't just want the code, but an explanation of what to do would be awesome.
Thanks for your time and I hope my ramblings make sense to you clever people out there.
4 replies
-
Hi ,
You could make the URL in front with a variable like:
let URL := "https://api.weatherapi.com/v1/current.json?q="+datatextfieldContainingThePlace+"&key=77037*******************101" let response := http("GET", URL); 'Json Response' := formatJSON(response.result);
for the response you can use the variable 'Json Response' like you would use a select() function like:
'Json Response'.location.name <gives you the Location Name
'Json Response'.current.temp_c < gives you the temperature
'Json Response'.current.condition.text <gives you the weathercondition
Content aside
- Status Answered
- 10 mths agoLast active
- 4Replies
- 111Views
-
2
Following