Closed sdumorti closed 2 years ago
Hello All,
The main issue was "devmode" instead of "generate" in url_gen... If it could help somebody, here's the working transcript using a Requests Session to automatically carry the cookie around
>>> import requests
>>> import json
>>>
>>> s = requests.Session()
>>>
>>> ## Login
>>> headers = {"Content-Type": "application/x-www-form-urlencoded"}
>>> data = {"userId": MY_EMAIL, "userPassword": MY_PASSWORD}
>>> url = "https://ha101-1.overkiz.com/enduser-mobile-web/enduserAPI/login"
>>> r = s.post(url, headers=headers, data=data)
>>>
>>> r.status_code
200
>>>
>>> ## Generate a token
>>> url_gen = "https://ha101-1.overkiz.com/enduser-mobile-web/enduserAPI/config/MY_PIN/local/tokens/generate"
>>> headers_gen = {"Content-Type": "application/json"}
>>> r_gen = s.get(url_gen, headers=headers_gen)
>>>
>>> r_gen.status_code
200
>>> r_gen.text
'{"token":"XXXXXXXXXXXXXXXX"}'
>>>
>>> ## Activate your token
>>> url_act = "https://ha101-1.overkiz.com/enduser-mobile-web/enduserAPI/config/MY_PIN/local/tokens"
>>> headers_act = {"Content-Type": "application/json"}
>>> data_act = {"label": "My token", "token": r_gen.json()['token'], "scope": "devmode"}
>>> r_act = s.post(url_act, headers=headers_act, json=data_act)
>>>
>>> r_act.status_code
200
>>>
If you are not using a session, you have to pass the cookie
r_gen = requests.get(url_gen, headers=headers_gen, cookies=r.cookies)
Simon
Hello All,
I wanted to try this new local API in Python but I have issues getting a token (dev mode activated and visible in mDNS). I'm no token expert and any help is appreciated. Even if the token generation query is successful, it returns an empty structure:
Here's the full anonymized transcript:
Thank you, Simon