Tyler Hutchison tyler.hutchison@particle.io asked me to post this question here:
Though I have been teaching the IoT class using the Argon for 4 years, my background is more electrical engineering than coding. So, I occasionally run up against things that I am less proficient at.
I like to show my students a webhook example in the class. In the DeviceOS documentation there is an openweathermaps.org example that I had been using. However, openweathermaps.org changed their registration and so now in order to get an API key that works, you need to give them a credit card (even if you say within the free usage limit). This doesn’t work in our environment with students.
So, I have changed to using TomTom where I can still get a totally free / no credit card API and doing a query to find the closed Pizza to my classroom. This works:
However, the JSON that I get back is an outer object of an Array with the GPS coordinates in the inner object(s). I am, at best, a total novice at JSON. I was wondering if there is anyone in your education support team that could
- Show me how to setup the “response template” in the webhook. I think I know how to modify the “query” given the above. I think my issue is I don’t know how to deal with the other array.
- Show me how to then parse the json on the Argon to extract just lat and lon.
Here is what gets returned from the query (it is obviously easier to read in a JSONViewer)
{"summary":{"query":"pizza","queryType":"NON_NEAR","queryTime":6,
"numResults":1,"offset":0,"totalResults":94,"fuzzyLevel":1,
"geoBias":{"lat":35.08425,"lon":-106.64924},"queryIntent":[],
"geobiasCountry":"US"},"results":[{"type":"POI",
"id":"W8FPHJMG6uTenwbelVPptg","score":0.9930446148,
"dist":70.421687,"info":"search:ta:840351000124089-US","poi":
{"name":"JC's New York Pizza Department","phone":"+1 505-766-6973",
"categorySet":[{"id":7315036}],"url":"jcnypd.com",
"categories":["pizza","restaurant"],
"classifications":[{"code":"RESTAURANT",
"names":[{"nameLocale":"en-US","name":"restaurant"},
{"nameLocale":"en-US","name":"pizza"}]}]},
"address":{"streetNumber":"215","streetName":"Central Avenue Northwest",
"municipalitySubdivision":"Downtown Albuquerque",
"municipality":"Albuquerque",
"countrySecondarySubdivision":"Bernalillo","countrySubdivision":"NM",
"countrySubdivisionName":"New Mexico",
"postalCode":"87102","extendedPostalCode":"87102-3317",
"countryCode":"US","country":"United States","countryCodeISO3":"USA",
"freeformAddress":"215 Central Avenue Northwest,
Albuquerque, NM 87102","localName":"Albuquerque"},
"position":{"lat":35.084629,"lon":-106.64986},
"viewport":{"topLeftPoint":{"lat":35.08553,"lon":-106.65096},
"btmRightPoint":{"lat":35.08373,"lon":-106.64876}},
"entryPoints":[{"type":"main",
"position":{"lat":35.08433,"lon":-106.6499}},
{"type":"main","position":{"lat":35.08433,"lon":-106.64991}}]}]}