This object is in archive! 

Howto connect to API (v2) using CURL (on linux)

Bad Wolf shared this idea 10 years ago
Under Consideration

Hi all,


Here is a script to easily connect to the APIv2.


api.sh:

  1. #!/bin/sh
  2. #CLOUD APIv2
  3. url=https://my.zipato.com:443/zipato-web/v2
  4. #ZIPABOX APIv2 (does not work for me)
  5. #url=http://172.31.17.2:8080/zipato-web/v2
  6. login=<ZIPATO_LOGIN>
  7. password=<ZIPATO_PASSWORD>
  8. echo "##########################################################"
  9. echo "base url = "\"$url\"
  10. echo "login = "\"$login\"
  11. echo "password = "\"$password\"
  12. rm -f cookies init.txt login.txt
  13. echo "##########################################################"
  14. uri="user/init"
  15. echo "REQUEST = "$uri
  16. echo "##########################################################"
  17. curl -is -c cookies "$url/$uri" > init.log
  18. cat init.log ; echo
  19. echo "##########################################################"
  20. nonce=`cat init.log | grep nonce | \
  21. sed -e 's/^[^"]*"nonce"[^"]*"\([^"]*\)"[^"]*$/\1/' | tail -n 1`
  22. echo "nonce = "\"$nonce\"
  23. sha=`echo -n $password | sha1sum | awk '{print $1}'`
  24. echo "sha = "\"$sha\"
  25. token=`echo -n $nonce$sha | sha1sum | awk '{print $1}'`
  26. echo "token = "\"$token\"
  27. echo "##########################################################"
  28. uri="user/login?username=${login}&token=${token}"
  29. echo "REQUEST = "$uri
  30. echo "##########################################################"
  31. curl -is -b cookies "$url/$uri" > login.log
  32. cat login.log ; echo
  33. echo "##########################################################"
  34. 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 !

Replies (2)

photo
1

Local connection will work after firmware upgrade. This will happen within a next few days.

photo
1

Thanks!


i tried to convert it to powershell and here's a working script in powershell.

  1. $login="user@mail.com"
  2. $password="password"
  3. Function Get-StringHash([String] $String,$HashName = "SHA1")
  4. {
  5. $StringBuilder = New-Object System.Text.StringBuilder
  6. [System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))|%{
  7. [Void]$StringBuilder.Append($_.ToString("x2"))
  8. }
  9. $StringBuilder.ToString()
  10. }
  11. $sessioninit=Invoke-RestMethod -uri https://my.zipato.com:443/zipato-web/v2/user/init -SessionVariable sessionvar
  12. $sha1=Get-StringHash $password
  13. $nounce=$sessioninit.nonce
  14. $token1=$nounce+$sha1
  15. $token= (Get-StringHash $token1)
  16. $url="https://my.zipato.com:443/zipato-web/v2/user/login?username="+$login+"&token="+$token
  17. $session= Invoke-RestMethod -Uri $url -WebSession $sessionvar

Example:

  1. Invoke-RestMethod -uri https://my.zipato.com:443/zipato-web/v2/devices -WebSession $sessionvar

photo
1

Excellent, did you get any further? I just started looking at this

photo
Leave a Comment
 
Attach a file