question

Donald Zimmanck avatar image
Donald Zimmanck asked

JSON query to a Third Party API - Solar Application

Hello all, I am working on a skill that allows Alexa to response to questions regarding the performance of a solar array using the Enphase Energy API. It would work basically like the following: "Alexa. Ask Enphase how much energy my array has produced in the last month." ALEXA <"Your solar array has produced 520 kWh in the last month."> "Alexa. Ask Enphase how much power I am currently producing" ALEXA <"Your solar array is currently producing 4.2kW."> I've written the basic intent interpretation code and currently have Alexa return fake hard coded solar data. Now I want to link it to the Enphase API. The Enphase API is a relatively simple JSON based API. I'm just not very familiar with JavaScript or AWS Lambda. Is there a way to embed JSON query's within a AWS Lambda function and parse the data so that Alexa can respond? Here is an example of using the API using cURL. Request $ curl -v " https://api.enphaseenergy.com/api/v2/systems/67/summary?key=452a5aac149b0fe246999de0455a7575&user_id=4d7a45774e6a41320a" Response HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Status: 200 {"system_id":67,"modules":35,"size_w":6270,"current_power":271,"energy_today":30030,"energy_lifetime":59847036,"summary_date":"2015-03- 04","source":"microinverters","status":"normal","operational_at":1201362300,"last_report_at":1425517225} Thanks!
alexa skills kitdebugging
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jjaquinta avatar image
jjaquinta answered
This is a pure Javascript task. I don't think there is anything special about the Lambda environment you need to know. Find a book or look for a tutorial on the internet on how to call REST APIs from Javascript. That should do you.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Nick Gardner avatar image
Nick Gardner answered
Hi, The first thing I'd suggest is looking at the HistoryBuff sample skill, which can be found in the zip file here: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/using-the-alexa-skills-kit-samples. That sample includes a JSON API query to a third party API, so you should be able to either edit the sample code or use it as an example for your own development. -Nick
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Donald Zimmanck avatar image
Donald Zimmanck answered
Thanks! That example looks like a good starting point. It looks like it uses request which was what was recommended on StackOverflow as well.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.