API client class v1.1.41

changed create_wlan function/method to not include passphrase in payload when security = "open" and passphrase = null
fixed indentations in several places
added custom_api_request() function/method which allows a programmer to issue custom API requests that may not yet be supported by this client (to be used with care!)
added example to demonstrate use of custom_api_request()
removed repetitive code and optimized exec_curl() when creating the final payload, resulting in 10-20% performance increase and slightly lower memory consumption by PHP
This commit is contained in:
malle-pietje 2019-04-29 17:35:09 +02:00
parent 55867197e3
commit 09db47affd
5 changed files with 418 additions and 364 deletions

View File

@ -1,6 +1,6 @@
## UniFi Controller API client class
A PHP class which provides access to Ubiquiti's [**UniFi SDN Controller API**](https://unifi-sdn.ui.com/), versions 4.X.X and 5.X.X of the UniFi SDN Controller software are supported (version 5.10.5 has been confirmed to work). It's a standalone version of the class which is used in our API browser tool which can be found [here](https://github.com/Art-of-WiFi/UniFi-API-browser).
A PHP class which provides access to Ubiquiti's [**UniFi SDN Controller API**](https://unifi-sdn.ui.com/), versions 4.X.X and 5.X.X of the UniFi SDN Controller software are supported (version 5.10.19 has been confirmed to work). It's a standalone version of the class which is used in our API browser tool which can be found [here](https://github.com/Art-of-WiFi/UniFi-API-browser).
This class can be installed manually or using composer/[packagist](https://packagist.org/packages/art-of-wifi/unifi-api-client) for easy inclusion in your projects.
@ -92,9 +92,9 @@ Please refer to the `examples/` directory for some more detailed examples which
2. The last optional parameter that is passed to the constructor in the above example (`true`), enables validation of the controller's SSL certificate which is otherwise **disabled** by default. It is highly recommended to enable this feature in production environments where you have a valid SSL cert installed on the UniFi Controller, and which is associated with the FQDN of the server as used in the `controller_url` parameter. This option was added with API client version 1.1.16.
## Methods and functions supported
## Functions/methods supported
The class currently supports the following functions/methods to get/post/put/delete data through the UniFi Controller API. Please refer to the source code for more details on the functions/methods and their respective parameters.
The class currently supports the following functions/methods to GET/POST/PUT/DELETE data through the UniFi Controller API. Please refer to the source code for more details on the functions/methods and their respective parameters.
- login()
- logout()
@ -112,6 +112,7 @@ The class currently supports the following functions/methods to get/post/put/del
- create_user()
- create_voucher()
- create_wlan()
- custom_api_request()
- delete_device()
- delete_firewallgroup()
- delete_network()
@ -126,6 +127,7 @@ The class currently supports the following functions/methods to get/post/put/del
- extend_guest_validity()
- forget_sta() (supported on controller version 5.9.X and higher)
- invite_admin()
- assign_existing_admin()
- revoke_admin()
- led_override()
- list_admins()
@ -249,10 +251,14 @@ If you would like to contribute code (improvements), please open an issue and in
## Credits
This class is based on the initial work done by the following developers:
This class is based on the initial work by the following developers:
- domwo: http://community.ubnt.com/t5/UniFi-Wireless/little-php-class-for-unifi-api/m-p/603051
- fbagnol: https://github.com/fbagnol/class.unifi.php
- and the API as published by Ubiquiti: https://dl.ubnt.com/unifi/5.9.29/unifi_sh_api
and the API as published by Ubiquiti:
- https://dl.ubnt.com/unifi/5.10.19/unifi_sh_api
## Important Disclaimer

View File

@ -19,6 +19,7 @@ require_once('config.php');
/**
* site id and MAC address of AP to query
* https://github.com/Art-of-WiFi/UniFi-API-client#important-notes
*/
$site_id = '<enter your site id here>';
$ap_mac = '<enter MAC address of Access Point to check>';

View File

@ -11,6 +11,7 @@ require_once('config.php');
/**
* site id of the AP to update
* https://github.com/Art-of-WiFi/UniFi-API-client#important-notes
*/
$site_id = '<enter your site id here>';

View File

@ -0,0 +1,47 @@
<?php
/**
* PHP API usage example
*
* contributed by: Art of WiFi
* description: example basic PHP script to execute a custom API request using the
* custom_api_request() function/method
*/
/**
* using the composer autoloader
*/
require_once('vendor/autoload.php');
/**
* include the config file (place your credentials etc. there if not already present)
* see the config.template.php file for an example
*/
require_once('config.php');
/**
* The site to authorize the device with
* https://github.com/Art-of-WiFi/UniFi-API-client#important-notes
*/
$site_id = '<enter your site id here>';
/**
* parameters
*/
$url = '/api/s/' . $site_id . '/stat/fwupdate/latest-version';
$request_type = 'GET';
$payload = null;
$return = 'array';
/**
* 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();
$results = $unifi_connection->custom_api_request($url, $request_type, $payload, $return);
/**
* provide feedback in JSON format or as PHP Object
*/
echo json_encode($results, JSON_PRETTY_PRINT);
//print_r($results);

File diff suppressed because it is too large Load Diff