Reply
Member
Posts: 108
Registered: ‎02-22-2015
Kudos: 8

Re: Unifi API browser tool: updates and discussion

Hi @slooffmaster

 

Thanks so much for the code, I created a new php file, updated the site ID to mine "Home" and called it unifihealth.php and then placed into the same folder as th API Browser.

 

When I run it, it just returned the following.

 

[]
Veteran Member
Posts: 4,650
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: updates and discussion

[ Edited ]

parkerc wrote:

Hi @slooffmaster

 

Thanks so much for the code, I created a new php file, updated the site ID to mine "Home" and called it unifihealth.php and then placed into the same folder as th API Browser.

 

When I run it, it just returned the following.

 

[]

@parkerc Good start. You will however need to use the short site id, which you can either find in the url when managing the site or by using the API browser. There in the sites collection look for "name", not "desc".

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.
Details on our UniFi Device Search tool can be found here.
Member
Posts: 108
Registered: ‎02-22-2015
Kudos: 8

Re: Unifi API browser tool: updates and discussion

Success ! Short Name looks to be 'default' which i assume is standard..

 

Ok now on to surf for how to extract some of the data from that JSON and present it - wish me luck Man Happy

Veteran Member
Posts: 4,650
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: updates and discussion

[ Edited ]

parkerc wrote:

Success ! Short Name looks to be 'default' which i assume is standard..

 

Ok now on to surf for how to extract some of the data from that JSON and present it - wish me luck Man Happy


Good to hear it's working! To manipulate the data before sending it to client will require some understanding of how to work with multidimensional, associative arrays with PHP. Not an easy topic...Icon Wink Hopefully you can do some things (manipulate, filter, etc.) on the client side?

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.
Details on our UniFi Device Search tool can be found here.
Member
Posts: 108
Registered: ‎02-22-2015
Kudos: 8

Re: Unifi API browser tool: updates and discussion

[ Edited ]

Hi @slooffmaster

 

