Skip to end of metadata
Go to start of metadata

Problem

If Authentication for API is defined in Z-way server - it would be not possible to directly execute API commands - we would receive error 401.

There are some solutions like authentication in the first step to grab a cookie and then reuse that cookie when executing API. We can as well disable Authentication for API - but this is security hole for the whole automation system.

To solve that issue we can create a small script which could by-pass this problem.

Solution

Please find below code related to this issue.

Example Script with authentication
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

1. Based on Z-wave.me forum