Reply
Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218
Accepted Solution

UniFi API browser tool: updates and discussion

[ Edited ]

Here's a tool I created for my own use which I think will also be of use to others on this forum. The tool allows you to easily browse/explore a lot of the data (and I will be adding more over time) that is accessible through the UniFi Controller API. The tool currently supports UniFi Controller versions 4.X.X and 5.X.X. and requires a server running an apache2 web server with PHP and curl installed. Other web servers could also work but have not been tested.

 

You can easily clone/download the tool from GitHub here:
https://github.com/Art-of-WiFi/UniFi-API-browser


Once installed somewhere in the web server path on your system, and after you've edited and renamed the config template, you can access the tool with your browser. After selecting one of the sites from the "sites" drop-down menu, you can select a data collection you wish to browse through from the other drop-down category menus.

 

If you have multiple controllers, you can now configure the tool to support this as well.

 

Please do keep in mind this tool exposes A LOT OF the information available in your controller, so you should somehow restrict access to it! There are no security controls built into the tool...

 

Here's a screenshot of the interface:

api browser screenshot.PNG

I have installed a demo of the API browser tool which points to Ubiquiti's demo controller, demo.ubnt.com, here:
http://api-browser-demo.artofwifi.net/

 

I look forward to your feedback!

 

EDIT (30-1-2017): updated the supported versions and screenshot

EDIT (22-12-2017): added link to online demo

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.

Accepted Solutions
Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

[ Edited ]

I just published a minor update of the tool with some cosmetic improvements (I hope) and I have added the ability to switch between json and PHP array output formats.

 

Here's an excerpt from the updated README.md file which is hosted on github:

https://github.com/malle-pietje/Unifi-API-browser

 

Features
The Unifi API browser tool offers the following features:

  • browse through data collections exposed by the Unifi Controller API in an easy manner
  • switch between sites managed by the connected controller
  • switch between output formats (currently json and PHP array)
  • very easy setup with minimal dependencies
  • timing details of API queries can help "benchmark" your controller
  • useful tool when developing applications making use of the API
  • the API exposes more data than is visible through the Controller's web interface which can be useful for troubleshooting purposes

Data collections currently implemented

Users/clients

  • list online clients
  • list guests
  • list users
  • list user groups
  • stat all users
  • stat authorisations
  • stat sessions

Access points/devices

  • list devices (access points, USG routers and USW switches)
  • list wlan groups
  • list rogue access points
  • list_known_rogueaps
  • list devices tags (supported on controller version 5.5.19 and higher)

Stats

  • 5 minutes site stats (supported on controller version 5.5.* and higher)
  • hourly site stats
  • daily site stats
  • 5 minutes access point stats (supported on controller version 5.5.* and higher)
  • hourly access point stats
  • daily access point stats
  • all sites stats (supported on controller version 5.2.9 and higher)
  • health metrics
  • 5 minutes dashboard metrics (supported on controller version 5.5.* and higher)
  • dashboard metrics (supported on controller version 4.9.1.alpha and higher)
  • port forward stats

Configuration

  • list sites on this controller
  • list site settings
  • list admins for current site
  • sysinfo
  • self
  • wlan config
  • list VoIP extension
  • list network configuration
  • list port configurations
  • list port forwarding rules
  • list current channels
  • list DPI stats
  • dynamic DNS configuration
  • list Radius accounts (supported on controller version 5.5.19 and higher)

Messages

  • list events
  • list alarms
  • count alarms

Credits
The phpapi that comes bundled with this tool is based on the work done by the following developers:

Installation
Installation of this tool is quite straightforward. The easiest way to do this is by using git clone which also allows for easy updates.

  • open up a terminal window on your server and cd to the root folder of you web server (on Ubuntu this is /var/www/html) and execute the following command from your command prompt:
git clone https://github.com/malle-pietje/Unifi-API-browser.git
  • when git is done cloning, follow the steps below to configure the settings for access to your Unifi Controller's API.