I spent the weekend surfing for ideas I could repurpose for this, but have not had much success (and not having the skills it's not been an easy thing to do) - this script looks promising but does not return anything, i think it is looking for something called a ?callback?

 

i don't want to take up your thread with this, if you are able to help/direct etc, here's the Status Board post I did before reaching out to you - that might be a better place to try to progress this > http://community.ubnt.com/t5/UniFi-Wireless/Panic-s-Status-Board-UniFi-Widgets-Anyone/m-p/1634390#M1...

 

Here is the original script.

 

<script type="text/javascript">
			function getStatus() {
				$.getJSON('https://status.github.com/api/status.json?callback=?', function(data) {
					var status = data.status;
					$('#status').addClass(status);
					$('#status').html(status);
				});
			}
			var int=self.setInterval(function(){getStatus()},900000);
		</script>

 

and here was what I've tried to change it to, to get it work with my local hosting of your great API browser (as it also has a 'status' value in that JSON )

 

<script type="text/javascript">

			function getStatus() {
				$.getJSON('http://192.168.1.111/Unifi-API-browser/unifihealth.php', function(data) {
					var status = data.status;
					$('#status').addClass(status);
					$('#status').html(status);
				});
			}

			var int=self.setInterval(function(){getStatus()},900000);

		</script>

 

Veteran Member
Posts: 4,650
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: updates and discussion


parkerc wrote:

Hi @slooffmaster

 

I spent the weekend surfing for ideas I could repurpose for this, but have not had much success (and not having the skills it's not been an easy thing to do) - this script looks promising but does not return anything, i think it is looking for something called a ?callback?

 

i don't want to take up your thread with this, if you are able to help/direct etc, here's the Status Board post I did before reaching out to you - that might be a better place to try to progress this > http://community.ubnt.com/t5/UniFi-Wireless/Panic-s-Status-Board-UniFi-Widgets-Anyone/m-p/1634390#M1...

 

Here is the original script.

 

<script type="text/javascript">
			function getStatus() {
				$.getJSON('https://status.github.com/api/status.json?callback=?', function(data) {
					var status = data.status;
					$('#status').addClass(status);
					$('#status').html(status);
				});
			}
			var int=self.setInterval(function(){getStatus()},900000);
		</script>

 

and here was what I've tried to change it to, to get it work with my local hosting of your great API browser (as it also has a 'status' value in that JSON )

 

<script type="text/javascript">

			function getStatus() {
				$.getJSON('http://192.168.1.111/Unifi-API-browser/unifihealth.php', function(data) {
					var status = data.status;
					$('#status').addClass(status);
					$('#status').html(status);
				});
			}

			var int=self.setInterval(function(){getStatus()},900000);

		</script>

 


@parkerc In your json output example, "data" is an array containing multiple objects, and "status" is a key in each of the objects. You will need to decide which objects you want display keys/values for. If you are looking for a library to faciliate such array functions, I can highly recommend lodash. In this specific case you will probably be best off using it's find function.

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.
Details on our UniFi Device Search tool can be found here.
Established Member
Posts: 1,226
Registered: ‎07-17-2013
Kudos: 821
Solutions: 83
Contributions: 1

Re: UniFi API browser tool: updates and discussion

Hi @slooffmaster, it's me again Man Happy

 

I'm trying your API, specially the 'list_guests' function, and in my testings it seems to return only the authorized users, by voucher or external API calls or even manually. On a plain 'guest network' enabled network but with no user authentication, list_guests always returns nothing.

 

Is this the expected behavior ? Can you confirm this ? It seems i'll have to use 'list_clients' instead on this scenario, where i want guest network enabled only for client isolation, not for any kind of authentication.

 

Tests done on 4.8.20 controller.

 

list_guest output:

[root@iweb admin]# php teste2.php
array(0) {
}

list_clients output:

[root@iweb admin]# php teste2.php | head -2
array(12) {
  [0]=>

 

Solutti Tecnologia Ltda - Goiânia/Goiás/Brazil
www.solutti.com.br / www.wifiquefunciona.com.br
Ubiquiti Enterprise Wireless Admin (UEWA) certified
did my answer helped you ? if yes, i would love your kudos on it Man Happy
Veteran Member
Posts: 4,650
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: UniFi API browser tool: updates and discussion


leonardogyn wrote:

Hi @slooffmaster, it's me again Man Happy

 

I'm trying your API, specially the 'list_guests' function, and in my testings it seems to return only the authorized users, by voucher or external API calls or even manually. On a plain 'guest network' enabled network but with no user authentication, list_guests always returns nothing.

 

Is this the expected behavior ? Can you confirm this ? It seems i'll have to use 'list_clients' instead on this scenario, where i want guest network enabled only for client isolation, not for any kind of authentication.

 

Tests done on 4.8.20 controller.

 

list_guest output:

[root@iweb admin]# php teste2.php
array(0) {
}

list_clients output:

[root@iweb admin]# php teste2.php | head -2
array(12) {
  [0]=>

 


Hi again @leonardogyn :-) From my experience this is not expected behaviour. I have one site that uses password auth and I there can see all auth-ed guests with the "authorized_by" attribute set to "password". This is on a controller that went from 4.6.x to 4.9.x.

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.
Details on our UniFi Device Search tool can be found here.
Veteran Member
Posts: 4,650
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: UniFi API browser tool: updates and discussion

[ Edited ]

Cross-posting here for forum members who are only following this thread:

I just committed a new version, 1.0.6, of the PHP API client to Github, the API browser remains unchanged. Here are the details:

added `stat_sta_sessions_latest()` function/method
fixed bug in `create_voucher()` function/method (wasn't returning the newly created voucher codes)
modified `set_wlansettings()` function/method to make `name` an optional parameter
where applicable, the functions/methods now return TRUE/FALSE (in capital letters)
cleanup of comments

Any feedback is welcome.

 

As always, enjoy! Icon Smile

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.
Details on our UniFi Device Search tool can be found here.
New Member
Posts: 3
Registered: ‎07-15-2016

Re: UniFi API browser tool: updates and discussion

Having a bit of an issue.

 

I have it installed and it appears to be working, ie I can select a site, but once I select a drop-down ie device list. I reverts back to selecting a site.

 

Any ideas?

 

The onlything I can think of is it has something to do with the version of the controller I am using/ having listed in the config.php. I'm running 5.0.7, which I put in the config, but in the about section it says version "undectected". thoughts?

 

If this isn't a good place to put this, please direct me to where I should.

Veteran Member
Posts: 4,650
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: UniFi API browser tool: updates and discussion


tragicdog wrote:

Having a bit of an issue.

 

I have it installed and it appears to be working, ie I can select a site, but once I select a drop-down ie device list. I reverts back to selecting a site.

 

Any ideas?

 

The onlything I can think of is it has something to do with the version of the controller I am using/ having listed in the config.php. I'm running 5.0.7, which I put in the config, but in the about section it says version "undectected". thoughts?

 

If this isn't a good place to put this, please direct me to where I should.


Hmmm, I suspect this is a server cookie issue. Could you share your PHP, operating system and cURL versions from the "About" modal? It would also help if you could enable debug mode in your config file and share the debug from when you select one of the dropdowns?

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.
Details on our UniFi Device Search tool can be found here.
Veteran Member
Posts: 4,650
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: UniFi API browser tool: updates and discussion

The controller version in the config file isn't important at the moment, it's there in case there are differences between the APIs in future controller releases. Undetected in the About modal indicates the API browser tool was unable to collect the version number from the controller itself, this value does not come from 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.
Details on our UniFi Device Search tool can be found here.
New Member
Posts: 3
Registered: ‎07-15-2016

Re: UniFi API browser tool: updates and discussion

from the About Module:

PHP Version: 5.4.16

PHP Memory_Limit 128M

PHP Memory Used 0.54M

CURL Version 7.29.0

OS is Centos 7

 

 DEBUG info:

-----LOGIN-------------------
Array
(
[url] => https://unifi.XXXX.org:443/api/login
[content_type] => application/json;charset=UTF-8
[http_code] => 200
[header_size] => 332
[request_size] => 231
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.960671
[namelookup_time] => 0.004389
[connect_time] => 0.00485
[pretransfer_time] => 0.236776
[size_upload] => 44
[size_download] => 41
[speed_download] => 42
[speed_upload] => 45
[download_content_length] => 41
[upload_content_length] => 44
[starttransfer_time] => 0.960573
[redirect_time] => 0
[certinfo] => Array
(
)

[primary_ip] => 192.168.XXX.XXX
[primary_port] => 443
[local_ip] => 192.168.XXX.XXX
[local_port] => 35922
[redirect_url] =>
)

-----RESPONSE----------------
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-FRAME-OPTIONS: SAMEORIGIN
Set-Cookie: unifises=mDnY07ty2mJMYtTMUBIpsX9EgykX8aPa; Path=/; Secure; HttpOnly
Set-Cookie: csrf_token=mDnY07ty2mJMYtTMUBIpsX9EgykX8aPa; Path=/; Secure
Content-Type: application/json;charset=UTF-8
Content-Length: 41
Date: Mon, 19 Sep 2016 17:21:04 GMT

{ "data" : [ ] , "meta" : { "rc" : "ok"}}
-----------------------------
-----cURL INFO---------------
Array
(
[url] => https://unifi.XXXX.org:443/api/self/sites
[content_type] => application/json;charset=UTF-8
[http_code] => 200
[header_size] => 266
[request_size] => 168
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.041029
[namelookup_time] => 0.004237
[connect_time] => 0.004598
[pretransfer_time] => 0.037303
[size_upload] => 0
[size_download] => 735
[speed_download] => 17914
[speed_upload] => 0
[download_content_length] => 735
[upload_content_length] => 0
[starttransfer_time] => 0.040978
[redirect_time] => 0
[certinfo] => Array
(
)

[primary_ip] => 192.168.XXX.XXX
[primary_port] => 443
[local_ip] => 192.168.XXX.XXX
[local_port] => 35924
[redirect_url] =>
)

-----URL & PAYLOAD-----------
https://unifi.XXXX.org:443/api/self/sites

-----RESPONSE----------------
{ "data" : [ { "_id" : "534c4ee5e4b02121c98895d1" , "attr_hidden_id" : "default" , "attr_no_delete" : true , "desc" : "Default" , "name" : "default" , "role" : "admin"} , { "_id" : "534c4f23e4b02121c98895d9" , "desc" : "Forest Home MCC" , "name" : "foho" , "role" : "admin"} , { "_id" : "53fe27e1e4b0b1f569ebd765" , "desc" : "FH Guest Events" , "name" : "fhevents" , "role" : "admin"} , { "_id" : "5758547ae4b0749099d7c6ea" , "desc" : "Forest Home Ojai" , "name" : "2815d3so" , "role" : "admin"} , { "_id" : "539601dfe4b003aa977b68eb" , "desc" : "FH Testing" , "name" : "fhtest" , "role" : "admin"} , { "_id" : "57b20216e4b0be79067afdcf" , "desc" : "Offsite Office" , "name" : "0fhc8n8j" , "role" : "admin"}] , "meta" : { "rc" : "ok"}}
-----------------------------
-----cURL INFO---------------
Array
(
[url] => https://unifi.XXXX.org:443/logout
[content_type] =>
[http_code] => 302
[header_size] => 314
[request_size] => 160
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.05202
[namelookup_time] => 0.012361
[connect_time] => 0.012708
[pretransfer_time] => 0.045644
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.049797
[redirect_time] => 0
[certinfo] => Array
(
)

[primary_ip] => 192.168.XXX.XXX
[primary_port] => 443
[local_ip] => 192.168.XXX.XXX
[local_port] => 35926
[redirect_url] => https://unifi.XXXX.org/manage
)

-----URL & PAYLOAD-----------
https://unifi.XXXX.org:443/logout

-----RESPONSE----------------

-----------------------------

Veteran Member
Posts: 4,650
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: UniFi API browser tool: updates and discussion

@tragicdog Thx. From looking at the debug output it looks as if basic auth and the self/sites API endpoint are working fine. I'm suspecting some other piece of logic on the index.php page is not working well. What do your PHP/apache error log and browser console say?

 

Could well be caused by your PHP version.

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.
Details on our UniFi Device Search tool can be found here.
Veteran Member
Posts: 4,650
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: UniFi API browser tool: updates and discussion

I just committed version 1.0.3 of the API Browser tool and version 1.0.7 of the PHP API client to Github. Here are the details:

added ability to optionally configure multiple controllers in `config.php`
general code and comments cleanup
added `stat_sites()` function to the API client class (supported on UniFi controllers 5.2.9 and higher)

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

 

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.
Details on our UniFi Device Search tool can be found here.
Veteran Member
Posts: 4,650
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: UniFi API browser tool: updates and discussion

@Frankedinven the multiple controller option is based on your request/suggestion. Took a bit longer to implement than I had hoped... Icon Wink Please let me know how this option works for you. Also I would be interested to get feedback whether the instructions in the config template file are clear enough.

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.
Details on our UniFi Device Search tool can be found here.
Regular Member
Posts: 422
Registered: ‎10-21-2014
Kudos: 119
Solutions: 16

Re: UniFi API browser tool: updates and discussion

 


slooffmaster wrote:

@Frankedinven the multiple controller option is based on your request/suggestion. Took a bit longer to implement than I had hoped... Icon Wink Please let me know how this option works for you. Also I would be interested to get feedback whether the instructions in the config template file are clear enough.


@slooffmaster, Thanks for this, much appreciated. I will try it out as soon as possible, which will be mid next week when I am back at the office :-)

Veteran Member
Posts: 4,650
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: UniFi API browser tool: updates and discussion

You're welcome. I'll be looking forward to your feedbackIcon 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.
Details on our UniFi Device Search tool can be found here.
New Member
Posts: 4
Registered: ‎08-18-2016
Kudos: 22

Re: UniFi API browser tool: updates and discussion

 
Highlighted
Regular Member
Posts: 422
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

Reply