December 2018
Intermediate to advanced
226 pages
4h 57m
English
Here, we call the weather API to get coordinates for a particular location (say London, England):
#use the city of london as a reference $city="london" $urlx="https://samples.openweathermap.org/data/2.5/weather?q="+$city+"&appid=b6907d289e10d714a6e88b30761fae22"# used to Invoke API using GET method $stuff = Invoke-RestMethod -Uri $urlx -Method Get#write raw json $stuff#write the output of latitude and longitude write-host ("Longitude: "+$stuff.coord.lon+" , "+"Latitude: "+$stuff.coord.lat)
The output is as follows:
PS C:\Users\abhishek.ratan> C:\gdrive\book2\github\edition2\chapter1\api_invoke_ps.ps1coord : @{lon=-0.13; lat=51.51} weather : {@{id=300; main=Drizzle; description=light intensity drizzle; icon=09d}} base : stations ...Read now
Unlock full access