### Start Rolling Upgrade Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Starts a rolling firmware upgrade. Accepts an array of device types to include. ```php public function start_rolling_upgrade(array $payload = ['uap', 'usw', 'ugw', 'uxg']): bool ``` -------------------------------- ### Install UniFi API Client v1.x.x Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/README.md To install version 1.x.x of the API client, specify the version constraint in your composer.json file. ```javascript { "require": { "art-of-wifi/unifi-api-client": "^1.1" } } ``` -------------------------------- ### Install UniFi API Client via Composer Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/INDEX.md Use Composer to add the UniFi API Client library to your project. This command fetches and installs the package and its dependencies. ```bash composer require art-of-wifi/unifi-api-client ``` -------------------------------- ### Start Rolling Upgrade Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Starts a rolling firmware upgrade. Accepts an array of device types to include. ```APIDOC ## Start Rolling Upgrade ### Description Starts a rolling firmware upgrade. ### Method Not specified (assumed to be a client method call) ### Endpoint Not specified ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **payload** (array): Array of device types to include in rolling upgrade ### Returns - bool - true upon success ``` -------------------------------- ### Install OS Console Update Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Install an available OS console update on a UniFi OS device. Returns true upon success. Throws NotAUnifiOsConsoleException if not a UniFi OS console. ```php public function update_os_console(): bool { } ``` -------------------------------- ### Execute PHP Script from CLI Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/examples/README.md Demonstrates how to run a PHP script from the command line interface. Ensure the 'php-cli' module is installed. ```sh $ php list_site_health.php ``` -------------------------------- ### List Firmware Information Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Fetches firmware information for devices. The 'type' parameter can be set to 'available' or 'installed'. ```php public function list_firmware(string $type = 'available') ``` -------------------------------- ### Session Persistence Example Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Demonstrates how to achieve session persistence by saving and restoring cookies. This avoids the need for re-login on subsequent requests. ```php // First session: login and save cookies $client = new UniFi_API\Client('admin', 'password', $url, 'default'); $client->login(); $cookies = $client->get_cookies(); // Store $cookies in database, file, or session // Later: restore cookies, avoid re-login $client = new UniFi_API\Client('admin', 'password', $url, 'default'); $client->set_cookies($cookies); $clients = $client->list_clients(); // No login() needed ``` -------------------------------- ### update_os_console() Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Installs an available OS console update for UniFi OS consoles. ```APIDOC ## update_os_console() ### Description Install OS console update (UniFi OS only). ### Method Not specified (likely a client method call) ### Response #### Success Response - **bool** - `true` upon success ### Throws - `NotAUnifiOsConsoleException` - if not a UniFi OS console ``` -------------------------------- ### list_firmware Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Fetch firmware information. Can retrieve available or installed firmware details based on the specified type. ```APIDOC ## list_firmware(string $type = 'available') ### Description Fetch firmware information. Can retrieve available or installed firmware details based on the specified type. ### Method Not specified (likely a client method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **type** (string) - Optional - Firmware type: `'available'`, `'installed'`. Defaults to `'available'`. ### Request Example ```php $client->list_firmware('installed'); ``` ### Response #### Success Response - **array** - firmware objects #### Response Example ```json [ { "version": "4.3.21", "url": "http://..." } ] ``` ``` -------------------------------- ### List Site Settings Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Retrieves all configuration settings for the current Unifi site. This method provides a comprehensive view of the site's setup. ```php public function list_settings(): array ``` -------------------------------- ### Initialize Client Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/README.md Demonstrates how to initialize the Unifi API Client, either with standard credentials or using an API key for UniFi OS. ```APIDOC ## Initialize Client ### Description Initializes the Unifi API Client with controller credentials or an API key. ### Method POST (Implicit for login) ### Endpoint N/A (Client-side instantiation) ### Parameters #### Constructor Options - `$user` (string) - Username for authentication. - `$password` (string) - Password for authentication. - `$baseurl` (string) - The base URL of the UniFi controller (e.g., 'https://192.168.1.1:8443'). - `$site` (string) - The site identifier (default is 'default'). - `$api_key` (string) - API key for UniFi OS authentication. ### Request Example ```php // Standard controller $client = new UniFi_API\Client('admin', 'password', 'https://192.168.1.1:8443', 'default'); $client->login(); // Or UniFi OS with API key $client = new UniFi_API\Client('', '', 'https://unifi:443', 'default'); $client->set_api_key('api-key-here'); ``` ``` -------------------------------- ### Get Cookie / Get Cookies Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Retrieves the current session cookie(s) used for authentication. ```APIDOC ## Get Cookie / Get Cookies ### Description Retrieves the current session cookie(s). ### Method ```php public function get_cookie(): string public function get_cookies(): string ``` ### Parameters None ### Returns - **string**: Current cookie value. ``` -------------------------------- ### Get Site Manager Console ID Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Gets the current Site Manager console ID. ```APIDOC ## Get Site Manager Console ID ### Description Gets the current Site Manager console ID. ### Method Not applicable (PHP method) ### Endpoint Not applicable (PHP method) ### Parameters None ### Request Example Not applicable (PHP method) ### Response #### Success Response - **string**: Console ID, empty string if not set ``` -------------------------------- ### Switch Between Sites Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Demonstrates how to switch between different UniFi sites using the client. Initialize the client with a default site, log in, and then use set_site() to change the active site for subsequent operations. ```php $client = new UniFi_API\Client('admin', 'password', $url, 'site1'); $client->login(); // Get stats for site1 $stats1 = $client->list_dashboard(); // Switch to site2 $client->set_site('site2'); $stats2 = $client->list_dashboard(); // Switch back to site1 $client->set_site('site1'); $stats3 = $client->list_dashboard(); ``` -------------------------------- ### Fetch All Settings Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Retrieves a comprehensive list of all system settings. ```php public function list_settings() ``` -------------------------------- ### get_curl_method() Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Gets the currently set HTTP method used for API requests. This is typically 'GET' or 'POST'. ```APIDOC ## get_curl_method() ### Description Gets the currently set HTTP method used for API requests. This is typically 'GET' or 'POST'. ### Method GET ### Endpoint /get_curl_method ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **method** (string) - The current HTTP method (e.g., 'GET', 'POST'). #### Response Example ```json { "method": "POST" } ``` ``` -------------------------------- ### Initialize UniFi API Client Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/README.md Instantiate the client for standard controller access or UniFi OS with an API key. Ensure the autoloader is included. ```php require_once 'vendor/autoload.php'; // Standard controller $client = new UniFi_API\Client('admin', 'password', 'https://192.168.1.1:8443', 'default'); $client->login(); // Or UniFi OS with API key $client = new UniFi_API\Client('', '', 'https://unifi:443', 'default'); $client->set_api_key('api-key-here'); ``` -------------------------------- ### Instantiate Client with Constructor Parameters Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/README.md Use this constructor to create a new instance of the UniFi API Client. It requires user credentials and optionally accepts base URL, site, version, SSL verification status, and cookie name. ```php new UniFi_API\Client( string $user, string $password, string $baseurl = 'https://127.0.0.1:8443', ?string $site = 'default', ?string $version = '8.0.28', bool $ssl_verify = false, string $unificookie_name = 'unificookie' ) ``` -------------------------------- ### Return Type Examples Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/README.md Illustrates the various return types from API methods, including arrays, objects, booleans, and custom JSON strings. Helps in understanding how to process API responses. ```php // Methods returning arrays $clients = $client->list_clients(); // array|false $stats = $client->stat_daily_site(); // array|false // Methods returning objects $client = $client->list_clients('aa:bb:cc:dd:ee:ff'); // object|false // Methods returning booleans $success = $client->login(); // bool $blocked = $client->block_sta('...'); // bool // Methods with custom returns $response = $client->custom_api_request(..., 'json'); // string (JSON) ``` -------------------------------- ### PHP Exception Handling for UniFi API Client Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/README.md This example demonstrates how to catch specific exceptions thrown by the UniFi API Client, such as network errors, invalid configurations, and login failures. It is recommended to use specific exception catching for more granular error reporting in production environments. ```php login(); $results = $unifi_connection->list_alarms(); // returns a PHP array containing alarm objects } catch (CurlExtensionNotLoadedException $e) { echo 'CurlExtensionNotLoadedException: ' . $e->getMessage(). PHP_EOL; } catch (InvalidBaseUrlException $e) { echo 'InvalidBaseUrlException: ' . $e->getMessage(). PHP_EOL; } catch (InvalidSiteNameException $e) { echo 'InvalidSiteNameException: ' . $e->getMessage(). PHP_EOL; } catch (JsonDecodeException $e) { echo 'JsonDecodeException: ' . $e->getMessage(). PHP_EOL; } catch (LoginRequiredException $e) { echo 'LoginRequiredException: ' . $e->getMessage(). PHP_EOL; } catch (ConsoleOfflineException $e) { echo 'ConsoleOfflineException: ' . $e->getMessage(). PHP_EOL; } catch (CurlGeneralErrorException $e) { echo 'CurlGeneralErrorException: ' . $e->getMessage(). PHP_EOL; } catch (CurlTimeoutException $e) { echo 'CurlTimeoutException: ' . $e->getMessage(). PHP_EOL; } catch (LoginFailedException $e) { echo 'LoginFailedException: ' . $e->getMessage(). PHP_EOL; } catch (Exception $e) { /** catch any other Exceptions that might be thrown */ echo 'General Exception: ' . $e->getMessage(). PHP_EOL; } ``` -------------------------------- ### Get Current HTTP Method Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Retrieves the HTTP method currently configured for API requests. Typically 'GET' or 'POST'. ```php public function get_curl_method(): string ``` -------------------------------- ### Turn On All Site LEDs Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Turns on all LEDs for devices within the current site. Returns true on success. ```php public function site_ledson(): bool ``` -------------------------------- ### Create Site Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Creates a new site with a given description or name. ```php public function create_site(string $description): bool ``` -------------------------------- ### List System Events Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Lists system events with options for history duration, starting index, and limit. Defaults to 720 hours of history. ```php public function list_events(int $historyhours = 720, int $start = 0, int $limit = 3000): array ``` -------------------------------- ### Get Cookie Creation Timestamp Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Get the Unix timestamp when the current session cookies were created. Useful for checking cookie age and determining if re-login is necessary. ```php $timestamp = $client->get_cookies_created_at(); $age = time() - $timestamp; if ($age > 3600) { // Cookies are over 1 hour old, consider re-login } ``` -------------------------------- ### Get Site Statistics Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Fetches statistical data for the sites. ```php public function stat_sites() ``` -------------------------------- ### Fetch Extension Configurations Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Retrieves all configured extension settings for the Unifi system. ```php public function list_extension() ``` -------------------------------- ### Get Tag Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Retrieves information about a specific tag using its ID. ```APIDOC ## Get Tag ### Description Retrieves information about a specific tag. ### Method Not specified (assumed to be a client method call) ### Endpoint Not specified ### Parameters #### Path Parameters Not applicable #### Query Parameters Not applicable #### Request Body Not applicable ### Request Example Not specified ### Response #### Success Response - **tag_info** (array) - Array containing tag information #### Response Example Not specified ``` -------------------------------- ### Fetch Basic Device Information Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Get basic information for all network devices, including Access Points, switches, and gateways. This method requires no parameters. ```php public function list_devices_basic() ``` -------------------------------- ### Get Current Site Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Retrieve the identifier of the currently active site. ```php $current_site = $client->get_site(); ``` -------------------------------- ### UniFi OS Configuration with API Key Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Configure the client for UniFi OS using an API key. Username and password fields are left empty. No explicit login() call is needed. ```php require_once 'vendor/autoload.php'; $client = new UniFi_API\Client( '', '', 'https://unifi:443', 'default' ); $client->set_api_key('your-api-key-here'); // No login() needed $clients = $client->list_clients(); ``` -------------------------------- ### Get All Session Cookies Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Retrieves all current session cookies as a single string. ```php public function get_cookies(): string ``` -------------------------------- ### Constructor Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Creates a new instance of the UniFi API client, allowing configuration of connection parameters like user credentials, controller URL, site, and SSL verification. ```APIDOC ## Constructor ### Description Creates a new instance of the UniFi API client. ### Method `__construct` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **user** (string) - Required - Username for the UniFi controller - **password** (string) - Required - Password for the UniFi controller - **baseurl** (string) - Optional - Base URL of the UniFi controller (must include 'https://' prefix, port suffix like :8443 required for non-UniFi OS controllers). Defaults to 'https://127.0.0.1:8443'. - **site** (string|null) - Optional - Short site name to access. Defaults to 'default'. - **version** (string|null) - Optional - Controller version number. Defaults to '8.0.28'. - **ssl_verify** (bool) - Optional - Whether to validate SSL certificate of the UniFi controller. Defaults to false. - **unificookie_name** (string) - Optional - Name of the cookie to use. Defaults to 'unificookie'. ### Throws - `CurlExtensionNotLoadedException` - `InvalidBaseUrlException` - `InvalidSiteNameException` ``` -------------------------------- ### Get Current Session Cookie Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Retrieves the value of the current session cookie. ```php public function get_cookie(): string ``` -------------------------------- ### list_settings Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Fetch all settings. ```APIDOC ## list_settings() ### Description Fetch all settings. ### Returns - `array` — settings objects; `false` on error ``` -------------------------------- ### Create Site Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Creates a new site with a specified description. ```APIDOC ## Create Site ### Description Creates a new site. ### Method POST (assumed, based on function name and typical REST patterns) ### Endpoint /api/v1/sites (assumed) ### Parameters #### Request Body - **description** (string) - Required - Description/name of the new site ### Response #### Success Response (200) - **bool** - true upon success ``` -------------------------------- ### Get Class Version Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Retrieves the version of the UniFi API client class. ```APIDOC ## Get Class Version ### Description Retrieves the version of this API client class. ### Method #### `get_class_version()` ##### Description Retrieves the version of the UniFi API client class. ##### Returns - `string`: The class version (e.g., '2.2.0'). ``` -------------------------------- ### site_ledson() Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Turns on all site LEDs. ```APIDOC ## site_ledson() ### Description Turn on all site LEDs. ### Method Not specified (likely POST or PUT) ### Endpoint Not specified ### Parameters None ### Response #### Success Response (200) - `bool` — `true` upon success ### Error Handling - Returns `false` on error ``` -------------------------------- ### Get/Set cURL Method Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Gets or sets the HTTP method used for cURL requests. ```APIDOC ## Get/Set cURL Method ### Description Gets or sets the cURL HTTP method. ### Method ```php public function get_curl_method(): string public function set_curl_method(string $curl_method): string ``` ### Parameters (set_curl_method) #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **curl_method** (string): Required (for set_curl_method) - HTTP method ('GET', 'POST', 'PUT', 'DELETE', 'PATCH'). ### Returns - **string**: Current cURL method. ### Throws - `InvalidCurlMethodException` (for set_curl_method) ``` -------------------------------- ### Force Device Provisioning Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Initiates a forced provisioning cycle for a specified device by its MAC address. Returns true upon success. ```php public function force_provision($mac): bool ``` -------------------------------- ### Get Single Session Cookie Value Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Retrieve the value of the single session cookie. ```php $cookie = $client->get_cookie(); ``` -------------------------------- ### Client Configuration Methods Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/method-index.md Methods for configuring client device settings. ```APIDOC ## Client Configuration ### Description Methods for configuring client device settings. ### Methods - `create_user(string, string, string, string, string, string, string)`: Create local user. Returns `bool`. - `set_sta_note(string, string)`: Set device note. Returns `bool`. - `set_sta_name(string, string)`: Set device name. Returns `bool`. - `set_usergroup(string, string)`: Assign to user group. Returns `bool`. - `edit_client_fixedip(string, bool, ?, ?)`: Configure static IP. Returns `array|bool`. - `edit_client_name(string, string)`: Change device name. Returns `array|bool`. ``` -------------------------------- ### Get HTTP Version Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Retrieve the current HTTP version setting used for requests. ```php $version = $client->get_curl_http_version(); ``` -------------------------------- ### Instantiate UniFi API Client Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Creates a new instance of the UniFi API client with specified connection parameters. Ensure SSL verification is handled appropriately for your environment. ```php public function __construct( string $user, string $password, string $baseurl = 'https://127.0.0.1:8443', ?string $site = 'default', ?string $version = '8.0.28', bool $ssl_verify = false, string $unificookie_name = 'unificookie' ) ``` -------------------------------- ### Get Connection Timeout Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Retrieves the current cURL connection timeout setting in seconds. ```php $timeout = $client->get_connection_timeout(); echo "Connection timeout: {$timeout}s"; ``` -------------------------------- ### Spectrum Scan Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Starts a spectrum scan on an access point using its MAC address. ```php public function spectrum_scan(string $mac): bool ``` -------------------------------- ### List Firmware Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Lists firmware versions, either 'available' or 'cached'. Defaults to 'available'. ```php public function list_firmware(string $type = 'available'): array ``` -------------------------------- ### Get Current API Key Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Retrieves the currently configured API key from the client instance. ```php $key = $client->get_api_key(); ``` -------------------------------- ### List Firmware Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Lists firmware versions. Defaults to 'available' firmware. ```APIDOC ## List Firmware ### Description Lists firmware versions. ### Method Not specified (assumed to be a client method call) ### Endpoint Not specified ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **type** (string): Type of firmware list: 'available', 'cached' (default: 'available') ### Returns - array - Array of firmware objects ``` -------------------------------- ### List All Sites Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Fetches all sites configured on the controller. ```php public function list_sites() ``` -------------------------------- ### Get UniFi Cookie Name Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Retrieves the specific name of the cookie used by the UniFi controller. ```APIDOC ## Get UniFi Cookie Name ### Description Retrieves the UniFi cookie name. ### Method ```php public function get_unificookie_name(): string ``` ### Parameters None ### Returns - **string**: Cookie name. ``` -------------------------------- ### Get Cookie Creation Time Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Retrieves the timestamp indicating when the current session cookies were created. ```APIDOC ## Get Cookie Creation Time ### Description Retrieves the timestamp when the cookies were created. ### Method ```php public function get_cookies_created_at(): int ``` ### Parameters None ### Returns - **int**: Timestamp of cookie creation. ``` -------------------------------- ### Connect via Site Manager Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Creates a new client instance preconfigured for Site Manager proxy mode, routing requests through Ubiquiti's cloud proxy. Requires console ID, API key, and optionally a site name. ```php public static function connect_via_site_manager(string $console_id, string $api_key, string $site = 'default'): static ``` ```php $client = UniFi_API\Client::connect_via_site_manager( '245A4CA234150000000005F23204000000000638FE970000000061156371:48913759', 'site-manager-api-key', 'default' ); $results = $client->list_alarms(); // No login() needed ``` -------------------------------- ### Get Session Cookie Name Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Retrieve the name of the session cookie. The default name is 'unificookie'. ```php $name = $client->get_unificookie_name(); ``` -------------------------------- ### Get Default HTTP Method Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Retrieve the current default HTTP method configured for the client. ```php $method = $client->get_curl_method(); ``` -------------------------------- ### Get cURL Request Timeout Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Retrieves the current cURL request timeout setting in seconds. ```php $timeout = $client->get_curl_request_timeout(); ``` -------------------------------- ### list_extension Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Fetch extension configurations. ```APIDOC ## list_extension() ### Description Fetch extension configurations. ### Returns - `array` — extension objects; `false` on error ``` -------------------------------- ### Create User Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Creates a new user with a specified name and MAC address. Optional hostname and note can be provided. ```php public function create_user( string $name, string $mac, ?string $hostname = null, ?string $note = null ): bool ``` -------------------------------- ### list_events() Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Fetch system events. Allows filtering by historical hours, start offset, and limit. ```APIDOC ## list_events() ### Description Fetch system events. ### Method GET (Assumed based on typical RESTful patterns for listing resources, actual method not specified in source) ### Endpoint `/events` (Assumed structure, actual endpoint not specified in source) ### Parameters #### Query Parameters - **historyhours** (int) - Optional - Default: `720` - Historical period in hours (720 = 30 days) - **start** (int) - Optional - Default: `0` - Start offset - **limit** (int) - Optional - Default: `3000` - Maximum events to return ### Returns - **array** - event objects; `false` on error ``` -------------------------------- ### List Events Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Lists system events, with options for history duration, starting index, and limit. ```APIDOC ## List Events ### Description Lists system events. ### Method Not specified (assumed to be a client method call) ### Endpoint Not specified ### Parameters #### Path Parameters Not applicable #### Query Parameters - **historyhours** (int) - Optional - Hours of history to retrieve (default: 720 = 30 days) - **start** (int) - Optional - Starting index for pagination (default: 0) - **limit** (int) - Optional - Maximum number of events to return (default: 3000) #### Request Body Not applicable ### Request Example Not specified ### Response #### Success Response - **events** (array) - Array of event objects #### Response Example Not specified ``` -------------------------------- ### Create New Site Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Creates a new site on the controller. Requires a site description or name. ```php public function create_site(string $description) ``` -------------------------------- ### Get/Set UniFi OS Flag Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Gets or sets a flag indicating if the controller is running on UniFi OS. ```APIDOC ## Get/Set UniFi OS Flag ### Description Gets or sets the UniFi OS flag. ### Method ```php public function get_is_unifi_os(): bool public function set_is_unifi_os(bool $is_unifi_os): bool ``` ### Parameters (set_is_unifi_os) #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **is_unifi_os** (bool): Required (for set_is_unifi_os) - true if controller is UniFi OS-based. ### Returns - **bool**: Current UniFi OS flag status. ``` -------------------------------- ### Switch Site and Enable Debugging Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/README.md Dynamically switch the active site for API requests and enable debug logging to aid in troubleshooting. Useful for managing multi-site deployments. ```php // Site switching $client->set_site('another_site'); // Debugging $client->set_debug(true); ``` -------------------------------- ### Standard Controller Configuration Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Configure the client using a username and password for a standard UniFi controller. Requires a login call after instantiation. ```php require_once 'vendor/autoload.php'; $client = new UniFi_API\Client( 'admin', 'password', 'https://192.168.1.1:8443', 'jl3z2shm' ); $client->login(); $clients = $client->list_clients(); ``` -------------------------------- ### Get/Set Site Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Gets the current site context or sets the site context for subsequent API calls. ```APIDOC ## Get/Set Site ### Description Gets or sets the current site. ### Method ```php public function get_site(): string public function set_site(string $site): string ``` ### Parameters (set_site) #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **site** (string): Required (for set_site) - Short site name to switch to. ### Returns - **string**: Current site name. ``` -------------------------------- ### List Available Backups Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Lists all available backups. Returns an array of backup objects. ```php public function list_backups(): array ``` -------------------------------- ### Get Session Cookies Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Retrieve the current session cookies. These can be stored for later use to persist the session. ```php $cookies = $client->get_cookies(); // Store in database, cache, or session ``` -------------------------------- ### Create User Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Creates a new user account with a specified name, MAC address, and optional hostname and note. ```APIDOC ## Create User ### Description Creates a new user. ### Method POST (Assumed, based on 'create' action) ### Endpoint /api/s/{site_id}/up/user ### Parameters #### Path Parameters - `site_id` (string) - Required - The ID of the site to create the user in. #### Request Body - `name` (string) - Required - Name of the new user - `mac` (string) - Required - MAC address of the user - `hostname` (string|null) - Optional - Hostname of the user - `note` (string|null) - Optional - Note about the user ### Response #### Success Response (200) - `bool` - true upon success ``` -------------------------------- ### Get SSL Host Verification Level Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Retrieve the current SSL host verification level setting. ```php $level = $client->get_curl_ssl_verify_host(); ``` -------------------------------- ### Spectrum Scan Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Starts a spectrum scan on an access point. Requires the AP's MAC address. ```APIDOC ## Spectrum Scan ### Description Starts a spectrum scan on an access point. ### Method Not specified (assumed to be a client method call) ### Endpoint Not specified ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **mac** (string): MAC address of the AP ### Returns - bool - true upon success ``` -------------------------------- ### Set Guest Login Settings Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Configures basic guest login portal settings including redirection and expiration. Requires specific parameters for portal behavior and access control. ```php public function set_guestlogin_settings( bool $portal_enabled, bool $portal_customized, bool $redirect_enabled, string $redirect_url, string $x_password, int $expire_number, int $expire_unit, string $section_id ): bool ``` -------------------------------- ### Client Constructor Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/README.md Initializes a new instance of the UniFi API Client. This constructor allows for various configuration options including user credentials, base URL, site, API version, SSL verification, and cookie name. ```APIDOC ## `new UniFi_API\Client(...)` ### Description Initializes a new instance of the UniFi API Client. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Signature ```php new UniFi_API\Client( string $user, string $password, string $baseurl = 'https://127.0.0.1:8443', ?string $site = 'default', ?string $version = '8.0.28', bool $ssl_verify = false, string $unificookie_name = 'unificookie' ) ``` ### Parameters - **user** (string) - The username for authentication. - **password** (string) - The password for authentication. - **baseurl** (string) - Optional. The base URL of the UniFi controller. Defaults to 'https://127.0.0.1:8443'. - **site** (string|null) - Optional. The site name to connect to. Defaults to 'default'. - **version** (string|null) - Optional. The API version to use. Defaults to '8.0.28'. - **ssl_verify** (bool) - Optional. Whether to verify SSL certificates. Defaults to `false`. - **unificookie_name** (string) - Optional. The name of the unifi cookie. Defaults to 'unificookie'. ``` -------------------------------- ### advanced_adopt_device() Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Adopts device(s) with advanced options, including model, serial, IP, and provisioning. ```APIDOC ## advanced_adopt_device($macs, string $model = '', string $serial = '', string $ip = '', bool $force_provision = false) ### Description Adopt device(s) with advanced options. ### Method Not specified (likely POST) ### Endpoint Not specified ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **macs** (string | array) - Required - Single MAC or array of MACs - **model** (string) - Optional - Device model for validation - **serial** (string) - Optional - Device serial for validation - **ip** (string) - Optional - Device IP address - **force_provision** (bool) - Optional - Force immediate provisioning ### Response #### Success Response (200) - `bool` — `true` upon success ### Error Handling - Returns `false` on error ``` -------------------------------- ### Get Current Active Site Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Retrieves the name of the currently active site. Useful for confirming the current context. ```php public function get_site(): string ``` ```php $current_site = $client->get_site(); ``` -------------------------------- ### list_models() Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Fetches the supported device models from the Unifi system. Returns an object containing the models or null if not supported. ```APIDOC ## list_models() ### Description Fetch supported device models. ### Returns `object` — models object; `null` if not supported ``` -------------------------------- ### Get API Client Class Version Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Retrieves the current version string of the Unifi API client class. ```php public function get_class_version(): string ``` ```php echo $client->get_class_version(); // "2.2.0" ``` -------------------------------- ### Get UniFi Cookie Name Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Retrieves the specific name of the cookie used by UniFi controllers for session management. ```php public function get_unificookie_name(): string ``` -------------------------------- ### list_networkconf() Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Fetches network configurations. ```APIDOC ## list_networkconf() ### Description Fetch network configurations. ### Method GET ### Endpoint /api/s/{site_id}/rest/networkconf ### Parameters #### Path Parameters - **site_id** (string) - Required - The ID of the site. #### Query Parameters - **network_id** (string) - Optional - Filter by network ID. ### Response #### Success Response (200) - **data** (array) - network configuration objects #### Response Example ```json { "data": [ { "_id": "5f9b3b3b3b3b3b3b3b3b3b3b", "name": "Default Network", "vlan_id": 1 } ] } ``` ``` -------------------------------- ### Get Alarm Count Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Retrieves the count of system alarms. Can filter by archived or active alarms, or return the total count. ```php public function count_alarms(?bool $archived = null) ``` -------------------------------- ### list_clients Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Fetches all client devices or a specific device by its MAC address. Returns comprehensive device data including connection statistics and configuration. Returns an array of client objects or false on error. ```APIDOC ## list_clients() ### Description Fetches all client devices or a specific device by MAC address. Returns comprehensive device data including connection statistics and configuration. ### Method ```php public function list_clients(?string $mac = null) ``` ### Parameters #### Path Parameters - **mac** (string | null) - Optional - Single MAC address to filter results; if null, returns all clients ### Returns - **array** - array of client objects; `false` on error ### Throws - `MacAddressInvalidException` — if MAC format is invalid - `LoginRequiredException` — if not authenticated ### Example ```php // Get all clients $all_clients = $client->list_clients(); // Get specific client $device = $client->list_clients('aa:bb:cc:dd:ee:ff'); ``` ``` -------------------------------- ### Get Last Results Raw Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Retrieves the raw results from the last API call. Can be returned as an array or a JSON string. ```APIDOC ## Get Last Results Raw ### Description Retrieves the last raw results from the API. ### Method ```php public function get_last_results_raw(bool $return_json = false): mixed ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **return_json** (bool): Optional - Whether to return results as JSON string (default: false). ### Returns - **mixed**: Last raw results (array or JSON string). ``` -------------------------------- ### Configuration Options Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/README.md Details the various options available for configuring the Unifi API Client, including constructor parameters and common setter methods for timeouts, SSL verification, and debugging. ```APIDOC ## Configuration Options ### Description Provides details on how to configure the Unifi API Client, covering both initial setup via the constructor and runtime adjustments using setter methods. ### Method N/A (Configuration) ### Endpoint N/A ### Parameters #### Constructor Options - `$user`, `$password` — Credentials for authentication. - `$baseurl` — Controller URL (e.g., 'https://host:port'). - `$site` — Site identifier. - `$version` — Controller version (optional). - `$ssl_verify` — Boolean to enable/disable SSL verification. - `$unificookie_name` — Session cookie name (optional). #### Common Configuration Methods - `set_connection_timeout(int $seconds)`: Sets the TCP connection timeout. - `set_curl_request_timeout(int $seconds)`: Sets the total request timeout. - `set_curl_ssl_verify_peer(bool $verify)`: Enables/disables peer certificate verification. - `set_curl_ssl_verify_host(int $verify)`: Sets the host verification level for SSL. - `set_site(string $site)`: Switches the client to a different site. - `set_debug(bool $debug)`: Enables/disables debug output. ### Request Example ```php // Timeouts $client->set_connection_timeout(20); // TCP connection timeout $client->set_curl_request_timeout(60); // Full request timeout // SSL/TLS $client->set_curl_ssl_verify_peer(true); // Verify peer certificate $client->set_curl_ssl_verify_host(2); // Verify hostname // Site switching $client->set_site('another_site'); // Debugging $client->set_debug(true); ``` ``` -------------------------------- ### Get Last Error Message Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Retrieves the last error message that occurred during an API interaction. This is helpful for diagnosing issues. ```APIDOC ## Get Last Error Message ### Description Retrieves the last error message. ### Method ```php public function get_last_error_message(): string ``` ### Parameters None ### Returns - **string**: Last error message. ``` -------------------------------- ### login() Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Authenticate to the UniFi controller using username and password. Automatically detects controller type and adjusts accordingly. No-op if already logged in. ```APIDOC ## login() ### Description Authenticate to the UniFi controller using username and password. Automatically detects controller type and adjusts accordingly. No-op if already logged in. Stateless in Site Manager proxy mode. ### Method POST ### Endpoint /api/login ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **username** (string) - Required - Username for authentication - **password** (string) - Required - Password for authentication ### Request Example ```php try { $client = new UniFi_API\Client('admin', 'password', 'https://192.168.1.1:8443', 'default'); if ($client->login()) { echo "Logged in successfully\n"; } } catch (UniFi_API\Exceptions\LoginFailedException $e) { echo "Login failed: " . $e->getMessage(); } ``` ### Response #### Success Response (200) - **data** (object) - Contains session information upon successful login #### Response Example ```json { "data": { "token": "your_session_token_here" } } ``` ### Throws: - `LoginFailedException` — if authentication fails - `CurlTimeoutException` — if the request times out - `CurlGeneralErrorException` — if a cURL error occurs ``` -------------------------------- ### Get Last Error Message Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Retrieves the last error message that occurred during an API interaction. This is useful for diagnosing issues. ```php public function get_last_error_message(): string ``` -------------------------------- ### Connect via Site Manager Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Creates a Client instance configured for Site Manager proxy mode, routing requests through Ubiquiti's cloud proxy instead of direct controller connection. No login is required. ```APIDOC ## Connect via Site Manager ### Description Creates a Client instance configured for Site Manager proxy mode. All API requests are routed through the Ubiquiti Site Manager cloud proxy at `api.ui.com` instead of connecting directly to a controller. No `login()` call is needed. ### Method `connect_via_site_manager` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **console_id** (string) - Required - Console host ID, visible in the `unifi.ui.com` URL: `https://unifi.ui.com/consoles/{console_id}/network/default/dashboard` - **api_key** (string) - Required - Site Manager API key (not the local controller API key) - **site** (string) - Optional - Short site name. Defaults to 'default'. ### Returns - Client instance configured for proxy mode ### Throws - `InvalidArgumentException` when `$console_id` or `$api_key` is empty - `CurlExtensionNotLoadedException` - `InvalidSiteNameException` ### Notes - The console must be online, running firmware >= 5.0.3, and accessible to the API key owner - Non-organization API keys can only access the key owner's consoles - Organization API keys can access any console within the organization - All 200+ API methods work transparently through the proxy ``` -------------------------------- ### Get Tag Information Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Retrieves information about a specific tag using its ID. Requires the tag ID as a string parameter. ```php public function get_tag(string $tag_id): array ``` -------------------------------- ### download_backup() Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/client.md Downloads a backup file from the server. ```APIDOC ## download_backup() ### Description Download a backup file. ### Method Not specified (assumed to be a client method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **filepath** (string) - Required - Server filepath of backup ### Response #### Success Response - **mixed** — file contents #### Error Response - **false** — on error ``` -------------------------------- ### Get UniFi OS Console Update Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/API_REFERENCE.md Retrieves available UniFi OS console updates. Only for UniFi OS-based controllers. ```APIDOC ## Get UniFi OS Console Update ### Description Retrieves available UniFi OS console updates. ### Method Not specified (assumed to be a client method call) ### Endpoint Not specified ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Note Only for UniFi OS-based controllers ### Returns - array - Update information ``` -------------------------------- ### Catching CurlExtensionNotLoadedException Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/exceptions.md This exception is thrown when the PHP cURL extension is not loaded. Ensure the php-curl module is enabled in your PHP installation. ```php try { $client = new UniFi_API\Client('user', 'pass', 'https://192.168.1.1:8443'); } catch (UniFi_API\Exceptions\CurlExtensionNotLoadedException $e) { echo "cURL extension required but not available"; } ``` -------------------------------- ### System Configuration Methods Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/method-index.md Methods for fetching and setting various system-wide configurations, including general settings, country codes, extensions, management, SMTP, identity, device settings, and command execution. ```APIDOC ## System Configuration ### `list_settings()` #### Description Fetch all settings. #### Returns `array|bool` ### `list_country_codes()` #### Description Available countries. #### Returns `array|bool` ### `list_extension()` #### Description Extension configs. #### Returns `array|bool` ### `set_super_mgmt_settings_base(string, mixed)` #### Description Controller management. #### Parameters - **param1** (string) - Description not specified - **param2** (mixed) - Description not specified #### Returns `bool` ### `set_super_smtp_settings_base(string, mixed)` #### Description SMTP email settings. #### Parameters - **param1** (string) - Description not specified - **param2** (mixed) - Description not specified #### Returns `bool` ### `set_super_identity_settings_base(string, mixed)` #### Description Identity settings. #### Parameters - **param1** (string) - Description not specified - **param2** (mixed) - Description not specified #### Returns `bool` ### `set_device_settings_base(string, mixed)` #### Description Device settings. #### Parameters - **param1** (string) - Description not specified - **param2** (mixed) - Description not specified #### Returns `bool` ### `cmd_stat(string)` #### Description Execute system command. #### Parameters - **param1** (string) - Description not specified #### Returns `bool` ### `set_element_adoption(bool)` #### Description Element adoption mode. #### Parameters - **param1** (bool) - Description not specified #### Returns `bool` ``` -------------------------------- ### Configuration with SSL Verification Source: https://github.com/art-of-wifi/unifi-api-client/blob/main/_autodocs/configuration.md Configure the client with SSL verification enabled for production environments. This ensures secure communication with the UniFi controller. ```php require_once 'vendor/autoload.php'; $client = new UniFi_API\Client( 'admin', 'password', 'https://controller.example.com:8443', 'default', '8.0.28', true // Enable SSL verification ); $client->login(); ```