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

HELP - All Unifi-API-client requests return ‘false’ ? #110

Closed nodecentral closed 3 years ago

nodecentral commented 3 years ago

Hi

I’m running the UniFi API Browser via Docker and I’m trying to get some of the example php scripts to work, but each one I run returns the word false so I can only assume my settings are wrong, but I’m not sure where. I’m hoping if I share what I’ve done someone can help ..

To access the Docker’s command line

docker exec -it unifi-host /bin/ash

Next, I copied over the config template file to edit and also some of the examples to try out.

cd UniFi-API-browser/vendor/art-of-wifi/unifi-api-client/examples/

cp list_connected_users.php /UniFi-API-browser
cp config.template.php /UniFi-API-browser
cp list_site_health.php /UniFi-API-browser

I then went on to edit the config.template.php file to access my controller. (Using a local account)

php
/**
�* Copyright (c) 2021, Art of WiFi
�*
�* This file is subject to the MIT license that is bundled with this package in the file LICENSE.md
�*/

/**
�* Controller configuration
�* ===============================
�* Copy this file to your working directory, rename it to config.php and update the section below with your UniFi
�* controller details and credentials
�*/
$controlleruser     = 'testinguser'; // the user name for access to the UniFi Controller
$controllerpassword = 'testingpass '; // the password for access to the UniFi Controller
$controllerurl      = 'https://192.168.22.207:443'; // 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  = '6.10.0'; // the version of the Controller software, e.g. '4.6.6' (must be at least 4.0.0)

/**
�* set to true (without quotes) to enable debug output to the browser and the PHP error log
�*/
$debug = false;

And then I saved it and also went on to rename it to the required config.php

mv config.template.php config.php

Next I tried to run the examples via the url, all of which returned false

192.168.22.227:8000/list_connected_users.php
192.168.22.227:8000/list_site_health.php

All ideas/suggestions welcome.

malle-pietje commented 3 years ago

Check the web server error logs.

malle-pietje commented 3 years ago

Also make sure you are actually including the class (correct path).

nodecentral commented 3 years ago

Check the web server error logs.

Hi @malle-pietje , where do I find the web server error logs ?

/UniFi-API-browser # ls
LICENSE.md  TODO.md  collections.php  composer.json  config      css          index.php  list_connected_users.php  login.php   templates
README.md   ajax     common.php       composer.lock  config.php  favicon.ico  js         list_site_health.php      logout.php  vendor
/UniFi-API-browser # 

And..

Also make sure you are actually including the class (correct path).

Sorry, where exactly do I need to do that ? All I’ve edited/created so far is the config.php - do I need to do something in each of the example scripts too ?

malle-pietje commented 3 years ago

The location of error logs will differ based on how the container is configured. Can't help you with that.

Please reads the docs on how to include: https://github.com/Art-of-WiFi/UniFi-API-client#installation

I can't help you further with basic PHP questions I'm afraid...

nodecentral commented 3 years ago

The location of error logs will differ based on how the container is configured. Can't help you with that.

Ok, as an FYI - I am just using the one linked to on your GitHub page - https://hub.docker.com/r/scyto/unifibrowser

Please reads the docs on how to include: https://github.com/Art-of-WiFi/UniFi-API-client#installation

I can't help you further with basic PHP questions I'm afraid...

I did, but I literally have no php knowledge or experience at all, and it’s not 100% clear to me what i should do - :-(

it says the following for example ..

include the file containing the class in your code

I looked up what class meant online and it said

Class is a programmer-defined data type, which includes local methods and local variables. Class is a collection of objects. Object has properties and behavior.

isn’t that the config.php?

It seems I’m obviously missing something obvious, but if I can ask one more thing - please can you confirm all I need to do is edit the example php files I want to use e.g list_connected_users.php

Really sorry for all the questions..

nodecentral commented 3 years ago

I’ve edited the list_connected_users.php file and updated the site_id value to home

The only other thing I can think to change within that file, is the line require_once 'path/to/src/Client.php'; but I can’t find a file called Client.php to point it to ?