Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Panel
bgColor#fff
Code Block
languagepy
themeDJangoEclipse
firstline01
titleExample Script with authentication
linenumberstrue
import json
import requests

topLevelUrl = 'http://127.0.0.1:8083' #define proper address of the Z-way server
RequestUrl= topLevelUrl +'/ZAutomation/api/v1/devices/{DEFINE COMMAND}'
LoginUrl = topLevelUrl + '/ZAutomation/api/v1/login'
username = 'admin' #modify that - I would suggest to create a dedicated user
password = 'password' #Try not to use special chars in password
LoginHeader = {'User-Agent': 'Mozilla/5.0', 'Content-Type': 'application/json'}
Formlogin = '{"form": true, "login": "'+username+'", "password": "'+password+'", "keepme": false, "default_ui": 1}'

session = requests.Session()
session.post(LoginUrl,headers=LoginHeader, data=Formlogin)

response = session.get(RequestUrl)
#html = response.text
#print html
parsed_json = response.json()
print parsed_json

This was tested and working with Z-way server 2.3

...