Configuration

  • credentials for access to the Unifi Controller API need to be configured in the file named "config.template.php" which should be copied/renamed to "config.php" before using the Unifi API browser tool
  • please see the above file for further instructions
  • after following these steps, you can open the tool in your browser (assuming you installed it in the root folder of your web server as suggested above) by going to this url: http://serverip/Unifi-API-browser/

Requirements

  • a web server with PHP and cURL modules installed (tested on PHP Version 5.6.1 and cURL 7.42.1)
  • network access from this web server to the server and port on which the Unifi controller is running
  • clients using this tool should have internet access to be able to load the required css files because they are loaded from CDN's.

Security notice
The use of this tool is not secured in any way! Make sure to prevent unauthorised access to it, preventing exposure of details and credentials such as user names and passwords for access to the Unifi controller!

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.

View solution in original post

Regular Member
Posts: 423
Registered: ‎10-21-2014
Kudos: 119
Solutions: 16

Re: UniFi API browser tool: updates and discussion


slooffmaster wrote:

You're welcome. I'll be looking forward to your feedbackIcon Wink


@slooffmaster What can I say, the multicontroller option just works great.

I have configured for my 3 controllers and send you for a large beer throug your github donate.

 

:;-) Frank

View solution in original post


All Replies
Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

[ Edited ]

I just published a minor update of the tool with some cosmetic improvements (I hope) and I have added the ability to switch between json and PHP array output formats.

 

Here's an excerpt from the updated README.md file which is hosted on github:

https://github.com/malle-pietje/Unifi-API-browser

 

Features
The Unifi API browser tool offers the following features:

  • browse through data collections exposed by the Unifi Controller API in an easy manner
  • switch between sites managed by the connected controller
  • switch between output formats (currently json and PHP array)
  • very easy setup with minimal dependencies
  • timing details of API queries can help "benchmark" your controller
  • useful tool when developing applications making use of the API
  • the API exposes more data than is visible through the Controller's web interface which can be useful for troubleshooting purposes

Data collections currently implemented

Users/clients

  • list online clients
  • list guests
  • list users
  • list user groups
  • stat all users
  • stat authorisations
  • stat sessions

Access points/devices

  • list devices (access points, USG routers and USW switches)
  • list wlan groups
  • list rogue access points
  • list_known_rogueaps
  • list devices tags (supported on controller version 5.5.19 and higher)

Stats

  • 5 minutes site stats (supported on controller version 5.5.* and higher)
  • hourly site stats
  • daily site stats
  • 5 minutes access point stats (supported on controller version 5.5.* and higher)
  • hourly access point stats
  • daily access point stats
  • all sites stats (supported on controller version 5.2.9 and higher)
  • health metrics
  • 5 minutes dashboard metrics (supported on controller version 5.5.* and higher)
  • dashboard metrics (supported on controller version 4.9.1.alpha and higher)
  • port forward stats

Configuration

  • list sites on this controller
  • list site settings
  • list admins for current site
  • sysinfo
  • self
  • wlan config
  • list VoIP extension
  • list network configuration
  • list port configurations
  • list port forwarding rules
  • list current channels
  • list DPI stats
  • dynamic DNS configuration
  • list Radius accounts (supported on controller version 5.5.19 and higher)

Messages

  • list events
  • list alarms
  • count alarms

Credits
The phpapi that comes bundled with this tool is based on the work done by the following developers:

Installation
Installation of this tool is quite straightforward. The easiest way to do this is by using git clone which also allows for easy updates.

  • open up a terminal window on your server and cd to the root folder of you web server (on Ubuntu this is /var/www/html) and execute the following command from your command prompt:
git clone https://github.com/malle-pietje/Unifi-API-browser.git
  • when git is done cloning, follow the steps below to configure the settings for access to your Unifi Controller's API.

Configuration

  • credentials for access to the Unifi Controller API need to be configured in the file named "config.template.php" which should be copied/renamed to "config.php" before using the Unifi API browser tool
  • please see the above file for further instructions
  • after following these steps, you can open the tool in your browser (assuming you installed it in the root folder of your web server as suggested above) by going to this url: http://serverip/Unifi-API-browser/

