This object is in archive! 
API
Answered
bonjour . quelqu'un pourrait m expliquer comment fonctionne l API ? par exemple , comment allumer une lampe ( quelle uuid et quelle commande ) .Merci.
You can't vote. Please authorize!
No connection
Real-time notifications may not work


The same question
Bonjour. Personne utilise l API ?
Bonjour. Personne utilise l API ?
Hi
to use API it is required to make login session which will keep your credentials. After that it is possible to control any device by changing either its attribute or ability value.
Below you may find one python example where you can check Login and ability/ attribute setting:
import requests import json import hashlib #from py_session import py_session import z_settings USERNAME = z_settings.USERNAME PASSWORD = z_settings.PASSWORD # Set session - one for the all requests session_login = requests.session() # Step 1 - init URL_init = z_settings.URL_MAIN + '/user/init' res = session_login.get(URL_init).json() if not res['success']: exit() # Step 2 - login URL_login = z_settings.URL_MAIN + "/user/login" pas2sign = hashlib.sha1(PASSWORD.encode("utf-8")).hexdigest() token = hashlib.sha1((res['nonce'] + pas2sign).encode("utf-8")).hexdigest() head = {'Authorization': 'token {}'.format(token)} data = {'username': USERNAME} res_login = session_login.get(URL_login, params={'username': USERNAME, 'token': token}) # Step 3 - set Zipato server URL_serial = z_settings.URL_MAIN + '/box/select?serial=' + z_settings.ZIPATO_SERIAL res_serial = session_login.get(URL_serial).json() server_name = res_serial['name'] server_localIP = res_serial['localIp'] server_remoteIP = res_serial['remoteIp'] # Step 4 - get user devices URL_devices = z_settings.URL_MAIN + "/devices" res_devices = session_login.get(URL_devices).json() user_device = "" for z_device in res_devices: if (z_device['name'] == z_settings.DEVICE_NAME): user_device = z_device['name'] user_device_uuid = z_device['uuid'] break # Step 4 - get device ability URL_abilities = z_settings.URL_MAIN + "/devices/" + user_device_uuid + "/abilities" res_abilities = session_login.get(URL_abilities).json() for z_ability in res_abilities: if (z_ability['name'] == z_settings.ABILITY_NAME): user_ability = z_ability['name'] user_ability_uuid = z_ability['uuid'] if z_ability['fields'][z_settings.STATE_ATTRIBUTE]: user_attribute_uuid = z_ability['fields'][z_settings.STATE_ATTRIBUTE] break if not user_attribute_uuid: exit() # Step 5 - get attribute value URL_attribute = z_settings.URL_MAIN + "/attributes/" + user_attribute_uuid + "/value" res_attribute = session_login.get(URL_attribute).json() attribute_value = res_attribute['value'] attribute_timestamp = res_attribute['timestamp'] # Switch state attribute_value_new = "false" if attribute_value == "false": attribute_value_new = "true" # Step 6 - set attribute value p_value = {'value': attribute_value_new} res_attribute_put = session_login.put(URL_attribute, data=json.dumps(p_value), headers=z_settings.HEADERS)Hi
to use API it is required to make login session which will keep your credentials. After that it is possible to control any device by changing either its attribute or ability value.
Below you may find one python example where you can check Login and ability/ attribute setting:
import requests import json import hashlib #from py_session import py_session import z_settings USERNAME = z_settings.USERNAME PASSWORD = z_settings.PASSWORD # Set session - one for the all requests session_login = requests.session() # Step 1 - init URL_init = z_settings.URL_MAIN + '/user/init' res = session_login.get(URL_init).json() if not res['success']: exit() # Step 2 - login URL_login = z_settings.URL_MAIN + "/user/login" pas2sign = hashlib.sha1(PASSWORD.encode("utf-8")).hexdigest() token = hashlib.sha1((res['nonce'] + pas2sign).encode("utf-8")).hexdigest() head = {'Authorization': 'token {}'.format(token)} data = {'username': USERNAME} res_login = session_login.get(URL_login, params={'username': USERNAME, 'token': token}) # Step 3 - set Zipato server URL_serial = z_settings.URL_MAIN + '/box/select?serial=' + z_settings.ZIPATO_SERIAL res_serial = session_login.get(URL_serial).json() server_name = res_serial['name'] server_localIP = res_serial['localIp'] server_remoteIP = res_serial['remoteIp'] # Step 4 - get user devices URL_devices = z_settings.URL_MAIN + "/devices" res_devices = session_login.get(URL_devices).json() user_device = "" for z_device in res_devices: if (z_device['name'] == z_settings.DEVICE_NAME): user_device = z_device['name'] user_device_uuid = z_device['uuid'] break # Step 4 - get device ability URL_abilities = z_settings.URL_MAIN + "/devices/" + user_device_uuid + "/abilities" res_abilities = session_login.get(URL_abilities).json() for z_ability in res_abilities: if (z_ability['name'] == z_settings.ABILITY_NAME): user_ability = z_ability['name'] user_ability_uuid = z_ability['uuid'] if z_ability['fields'][z_settings.STATE_ATTRIBUTE]: user_attribute_uuid = z_ability['fields'][z_settings.STATE_ATTRIBUTE] break if not user_attribute_uuid: exit() # Step 5 - get attribute value URL_attribute = z_settings.URL_MAIN + "/attributes/" + user_attribute_uuid + "/value" res_attribute = session_login.get(URL_attribute).json() attribute_value = res_attribute['value'] attribute_timestamp = res_attribute['timestamp'] # Switch state attribute_value_new = "false" if attribute_value == "false": attribute_value_new = "true" # Step 6 - set attribute value p_value = {'value': attribute_value_new} res_attribute_put = session_login.put(URL_attribute, data=json.dumps(p_value), headers=z_settings.HEADERS)It's getting too complicated for me. I would just like to know how to find the URL of the different devices to be able to control them with another system. Thank you.
It's getting too complicated for me. I would just like to know how to find the URL of the different devices to be able to control them with another system. Thank you.
Replies have been locked on this page!