Art-of-WiFi / UniFi-API-client

A PHP API client class to interact with Ubiquiti's UniFi Controller API
MIT License
1.09k stars 217 forks source link

No site-id on dashboard #176

Closed andreasloe closed 1 year ago

andreasloe commented 1 year ago

The commands like block or deblock do not work. I noticed that there is no site-id in dashboard anymore. Might this be the reason?

malle-pietje commented 1 year ago

Which dashboard are you referring to? To get the sites’ details you can best first call list_sites().

Please also share more details such as controller version and type (UniFi OS or not). These functions still work fine for us on the latest versions.

andreasloe commented 1 year ago

Malle-pietje: Thank you very much for sour support and sorry for providing so little information in the first post.

I am using a UniFi OS UCK G2 Plus 2.5.11. In order to block a client I am connecting to Unifi Network 7.2.94. The dashboard I am connecting to is available at https:///network/default/dashboard

Sicne I am not running php/python yet but rely on the GUI, I do not exactly know where I find the list_sties. I have one network 192.168.2.0/24 and three Wifi-networks. The AP use the newest firmware (6.2.35). Is there anything more I can do?

malle-pietje commented 1 year ago

Ok, no problem.

In your case the "site id" is "default" and that should work fine. If you wish to better understand the UniFi controller API and the data it exposes, I highly recommend installing the API Browser tool from here: https://github.com/Art-of-WiFi/UniFi-API-browser

andreasloe commented 1 year ago

Thanks, I tried the API browser before and got a 500 error despite having configured it using the GUI credentials: [Tue Sep 27 11:03 2022] [php7:error] [pid 23976] [client 192.168.2.XX:50387] PHP Fatal error: Uncaught Error: Call to undefined function curl_version() in /var/www/html/UniFi-API-browser/common.php:13\nStack trace:\n#0 /var/www/html/UniFi-API-browser/index.php(38): require_once()\n#1 {main}\n thrown in /var/www/html/UniFi-API-browser/common.php on line 13 And I have curl ist schon die neueste Version (7.64.0-4+deb10u3). PS The error remains after sudo apt-get install php-curl

andreasloe commented 1 year ago

PPS Got it. I needed several commands in case someone runs into the same problem: sudo apt-get update && sudo apt-get upgrade -y sudo apt-get install curl sudo apt-get install php-curl sudo service apache2 restart

andreasloe commented 1 year ago

And regarding the first question I now have an answer: Error loading sites or no sites available Hmm. I am back on square one. Although the log says 192.168.2.XX - - [27/Sep/2022:11:34:25 +0200] "POST /UniFi-API-browser/ajax/fetch_sites.php HTTP/1.1" 200 401 "http://raspfhem.fritz.box/UniFi-API-browser/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36" and * We are completely uploaded and fine

malle-pietje commented 1 year ago

What kind of credentials are you using? Does this local user have access to the Network Application for all sites?

andreasloe commented 1 year ago

I have two url's I am using: https://cloudkey.fritz.box/ [this is my local access] and https://unifi.ui.com/dashboard [this is the online access] and I have used all the credentials that were successful with those sites.

malle-pietje commented 1 year ago

Only direct access will work, server-to-server communication isn't supported through unifi.ui.com. Make sure to directly connect to the CloudKey using port 443.

andreasloe commented 1 year ago

OK, I checked that - to no avail. I believe that I have write access and I am using the local account. Strange.

Bildschirmfoto 2022-09-27 um 16 34 51
malle-pietje commented 1 year ago

I'm afraid I can't be of any further help but something is definitely wrong with the controller or the credentials.

malle-pietje commented 1 year ago

As a last resort you can enable debug mode in the API browser tool and share sanitized logs here.

andreasloe commented 1 year ago

Thanks anyway. I believe this has nothing to do with your software because I had the same problem with Perl. I will try this.

andreasloe commented 1 year ago

Here is the debug. I cannot see anything suspicious, unfortunately.

`* Connected to cloudkey.fritz.box (2003:cf:572f:e400:7683:XXXX:XXXX:XXXX) port 443 (#0)

malle-pietje commented 1 year ago

Other than the IPv6 address I don't see anything odd...

andreasloe commented 1 year ago

I am just reading this website „ There are times when having the site ID as default is not going to work for you or your clients. Primarily this becomes an issue when you are utilizing the UniFi API or any other script that engages the controller address via url“

malle-pietje commented 1 year ago

This only applies in cases where you have captive portal software connecting to multiple controllers and sites and you have more than 1 default site. Not applicable here.

andreasloe commented 1 year ago

Since I have (more or less) the same problem with a completely different software I suspect that Unifi is the culprit. I will now try to open a case in their forum. We can close the case here and I open it if I know more?

malle-pietje commented 1 year ago

Ok