Requirements

  • a web server with PHP and cURL modules installed (tested on PHP Version 5.6.1 and cURL 7.42.1)
  • network access from this web server to the server and port on which the Unifi controller is running
  • clients using this tool should have internet access to be able to load the required css files because they are loaded from CDN's.

Security notice
The use of this tool is not secured in any way! Make sure to prevent unauthorised access to it, preventing exposure of details and credentials such as user names and passwords for access to the Unifi controller!

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Highlighted
Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

[ Edited ]

Here are some updated screenshots after adding some small improvements to the menu structure and the ability to select a custom Bootswatch theme.

 

Showing the site's health metrics (json output) using the default Bootstrap theme:

screenshot4.JPG

Showing user stats (PHP array output) with one of the Bootswatch themes selected:

screenshot3.JPG

Hope you like it!Icon Biggrin

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Member
Posts: 253
Registered: ‎07-19-2015
Kudos: 8
Solutions: 2

Re: Unifi API browser tool: released

This is excellent! Well cool!

Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

Just submitted some small changes to the tool through github:

  • added "list wlan groups" function to phpapi
  • error handling for login() failures in phpapi
  • error handling when config.php is unreadable or does not exist
  • code clean up, comments in particular
Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

[ Edited ]

A couple of small changes have been committed to github:

  • added PHP var_export and var_dump output formats
  • added "stat sysinfo" data collection to the phpapi and tool interface
Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

[ Edited ]

Some updates to the tool were pushed to github today:

  • added "list sites" data collection
  • added info message when no site is selected
  • added info message when no data collection is selected
  • reduced retrieval of sites from the Unifi controller
  • removed the javascript based sites-menu population
Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

[ Edited ]

Just submitted some changes to the tool through github:

  • added output option: "json highlighted" (nice but slow for large collections...)
  • added an "About" modal to display some version info on PHP, cURL and the Unifi controller
  • clean up of progress bar code
  • minor code/comments clean up

here's a screenshot of the new "About" modal which shows the detected version of the Unifi Controller:

about modal.JPG

Enjoy!Icon Wink

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

[ Edited ]

I pushed a minor update to the tool to github today:

  • fixed a minor bug which caused unnecessary pulling of the sites list from the controller on each page refresh
  • cosmetic changes to the info row and timings progress bar (tooltips now display the actual timings)
  • minor code clean up

For those of you who used "git clone", a simple "git pull" is now all you need...

 

As always, enjoy! Icon Biggrin

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Emerging Member
Posts: 55
Registered: ‎03-14-2013
Kudos: 5

Re: Unifi API browser tool: released

[ Edited ]

