unifi-php-api/examples/change_super_mgmt.php
malle-pietje d66c3ddd75 API client class v1.1.81
- hotfix to address cookie issues in UniFi OS 3.2.7, reported by @tflatebo
- fixed minor typos
- minor code reformatting of the examples
- starting with this release, cookies are no longer supported when connecting to a UniFi OS-based controller
- added set_vlan_to_port.php example, contributed by @SamuelSchnelly, #203
- allow additional parameters in `create_wlan()`'s payload, contributed by @sgrodzicki, #191
2023-12-18 11:11:27 +01:00

73 lines
2.1 KiB
PHP
Executable File

<?php
/**
* PHP API usage example
*
* contributed by: Art of WiFi
* description: example basic PHP script to modify the super_mgmt settings for UniFi controller and output results
* in json format
*/
/**
* using the composer autoloader
*/
require_once 'vendor/autoload.php';
/**
* UniFi controller credentials and the site to use, in this case since we are modifying global settings you can select
* any site here that is available on the UniFi controller
*
* NOTE: in this case you need to enter Super Administrator account credentials in config.php
*/
require_once 'config.php';
$site_id = 'default';
$debug = false;
/**
* initialize the UniFi API connection class and log in to the controller and do our thing
*/
$unifi_connection = new UniFi_API\Client(
$controlleruser,
$controllerpassword,
$controllerurl,
$site_id,
$controllerversion
);
$set_debug_mode = $unifi_connection->set_debug($debug);
$loginresults = $unifi_connection->login();
$site_settings = $unifi_connection->list_settings();
$super_mgmt_settings = [];
$super_mgmt_settings_id = '';
if (!empty($site_settings)) {
foreach ($site_settings as $section) {
echo 'section key: ' . $section->key . PHP_EOL;
if ($section->key === 'super_mgmt') {
$super_mgmt_settings = $section;
$super_mgmt_settings_id = $section->_id;
}
}
}
/**
* modify the super_mgmt settings, in this example we only modify the Live Chat settings
* uncomment the required new value below:
*/
//$super_mgmt_settings->live_chat = 'disabled';
//$super_mgmt_settings->live_chat = 'enabled';
$super_mgmt_settings->live_chat = 'super-only';
/**
* we echo the parameters which we will be passing to the UniFi controller API
*/
echo $super_mgmt_settings_id . PHP_EOL;
echo json_encode($super_mgmt_settings, JSON_PRETTY_PRINT) . PHP_EOL . PHP_EOL;
$update_results = $unifi_connection->set_super_mgmt_settings_base($super_mgmt_settings_id, $super_mgmt_settings);
/**
* provide feedback in json format
*/
echo json_encode($update_results, JSON_PRETTY_PRINT);