Art-of-WiFi / UniFi-API-browser

Tool to browse data exposed by Ubiquiti's UniFi Controller API
MIT License
1.1k stars 150 forks source link

Is there any way to display the results directly? #90

Closed bluehj777 closed 3 years ago

bluehj777 commented 3 years ago

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

malle-pietje commented 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.

bluehj777 commented 3 years ago

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

malle-pietje commented 3 years ago

Nice approach but it’s more of a hack IMHO. But hey, if it works for you that’s fine👍

bluehj777 commented 3 years ago

Thank you for this project anyway :-)