doesn´t work, if i click on Select Site, no Sites lists. :-(

 

Controller: 4.7.5

Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

hmm, does the about modal show information? It's at the bottom of the "gear" menu.

If yes, what are the details there? If not, are there any clues in your apache error log?

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Emerging Member
Posts: 55
Registered: ‎03-14-2013
Kudos: 5

Re: Unifi API browser tool: released

[ Edited ]

the modal information:

 

Controller:
user admin
version detected
 

PHP version 5.4.45-0+deb7u2
cURL version 7.26.0
OS Linux 3.2.0-4-amd64
 
 
 
 
Error.log:
[Sun Dec 20 12:41:06 2015] [error] [client 192.168.249.3] PHP Notice:  Trying to get property of non-object in /var/www/Unifi-API-browser/index.php on line 138, referer: http://192.168.1.166/Unifi-API-browser/?action=stat_sysinfo
[Sun Dec 20 12:41:08 2015] [error] [client 192.168.249.3] File does not exist: /var/www/favicon.ico, referer: http://192.168.1.166/Unifi-API-browser/index.php
[Sun Dec 20 12:41:17 2015] [error] [client 192.168.249.3] PHP Notice:  Undefined offset: 0 in /var/www/Unifi-API-browser/index.php on line 138, referer: http://192.168.1.166/Unifi-API-browser/?action=stat_sysinfo
[Sun Dec 20 12:41:17 2015] [error] [client 192.168.249.3] PHP Notice:  Trying to get property of non-object in /var/www/Unifi-API-browser/index.php on line 138, referer: http://192.168.1.166/Unifi-API-browser/?action=stat_sysinfo
[Sun Dec 20 12:41:18 2015] [error] [client 192.168.249.3] File does not exist: /var/www/favicon.ico, referer: http://192.168.1.166/Unifi-API-browser/index.php
[Sun Dec 20 12:41:37 2015] [error] [client 192.168.249.3] PHP Notice:  Undefined offset: 0 in /var/www/Unifi-API-browser/index.php on line 138, referer: http://192.168.1.166/Unifi-API-browser/?action=stat_sysinfo
[Sun Dec 20 12:41:37 2015] [error] [client 192.168.249.3] PHP Notice:  Trying to get property of non-object in /var/www/Unifi-API-browser/index.php on line 138, referer: http://192.168.1.166/Unifi-API-browser/?action=stat_sysinfo
[Sun Dec 20 14:10:44 2015] [error] [client 192.168.249.3] PHP Notice:  Undefined offset: 0 in /var/www/Unifi-API-browser/index.php on line 138
[Sun Dec 20 14:10:44 2015] [error] [client 192.168.249.3] PHP Notice:  Trying to get property of non-object in /var/www/Unifi-API-browser/index.php on line 138
[Sun Dec 20 14:10:44 2015] [error] [client 192.168.249.3] File does not exist: /var/www/favicon.ico, referer: http://192.168.1.166/Unifi-API-browser/
 
Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

Thanks for the input. I'm suspecting this is PHP/cURL version related: the errors in your apache log are thrown at the point where the cURL functions are called for the first time. I will get back, probably with a request to increase the error reporting level in PHP.

 

Would you be able to update your PHP and cURL versions?

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

Another thing you can do to provide more info is setting the $debug var in the class.unifi.php file to true.

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
New Member
Posts: 44
Registered: ‎11-17-2013
Solutions: 1

Re: Unifi API browser tool: released

[ Edited ]
i cannot run it also, no sites button.
Controller 4.7.6
 
Controller:
user: admin
version detected
PHP version 5.5.9-1ubuntu4.14
cURL version 7.35.0
OS Linux 3.16.0-30-generic
 
trying to get property of non-object in /var/www/html/Unifi-API-browser/index.php on line 149, referer: http://192.168.1.245/html/Unifi-API-browser/index.php
PHP Notice:  Undefined offset: 0 in /var/www/html/Unifi-API-browser/index.php on line 149,
 

Emerging Member
Posts: 55
Registered: ‎03-14-2013
Kudos: 5

Re: Unifi API browser tool: released

new Versions, same problem:

 

Controller:
user admin
version detected
 

PHP version 5.6.14-0+deb8u1
cURL version 7.38.0
OS Linux 3.16.0-4-amd64
 
if i set debug=true, i get an "login" screen:

 

New Member
Posts: 44
Registered: ‎11-17-2013
Solutions: 1

Re: Unifi API browser tool: released

seems that if i use IE11 and chrome it's ok, just FF 40.0.2 cannot see button site name.

 

i upgraded php to 5.6.16-2+deb.sury.org~trusty+1

Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

Can you check whether you filled in a controller version number (eg 4.6.6) in your config.php file? Although it is not actively used, you do need to give a value of at least 4.0.0.

 

If this is the root cause I will have to clarify this in the comments in the config file.

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
New Member
Posts: 44
Registered: ‎11-17-2013
Solutions: 1

Re: Unifi API browser tool: released

yes, i have filled that value 4.7.6

Veteran Member
Posts: 4,663
Registered: ‎06-13-2015
Kudos: 1263
Solutions: 218

Re: Unifi API browser tool: released

that's weird.. I just used FF 43.0.1 to test and it worked fine.

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Reply