2019-04-29 17:35:09 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHP API usage example
|
|
|
|
*
|
|
|
|
* contributed by: Art of WiFi
|
2021-01-21 10:59:27 +01:00
|
|
|
* description: example basic PHP script to execute a custom API request using the
|
|
|
|
* custom_api_request() function/method
|
2019-04-29 17:35:09 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* using the composer autoloader
|
|
|
|
*/
|
2021-01-21 10:59:27 +01:00
|
|
|
require_once 'vendor/autoload.php';
|
2019-04-29 17:35:09 +02: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-04-29 17:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2021-01-21 10:59:27 +01:00
|
|
|
$url = '/api/s/' . $site_id . '/stat/fwupdate/latest-version';
|
|
|
|
$request_method = 'GET';
|
|
|
|
$payload = null;
|
|
|
|
$return = 'array';
|
2019-04-29 17:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
2021-01-21 10:59:27 +01:00
|
|
|
$results = $unifi_connection->custom_api_request($url, $request_method, $payload, $return);
|
2019-04-29 17:35:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* provide feedback in JSON format or as PHP Object
|
|
|
|
*/
|
|
|
|
echo json_encode($results, JSON_PRETTY_PRINT);
|
|
|
|
//print_r($results);
|