How to remote control Amazon Alexa.
With this tutorial I want to guide you to control your Alexa (Amazon
Echo or Amazon DOT) via command line (cURL tool).
To remote control your Alexa you need to extract some authentication
credentials from a Browser session.
Therefore you have to use Google Chrome and open
https://alexa.amazon.com
When you are logged in to the Webservice select "Music and Books"
Then select the correct Alexa you want to manage on the top menu
And finally select the "TuneIn" icon.
Then search for the Radio station you are looking for and start the
station.
Next step is to open in Chrome the developer tools.
The Chrome menu, Tools > Developer Tools.
Ctrl+Shift+I on Windows.
Cmd+Opt+I on Mac.
Now select the "Network Tab" (1) and clear to clear the cache (2).
Then select the radio station you want to listen (3).
Now you should find in the network tab a line starting with
"queue-and-play" (4).
Now you can rightclick the line => copy => copy as cURL

After right-click please select "Copy as cURL" (on Windows "Copy as
cURL (cmd)").

Please open a Text editor and paste the clipboard.
Now you can find all the important credentials for authentication -
you need to copy them into the shell-scripts:
DEVICENUMBER = "G999LF0964210K58"
(SerialNumber)
DEVICETYPE = "A3S5BHHHU6VAYF"
CUSTOMERID = "A2C7IGOABH59PS"
CSRF = "-2012345694" (please
copy the complete csrf with leading sign)
COOKIE = "Cookie: x-amzn-<.......>.aA="; csrf=-2012345694" (the whole
very long string!)
guideId = "s133505" - this
is the parameter for the selected radio station on TuneIn - will be
required as parameter
Example cURL from Clipboard (this is just scrambled demo data - use
your own!):
curl
'https://pitangui.amazon.com/api/tunein/queue-and-play?deviceSerialNumber=G999LF0964210K58&deviceType=A3S5BHHHU6VAYF&guideId=s133505&contentType=station&callSign=&mediaOwnerCustomerId=A2C7IGOABH59PS' -X POST -H 'Origin:
http://alexa.amazon.com' -H 'Accept-Encoding: gzip, deflate, br' -H
'Accept-Language: en' -H 'User-Agent: Mozilla/5.0 (iPad; CPU OS 9_1
like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0
Mobile/13B143 Safari/601.1' -H 'Content-Type: application/json;
charset=UTF-8' -H 'Accept: application/json, text/javascript, */*;
q=0.01' -H 'Referer: http://alexa.amazon.com/spa/index.html' -H 'csrf: -2012345694' -H 'Cookie: x-amzn-dat-gui-client-v=1.24.986.0;
aws-target-static-id=14712345678-839972;
aws-session-id=168-0412369-4130549;
aws-session-id-time=2106194071l;
aws-x-main=PgpqvER9Wibauhf4zfSDriNBlBILfMnk;
aws-at-main=Atza|IwEBIAFsntUWFc_PZvFde5drDzPNXXXXXXXXXHPqI53aQNl-Fu83eAMUsFJmMtamv_4mLKEh6N82lqq8OHA8SKgh44X2MZwTguXNcUvd0-RVQyayT2lQ86JjoXvJrlMlrZIs7kJLWBryCGJEXXXXXXXXXXFJQpHhnGeC72ljNT_nVObL_wZoYhMFHVMXGiYjFyrb-QcjYY-I3ar-Q-kLAmzZYQIKU-mZ8GChNefKuG_x4ZZ2A06XXXXXXXXXOhX9w94vgmn2y3Qr9Q0rEi8K--UoFuTQ54GArubNsofNLh4U2dov8D7Gs3GoW6Hp2zEwt7cyumpRR_vceAz3aUjskoNKXsgDfpPZrebl-0R4bC6BfIasyoDOX9XXXXXXXXjRihKSxf4gs79p1ExYBmaBOX6glBrsKRqOXfk6Vh87_96uQ;
aws-userInfo=%7B%22arn%22%3A%22arn%3Aaws%3Aiam%3A%3A314911114493%3Aroot%22%2C%22alias%22%3A%22%22%2C%22username%22%3A%22MeinUser%2520Name%22%2C%22keybase%22%3A%22dhVv%2Fmb%2BJyCH%2BJA6zwfighlgs5jc0W0mVYXkLBkb77M%5Cu003d%22%2C%22issuer%22%3A%22https%3A%2F%2Fwww.amazon.com%2Fap%2Fsignin%22%7D;
__utmv=191231197.PgpqvER9Wibauhf4zfSDXXXXXXXXk;
s_dslv=1475471239073; regStatus=registered;
aws-target-visitor-id=1475445653051-715340.26_4;
aws-target-data=%7B%22support%22%3A%221%22%7D;
s_pers=%20s_ev15%3D%255B%255B%2527Typed%252FBookmarked%2527%252C%25212375474893114%2527%255D%255D%7C1632141293114%3B%20s_fid%3D0523A63XXXXXXXXX3C9679E640DA3570%7C1538547024210%3B%20s_dl%3D1%7C1475481765932%3B%20gpv_page%3Dno%2520value%7C1475481765939%3B;
session-id=151-3512347-8293901; session-id-time=2106212731l;
s_fid=71689F1234D6D238-299FD69294EFC3C1;
s_nr=1475492764173-Repeat; aws-ubid-main=151-3388123-1263140;
aws-session-token="lprp9YroXXXXXXXXXz5EFfSaPt96R0oSBWL2dR/AGFdlmk4QwRcVPXXXXXXXrmZ5kfHBdNwvSWWMKTnYU0pB5CE2XXXXXXUk6SIuaQYti17ZQ8B3NGwyCKNs7Lil+kz9qonZS5/cwtmrWHCe7SGx/QmPXXXXXXX89WbiV2xwTRkhVw6hTjO+8WUOXXXXXXXXi8MaR196v+Ewflx7dd3ouTVtY+hbJE4XSs=";
__utma=194891197.1975555581.1444474071.1475495555.1475555580.5;
__utmz=194555597.1475555680.5.2.utmccn=(referral)|utmcsr=console.aws.amazon.com|utmcct=/cloudwatch/home|utmcmd=referral;
ubid-main=152-8362434-2710144;
session-token="Y2Eoqs81+wIbanI7mPonK9t7gFvH7ZdTG2OxCZB3orqTILNY5ev4cFBWiSPTl2u8nFNXNmwtFP6RxnPBTunkdbHfpos8WYYOX7gEF52wnn5J3SknsvO99+MAT5GeyMR4JRa+ZOX+DcnIt8xtgYY2sSaEZ3JspjrQF+M9PUkuT9D4aYbZGRNa1BkFvoOt8Kettr9xxS/ODPfXEaE6xJr7qyPv0IQ3K6e+FbfGk3AWypY=";
x-main=4r7ZrJJV4BT1R2sWn2W4NpiXZm9RSJLD;
at-main=Atza|IwEEEEE4EikDns-CTHnGRqXXXcnnaij75AfcF1-XOBvphYTp_ATJHu6f0vDgMI7B1ApWn51cP6bqvG-XXXXeTPD8t7jl5El_FdhlYn3mmtn476FfnI5E7anoZNSKLyE-jauNJssBeGUjsSd0z8746mujYcJbKQsMMVVUlxcu4jXXxXXYcC4GasQyvOIp92wY-TPKAOys8NV0-yXH4xTGBzgJ0zzJa5JvyRz2v0x3fijvyXXXXXXSDhZtaDOZ6GOQlYrsUmudsorYUcUT52x0EYavXXXXX92cmgkMUzuTxppV1SpLk2Wk63LQQkCCZLs6_HWlnX2Saf0zgc13BdUehhSBiYHzJJeg1Ys7g68GLG5IuSGvyGe8ebmcN9KUDdD2CwphaeW34iy6dVKGbUpJ3GKVlz;
sess-at-main="eSHstcxm5Krki5T1EAcQyk9XXXXXXqMbqcJqDBaA=";
csrf=-2012345694' -H 'Connection: keep-alive' -H
'Content-Length: 0' --compressed
If you do the same task with a pandora sataion you will find your
"Pandora-station Token" very similar:
...(truncated)...
--data-binary '{"stationToken":"3406518391113140889","createStation":false}'
...(truncated)...
These stationToken can be provided to the alexa-pandora.sh as
paremeter to tune this station. Please keep in mind that Pandora
does only work with Alexa set to U.S. (due to licenses Pandora is
currently not available outside united states).
You have to define the Variables in the shell-scripts - and you can
control volume, select TuneIn or Pandora stations from the command
line.
Here you find the current shell-scripts: GitHub