Monday, March 2, 2015

Amazon Echo Api

As I posted in my previous post, I recently bought an Amazon Echo. I saw some videos of people using their Echo to do home automation with a Raspberry Pi or Adriano. They did this by using something like Node, or python to monitor the tasks that are added to the Echo. To do the monitoring, they used the undocumented, unsupported, Api of the Echo.

I wanted to play around too. While I really don’t do anything related to home automation, I still wanted to explore the Echo Api and see if I could implement some type of wrapper for it in C#.

Here is what I found with the undocumented Api:

  • The desktop app connects to a WebSocket on the Echo device. I have not yet successfully connected to the socket, nor have I tried yet.
  • There is a url to get the latest “cards” - /api/cards?limit=N
  • Get the tasks - /api/todos?type=TASK
  • Get the shopping list - /api/todos?type=SHOPPING_ITEM
  • Get registered devices - /api/device
  • Get the media state for a device - /api/media/state?deviceSerialNumber={0}&deviceType={1}
  • Get the connected bluetooth devices - /api/bluetooth
  • Get music accounts - /api/music-account-details
  • logout - /logout
  • Get the capabilities of each provider - /api/media/provider-contenttype-capabilities

I also found that I should be able to send commands to Play, Stop, Next Track, Previous Track, Shuffle, Repeat, and set the Volume. The web app does this by first doing an HTTP/OPTIONS request, followed by an HTTP/POST. The post contains a JSON payload that contains the meta data of the device and what the volume is (if setting the volume). I have been unable to successfully POST these commands as there should be a CSRF token sent along with the POST. This token should be available in the cookies, but for some reason that I have not figured out yet, the token does not exist in the CookieContainer.

Currently, I have a working wrapper Api to Login, Logout, Get Tasks (TODO or SHOPPING), and update a task. I have posted my code on GitHub and I will push changes when I make them. This is just a little toy project that I decided to play with when bored. I will continue to work on it in free time, while I am interested in it. Feel free to fork it.

Amazon Echo Api

Happy Hacking of your Echo

Amazon Echo Api

As I posted in my previous post, I recently bought an Amazon Echo. I saw some videos of people using their Echo to do home automation with a Raspberry Pi or Adriano. They did this by using something like Node, or python to monitor the tasks that are added to the Echo. To do the monitoring, they used the undocumented, unsupported, Api of the Echo.

I wanted to play around too. While I really don’t do anything related to home automation, I still wanted to explore the Echo Api and see if I could implement some type of wrapper for it in C#.

Here is what I found with the undocumented Api:

  • The desktop app connects to a WebSocket on the Echo device. I have not yet successfully connected to the socket, nor have I tried yet.
  • There is a url to get the latest “cards” - /api/cards?limit=N
  • Get the tasks - /api/todos?type=TASK
  • Get the shopping list - /api/todos?type=SHOPPING_ITEM
  • Get registered devices - /api/device
  • Get the media state for a device - /api/media/state?deviceSerialNumber={0}&deviceType={1}
  • Get the connected bluetooth devices - /api/bluetooth
  • Get music accounts - /api/music-account-details
  • logout - /logout
  • Get the capabilities of each provider - /api/media/provider-contenttype-capabilities

I also found that I should be able to send commands to Play, Stop, Next Track, Previous Track, Shuffle, Repeat, and set the Volume. The web app does this by first doing an HTTP/OPTIONS request, followed by an HTTP/POST. The post contains a JSON payload that contains the meta data of the device and what the volume is (if setting the volume). I have been unable to successfully POST these commands as there should be a CSRF token sent along with the POST. This token should be available in the cookies, but for some reason that I have not figured out yet, the token does not exist in the CookieContainer.

Currently, I have a working wrapper Api to Login, Logout, Get Tasks (TODO or SHOPPING), and update a task. I have posted my code on GitHub and I will push changes when I make them. This is just a little toy project that I decided to play with when bored. I will continue to work on it in free time, while I am interested in it. Feel free to fork it.

Amazon Echo Api

Happy Hacking of your Echo