Howto connect to API (v2) using CURL (on linux)
Hi all,
Here is a script to easily connect to the APIv2.
api.sh:
- #!/bin/sh
- #CLOUD APIv2
- url=https://my.zipato.com:443/zipato-web/v2
- #ZIPABOX APIv2 (does not work for me)
- #url=http://172.31.17.2:8080/zipato-web/v2
- login=<ZIPATO_LOGIN>
- password=<ZIPATO_PASSWORD>
- echo "##########################################################"
- echo "base url = "\"$url\"
- echo "login = "\"$login\"
- echo "password = "\"$password\"
- rm -f cookies init.txt login.txt
- echo "##########################################################"
- uri="user/init"
- echo "REQUEST = "$uri
- echo "##########################################################"
- curl -is -c cookies "$url/$uri" > init.log
- cat init.log ; echo
- echo "##########################################################"
- nonce=`cat init.log | grep nonce | \
- sed -e 's/^[^"]*"nonce"[^"]*"\([^"]*\)"[^"]*$/\1/' | tail -n 1`
- echo "nonce = "\"$nonce\"
- sha=`echo -n $password | sha1sum | awk '{print $1}'`
- echo "sha = "\"$sha\"
- token=`echo -n $nonce$sha | sha1sum | awk '{print $1}'`
- echo "token = "\"$token\"
- echo "##########################################################"
- uri="user/login?username=${login}&token=${token}"
- echo "REQUEST = "$uri
- echo "##########################################################"
- curl -is -b cookies "$url/$uri" > login.log
- cat login.log ; echo
- echo "##########################################################"
- exit 0
To use it, replace <ZIPATO_LOGIN> and <ZIPATO_PASSWORD> by your login/password and execute the script. It will create 3 files: cookies (the cookies), init.log (the log of the init) and login.log (the log of the login). You can try local APIv2, but it seems nonfunctional.
After you called ./api.sh, you can try :
#GET Endpoints
curl -is -b cookies "https://my.zipato.com:443/zipato-web/v2/endpoints"
#GET Attributes of an Endpoint
curl -is -b cookies "https://my.zipato.com:443/zipato-web/v2/endpoints/<ENDPOIT_UUID>?attributes=true"
#GET The value of an Attribute
curl -is -b cookies "https://my.zipato.com:443/zipato-web/v2/attributes/<ATTRIBUTE_UUID>/value"
#SET The value of an Attribute
curl -is -b cookies -H "Content-Type: application/json;charset=UTF-8" -XPUT -d '{ "value" : "false" }' "https://my.zipato.com:443/zipato-web/v2/attributes/<ATTRIBUTE_UUID>/value"
Cheers !
Local connection will work after firmware upgrade. This will happen within a next few days.
Local connection will work after firmware upgrade. This will happen within a next few days.
Thanks!
i tried to convert it to powershell and here's a working script in powershell.
Example:
Thanks!
i tried to convert it to powershell and here's a working script in powershell.
Example:
Replies have been locked on this page!