Page 1 of 1

wget doesn't work

Posted: 19 Oct 2016 22:43
by gazier20
Hi,

When I navigate to this url with my browser, it works :

http://192.168.1.54:8083/ZWaveAPI/Run/d ... sic.Set(0)

I want to do the same from my terminal in raspberry pi (to schedule a cron) :

I tried :
sudo wget -o ./z-way.api -O ./z-way.api http://127.0.0.1:8083/ZWaveAPI/Run/devi ... Set%280%29

sudo wget -o ./z-way.api -O ./z-way.api "http://127.0.0.1:8083/ZWaveAPI/Run/devi ... sic.Set(0)"

...

any idea ?

I don't receive any error from the terminal.

Thank you

Re: wget doesn't work

Posted: 20 Oct 2016 15:41
by Provo
My guess is that on your browser, you're logged in. Your browser handles the cookies for you. With wget you could either log in, save the cookies and then send the api request using the cookies, or you could pass your username and password with the api request.

For the latter solution, try changing "http://127.0.0.1:8083/" to "http://username:password@127.0.0.1:8083/" (with your actual username and password of course).

(I don't understand why you're running wget as root and outputting both the log and the response to the same file, but that shouldn't be a problem.)

Re: wget doesn't work

Posted: 20 Oct 2016 15:45
by gazier20
I found the solution.

It's a cookie issue. We need a "login" cookie to run command line.

Here is the solution : https://forum.z-wave.me/viewtopic.php?f=3419&t=22778
Thanks to viper384

To do this from the command line you need to authenticate first and save a session cookie...

wget -q --header "Accept: application/json" --header "Content-Type: application/json" --post-data '{"form":true,"login":"admin","password":"admin","keepme":false,"default_ui":1}' http://127.0.0.1:8083/ZAutomation/api/v1/login --keep-session-cookie --save-cookie /tmp/zway-cookie.txt -O - 1>&2 >/dev/null

Then you use that session cookie for all subsequent requests with --load-cookies.

wget --load-cookies /tmp/zway-cookie.txt "http://127.0.0.1:8083/ZWaveAPI/Run/devi ... ].Set(255)" - O - 1>&2 >/dev/null