Closed bluehj777 closed 3 years ago
That isn’t an intended use case for this tool. You can however create a utility for this yourself using the PHP API client. Direct curl access to the API is quite tricky because of the authentication mechanism that is used by the UniFi controller API.
It looks like there is a solution: In the terminal: curl 'http://192.168.1.1/ajax/fetch_collection.php' \ -H 'Cookie: PHPSESSID=gt5cbcbsd8dookf6rq58aqtic1' \ --data-raw 'selected_collection_method=list_devices&selected_collection_label=+list+devices+&selected_collection_key=&selected_collection_params=%5B%5D&selected_collection_group=Devices&selected_site_id=abcdef&selected_output_method=json'
PHPSESSID->you can find in the apache server /var/lib/php/sessions/sess_gt5cbcbsd8dookf6rq58aqtic1 selected_site_id->which is the short site "name" (usually 8 characters long)
Finally, just make sure that the sess_gt5cbcbsd8dookf6rq58aqtic1 file is always there, you can now type the CURL command directly into any other machine and output the JSON results you need
In fact, this need of mine is for rest or command Line integration can be used in home assistant to monitor Unifi devices
Nice approach but it’s more of a hack IMHO. But hey, if it works for you that’s fine👍
Thank you for this project anyway :-)
hello This code is successfully installed and running.But my intention is to enter one URL directly into the browser, and then the browser can return JSON data results. someting like this.Example: http://192.168.1.1/ajax/fetch_collection.php?selected_collection_method=stat_sysinfo&selected_collection_label=sysinfo&selected_collection_group=Configuration&selected_site_id=abcdefg&selected_output_method=json
Or is it possible to use the curl command to show me the JSON results directly in the terminal environment
thanks