2019-12-13 09:15:10 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHP API usage example
|
|
|
|
*
|
|
|
|
* contributed by: @gahujipo
|
2021-01-21 10:59:27 +01:00
|
|
|
* description: example to pull connected users and their details from the UniFi controller and output the results
|
|
|
|
* in JSON format
|
2019-12-13 09:15:10 +01:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* using the composer autoloader
|
|
|
|
*/
|
2021-01-21 10:59:27 +01:00
|
|
|
require_once 'vendor/autoload.php';
|
2019-12-13 09:15:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* include the config file (place your credentials etc there if not already present)
|
|
|
|
* see the config.template.php file for an example
|
|
|
|
*/
|
2021-01-21 10:59:27 +01:00
|
|
|
require_once 'config.php';
|
2019-12-13 09:15:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the short name of the site which you wish to query
|
|
|
|
*/
|
|
|
|
$site_id = '<enter your site id here>';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* initialize the UniFi API connection class and log in to the controller and pull the requested data
|
|
|
|
*/
|
|
|
|
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
|
|
|
|
$set_debug_mode = $unifi_connection->set_debug($debug);
|
|
|
|
$loginresults = $unifi_connection->login();
|
|
|
|
$clients_array = $unifi_connection->list_clients();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* output the results in JSON format
|
|
|
|
*/
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
echo json_encode($clients_array);
|