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

Issue with accessing API on Unifi Dream Machine Pro / Network Application 7.2.92 #172

Closed fsteinmann closed 1 year ago

fsteinmann commented 1 year ago

Authenticating against unifi fails miserably:

-----------LOGIN------------- Array ( [url] => https://unifi.abcd.org/api/auth/login [content_type] => text/html [http_code] => 404 [header_size] => 227 [request_size] => 195 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.002246 [namelookup_time] => 0.000117 [connect_time] => 0.000118 [pretransfer_time] => 0.000231 [size_upload] => 53 [size_download] => 1648 [speed_download] => 733748 [speed_upload] => 23597 [download_content_length] => -1 [upload_content_length] => 53 [starttransfer_time] => 0.000234 [redirect_time] => 0 [redirect_url] => [primary_ip] => 80.254.189.5 [certinfo] => Array ( )

[primary_port] => 443
[local_ip] => 192.168.2.10
[local_port] => 47544
[http_version] => 3
[protocol] => 2
[ssl_verifyresult] => 0
[scheme] => HTTPS
[appconnect_time_us] => 118
[connect_time_us] => 118
[namelookup_time_us] => 117
[pretransfer_time_us] => 231
[redirect_time_us] => 0
[starttransfer_time_us] => 234
[total_time_us] => 2246

)

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

malle-pietje commented 1 year ago

Which firmware/UniFi OS version is running on the UDM PRO?

malle-pietje commented 1 year ago

Please also update the first comment, it looks incomplete.

fsteinmann commented 1 year ago

UnifiOS is 1.2.22.

Strange... GitHub didn't display all of my comment above. Here's the rest:

config.php is as follows:

'<?php '$controlleruser = 'my-username'; // the user name for access to the UniFi Controller '$controllerpassword = 'my-secret-password'; // the password for access to the UniFi Controller '$controllerurl = 'https://unifi.abcd.org'; // full url to the UniFi Controller, eg. 'https://22.22.11.11:8443', for UniFi OS-based ' // controllers a port suffix isn't required, no trailing slashes should be added '$controllerversion = '7.2.92'; // the version of the Controller software, e.g. '4.6.6' (must be at least 4.0.0) ' 'Browsing the API using the API browser leads to "Error loading sites or no sites available". I guess Ubiquiti has changed the 'API (again)...

malle-pietje commented 1 year ago

I doubt there is an issue with the API. I’ve run tests against a UDR running these versions:

and that worked fine.

Do you have the full debug output from a login and fetching some data?

malle-pietje commented 1 year ago

One of our customers is running UniFi OS version 1.2.22 with 7.2.92 with our captive portal connected to it using the PHP API client and that also works without any issues.

malle-pietje commented 1 year ago

Which PHP version and php-curl version are you running?

malle-pietje commented 1 year ago

Also, are you using a local administrator account? This blog post on our website explains how to set up a local account for use with the API: https://artofwifi.net/2022/04/07/how-to-access-the-unifi-controller-by-wan-ip-or-hostname-on-a-udm-pro/

fsteinmann commented 1 year ago

I will have a thorough look tomorrow morning when I will have some more time. I have a local admin account, but with your comments I suspect it could be rather a set up issue with the web server rather the actual API. Will keep you posted. Thanks for looking into it this far!

fsteinmann commented 1 year ago

Found it - it's completely unrelated to the API. Since UDM is both router and controller, IP address obviously changed, and DNS resolution for the unifi URL pointed to the WAN interface - but I have port forwarding in place, so the request ended up on the wrong web server and thus resulted in the 404. Thanks anyway for looking into it!