This document provides a comprehensive reference for all public methods available in the UniFi API Client class. We do our best to keep this document up-to-date with the latest version of the API client.
- Connection Management
- Client Management
- Access Point Management
- AP Group Management
- Site Management
- Network Management
- User Management
- User Group Management
- Guest Management
- Firewall Management
- Routing and Health
- Device Management
- Tag Management
- Rogue AP Management
- Backup Management
- Admin Management
- WLAN Group Management
- DNS Management
- System Management
- Statistics
- Debug and Utility Methods
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'
)
Creates a new instance of the UniFi API client.
Parameters:
$user
(string): Username for the UniFi controller$password
(string): Password for the UniFi controller$baseurl
(string): Base URL of the UniFi controller (must include 'https://' prefix)$site
(string|null): Short site name to access (default: 'default')$version
(string|null): Controller version number (default: '8.0.28')$ssl_verify
(bool): Whether to validate SSL certificate (default: false)$unificookie_name
(string): Name of the cookie to use (default: 'unificookie')
Throws:
CurlExtensionNotLoadedException
InvalidBaseUrlException
InvalidSiteNameException
public function login(): bool
Logs in to the UniFi controller.
Returns: bool - true upon successful login
Throws:
LoginFailedException
CurlTimeoutException
CurlGeneralErrorException
public function logout(): bool
Logs out from the UniFi controller.
Returns: bool - true upon success
Throws:
CurlGeneralErrorException
CurlTimeoutException
public function list_clients(?string $mac = null, ?string $site_id = null): array
Lists all clients or a specific client.
Parameters:
$mac
(string|null): MAC address of the client to list$site_id
(string|null): Site ID to use (default: current site)
Returns: array - Array of client objects
public function block_sta(string $mac, ?string $site_id = null): bool
Blocks a client from accessing the network.
Parameters:
$mac
(string): MAC address of the client to block$site_id
(string|null): Site ID to use (default: current site)
Returns: bool - true upon success
public function unblock_sta(string $mac, ?string $site_id = null): bool
Unblocks a client from accessing the network.
Parameters:
$mac
(string): MAC address of the client to unblock$site_id
(string|null): Site ID to use (default: current site)
Returns: bool - true upon success
public function reconnect_sta(string $mac): bool
Reconnects a client to the network.
Parameters:
$mac
(string): MAC address of the client to reconnect
Returns: bool - true upon success
public function forget_sta(string $mac): bool
Removes a client from the controller's memory.
Parameters:
$mac
(string): MAC address of the client to forget
Returns: bool - true upon success
public function set_sta_note(string $user_id, string $note = ''): bool
Sets a note for a specific client.
Parameters:
$user_id
(string): ID of the client$note
(string): Note to set (default: empty string)
Returns: bool - true upon success
public function set_sta_name(string $user_id, string $name = ''): bool
Sets the name for a specific client.
Parameters:
$user_id
(string): ID of the client$name
(string): Name to set (default: empty string)
Returns: bool - true upon success
public function list_active_clients(bool $include_traffic_usage = true, bool $include_unifi_devices = true): array
Lists all currently active clients.
Parameters:
$include_traffic_usage
(bool): Whether to include traffic usage information (default: true)$include_unifi_devices
(bool): Whether to include UniFi devices (default: true)
Returns: array - Array of active client objects
public function list_clients_history(bool $only_non_blocked = true, bool $include_unifi_devices = true, int $within_hours = 0): array
Lists historical client information.
Parameters:
$only_non_blocked
(bool): Whether to only show non-blocked clients (default: true)$include_unifi_devices
(bool): Whether to include UniFi devices (default: true)$within_hours
(int): Hours of history to retrieve (default: 0)
Returns: array - Array of historical client objects
public function list_fingerprint_devices(int $fingerprint_source = 0): array
Lists devices identified by fingerprinting.
Parameters:
$fingerprint_source
(int): Source of fingerprint data (default: 0)
Returns: array - Array of fingerprint device objects
public function set_usergroup(string $client_id, string $group_id): bool
Sets the user group for a client.
Parameters:
$client_id
(string): ID of the client$group_id
(string): ID of the user group to assign
Returns: bool - true upon success
public function edit_client_fixedip(string $client_id, bool $use_fixedip, ?string $network_id = null, ?string $fixed_ip = null): bool
Configures fixed IP settings for a client.
Parameters:
$client_id
(string): ID of the client$use_fixedip
(bool): Whether to use a fixed IP$network_id
(string|null): ID of the network to use$fixed_ip
(string|null): Fixed IP address to assign
Returns: bool - true upon success
public function edit_client_name(string $client_id, string $name): bool
Edits the name of a client.
Parameters:
$client_id
(string): ID of the client$name
(string): New name for the client
Returns: bool - true upon success
public function list_aps(?string $mac = null, ?string $site_id = null): array
Lists all access points or a specific access point.
Parameters:
$mac
(string|null): MAC address of the AP to list$site_id
(string|null): Site ID to use (default: current site)
Returns: array - Array of access point objects
public function set_ap_radiosettings(
string $ap_id,
?string $radio = null,
?string $channel = null,
?string $ht = null,
?string $tx_power_mode = null,
?string $tx_power = null,
?string $site_id = null
): bool
Configures radio settings for an access point.
Parameters:
$ap_id
(string): ID of the access point$radio
(string|null): Radio to configure ('ng' or 'na')$channel
(string|null): Channel to set$ht
(string|null): HT mode to set$tx_power_mode
(string|null): TX power mode to set$tx_power
(string|null): TX power level to set$site_id
(string|null): Site ID to use (default: current site)
Returns: bool - true upon success
public function list_apgroups(): array
Lists all AP groups.
Returns: array - Array of AP group objects
public function create_apgroup(string $group_name, array $device_macs = []): bool
Creates a new AP group.
Parameters:
$group_name
(string): Name of the new group$device_macs
(array): Array of MAC addresses of APs to include in the group
Returns: bool - true upon success
public function edit_apgroup(string $group_id, string $group_name, array $device_macs): bool
Edits an existing AP group.
Parameters:
$group_id
(string): ID of the group to edit$group_name
(string): New name for the group$device_macs
(array): Array of MAC addresses of APs to include in the group
Returns: bool - true upon success
public function delete_apgroup(string $group_id): bool
Deletes an AP group.
Parameters:
$group_id
(string): ID of the group to delete
Returns: bool - true upon success
public function list_sites(): array
Lists all sites available to the current user.
Returns: array - Array of site objects
public function create_site(string $name, string $desc = ''): bool
Creates a new site.
Parameters:
$name
(string): Name of the new site$desc
(string): Description of the new site
Returns: bool - true upon success
public function delete_site(string $site_id): bool
Deletes a site.
Parameters:
$site_id
(string): ID of the site to delete
Returns: bool - true upon success
public function set_site_name(string $site_name): bool
Sets the name of the current site.
Parameters:
$site_name
(string): New name for the site
Returns: bool - true upon success
public function set_site_country(string $country_id, $payload): bool
Sets the country settings for the current site.
Parameters:
$country_id
(string): ID of the country settings$payload
(mixed): Country configuration data
Returns: bool - true upon success
public function set_site_locale(string $locale_id, $payload): bool
Sets the locale settings for the current site.
Parameters:
$locale_id
(string): ID of the locale settings$payload
(mixed): Locale configuration data
Returns: bool - true upon success
public function set_site_snmp(string $snmp_id, $payload): bool
Sets the SNMP settings for the current site.
Parameters:
$snmp_id
(string): ID of the SNMP settings$payload
(mixed): SNMP configuration data
Returns: bool - true upon success
public function set_site_mgmt(string $mgmt_id, $payload): bool
Sets the management settings for the current site.
Parameters:
$mgmt_id
(string): ID of the management settings$payload
(mixed): Management configuration data
Returns: bool - true upon success
public function set_site_guest_access(string $guest_access_id, $payload): bool
Sets the guest access settings for the current site.
Parameters:
$guest_access_id
(string): ID of the guest access settings$payload
(mixed): Guest access configuration data
Returns: bool - true upon success
public function set_site_ntp(string $ntp_id, $payload): bool
Sets the NTP settings for the current site.
Parameters:
$ntp_id
(string): ID of the NTP settings$payload
(mixed): NTP configuration data
Returns: bool - true upon success
public function set_site_connectivity(string $connectivity_id, $payload): bool
Sets the connectivity settings for the current site.
Parameters:
$connectivity_id
(string): ID of the connectivity settings$payload
(mixed): Connectivity configuration data
Returns: bool - true upon success
public function list_networks(?string $site_id = null): array
Lists all networks or networks for a specific site.
Parameters:
$site_id
(string|null): Site ID to use (default: current site)
Returns: array - Array of network objects
public function create_network(
string $name,
string $vlan_id,
string $purpose = 'corporate',
?string $subnet = null,
?string $dhcpd_enabled = null,
?string $dhcpd_start = null,
?string $dhcpd_stop = null,
?string $dhcpd_leasetime = null,
?string $site_id = null
): bool
Creates a new network.
Parameters:
$name
(string): Name of the new network$vlan_id
(string): VLAN ID for the network$purpose
(string): Purpose of the network (default: 'corporate')$subnet
(string|null): Subnet for the network$dhcpd_enabled
(string|null): Whether DHCP is enabled$dhcpd_start
(string|null): DHCP start address$dhcpd_stop
(string|null): DHCP stop address$dhcpd_leasetime
(string|null): DHCP lease time$site_id
(string|null): Site ID to use (default: current site)
Returns: bool - true upon success
public function list_users(?string $site_id = null): array
Lists all users or users for a specific site.
Parameters:
$site_id
(string|null): Site ID to use (default: current site)
Returns: array - Array of user objects
public function create_user(
string $name,
string $mac,
?string $hostname = null,
?string $note = null,
?string $site_id = null
): bool
Creates a new user.
Parameters:
$name
(string): Name of the new user$mac
(string): MAC address of the user$hostname
(string|null): Hostname of the user$note
(string|null): Note about the user$site_id
(string|null): Site ID to use (default: current site)
Returns: bool - true upon success
public function list_usergroups(): array
Lists all user groups.
Returns: array - Array of user group objects
public function create_usergroup(string $group_name, int $group_dn = -1, int $group_up = -1): bool
Creates a new user group.
Parameters:
$group_name
(string): Name of the new group$group_dn
(int): Download speed limit in Kbps (default: -1 for unlimited)$group_up
(int): Upload speed limit in Kbps (default: -1 for unlimited)
Returns: bool - true upon success
public function edit_usergroup(string $group_id, string $site_id, string $group_name, int $group_dn = -1, int $group_up = -1): bool
Edits an existing user group.
Parameters:
$group_id
(string): ID of the group to edit$site_id
(string): ID of the site$group_name
(string): New name for the group$group_dn
(int): Download speed limit in Kbps (default: -1 for unlimited)$group_up
(int): Upload speed limit in Kbps (default: -1 for unlimited)
Returns: bool - true upon success
public function delete_usergroup(string $group_id): bool
Deletes a user group.
Parameters:
$group_id
(string): ID of the group to delete
Returns: bool - true upon success
public function list_guests(int $within = 8760): array
Lists all guest clients.
Parameters:
$within
(int): Hours of history to retrieve (default: 8760)
Returns: array - Array of guest client objects
public function authorize_guest(string $mac, int $minutes, ?int $up = null, ?int $down = null, ?int $megabytes = null, ?string $ap_mac = null): bool
Authorizes a guest client to access the network.
Parameters:
$mac
(string): MAC address of the guest client$minutes
(int): Duration of authorization in minutes$up
(int|null): Upload speed limit in Kbps$down
(int|null): Download speed limit in Kbps$megabytes
(int|null): Data usage limit in MB$ap_mac
(string|null): MAC address of specific AP to connect to
Returns: bool - true upon success
public function unauthorize_guest(string $mac): bool
Revokes guest client authorization.
Parameters:
$mac
(string): MAC address of the guest client
Returns: bool - true upon success
public function list_firewallgroups(string $group_id = ''): array
Lists all firewall groups or a specific group.
Parameters:
$group_id
(string): ID of specific group to list (default: empty string)
Returns: array - Array of firewall group objects
public function create_firewallgroup(string $group_name, string $group_type, array $group_members = []): bool
Creates a new firewall group.
Parameters:
$group_name
(string): Name of the new group$group_type
(string): Type of the group$group_members
(array): Array of group members
Returns: bool - true upon success
public function edit_firewallgroup(string $group_id, string $site_id, string $group_name, string $group_type, array $group_members = []): bool
Edits an existing firewall group.
Parameters:
$group_id
(string): ID of the group to edit$site_id
(string): ID of the site$group_name
(string): New name for the group$group_type
(string): Type of the group$group_members
(array): Array of group members
Returns: bool - true upon success
public function delete_firewallgroup(string $group_id): bool
Deletes a firewall group.
Parameters:
$group_id
(string): ID of the group to delete
Returns: bool - true upon success
public function list_firewallrules(): array
Lists all firewall rules.
Returns: array - Array of firewall rule objects
public function list_routing(string $route_id = ''): array
Lists all routing information or a specific route.
Parameters:
$route_id
(string): ID of specific route to list (default: empty string)
Returns: array - Array of routing objects
public function list_health(): array
Lists system health information.
Returns: array - Array containing health information
public function list_dashboard(bool $five_minutes = false): array
Lists dashboard information.
Parameters:
$five_minutes
(bool): Whether to get 5-minute data (default: false)
Returns: array - Array containing dashboard information
public function list_devices_basic(): array
Lists basic information about all devices.
Returns: array - Array of basic device information
public function list_devices($macs = []): array
Lists detailed information about devices.
Parameters:
$macs
(array): Array of MAC addresses of specific devices to list
Returns: array - Array of device objects
public function list_tags(): array
Lists all tags.
Returns: array - Array of tag objects
public function create_tag(string $name, ?array $macs = null): bool
Creates a new tag.
Parameters:
$name
(string): Name of the new tag$macs
(array|null): Array of MAC addresses to tag
Returns: bool - true upon success
public function set_tagged_devices(array $macs, string $tag_id): bool
Sets devices for a specific tag.
Parameters:
$macs
(array): Array of MAC addresses to tag$tag_id
(string): ID of the tag
Returns: bool - true upon success
public function get_tag(string $tag_id): array
Retrieves information about a specific tag.
Parameters:
$tag_id
(string): ID of the tag
Returns: array - Array containing tag information
public function delete_tag(string $tag_id): bool
Deletes a tag.
Parameters:
$tag_id
(string): ID of the tag to delete
Returns: bool - true upon success
public function list_rogueaps(int $within = 24): array
Lists rogue access points.
Parameters:
$within
(int): Hours of history to retrieve (default: 24)
Returns: array - Array of rogue AP objects
public function list_known_rogueaps(): array
Lists known rogue access points.
Returns: array - Array of known rogue AP objects
public function generate_backup(int $days = -1): array
Generates a backup of the controller.
Parameters:
$days
(int): Number of days of history to include (default: -1)
Returns: array - Array containing backup information
public function download_backup(string $filepath): bool
Downloads a backup file.
Parameters:
$filepath
(string): Path where to save the backup file
Returns: bool - true upon success
public function list_backups(): array
Lists available backups.
Returns: array - Array of backup objects
public function generate_backup_site(): array
Generates a backup of the current site.
Returns: array - Array containing site backup information
public function list_admins(): array
Lists all administrators.
Returns: array - Array of admin objects
public function list_all_admins(): array
Lists all administrators including super admins.
Returns: array - Array of admin objects
public function invite_admin(
string $name,
string $email,
bool $for_super = false,
?string $cmd = null,
?string $role = null
): bool
Invites a new administrator.
Parameters:
$name
(string): Name of the new admin$email
(string): Email address of the new admin$for_super
(bool): Whether to invite as super admin (default: false)$cmd
(string|null): Additional command parameters$role
(string|null): Role to assign
Returns: bool - true upon success
public function assign_existing_admin(
string $admin_id,
string $name,
bool $for_super = false,
?string $cmd = null,
?string $role = null
): bool
Assigns an existing admin to a site.
Parameters:
$admin_id
(string): ID of the admin$name
(string): Name of the admin$for_super
(bool): Whether to assign as super admin (default: false)$cmd
(string|null): Additional command parameters$role
(string|null): Role to assign
Returns: bool - true upon success
public function update_admin(
string $admin_id,
string $name,
bool $for_super = false,
?string $cmd = null,
?string $role = null
): bool
Updates an administrator's settings.
Parameters:
$admin_id
(string): ID of the admin to update$name
(string): New name for the admin$for_super
(bool): Whether to set as super admin (default: false)$cmd
(string|null): Additional command parameters$role
(string|null): Role to assign
Returns: bool - true upon success
public function revoke_admin(string $admin_id): bool
Revokes an administrator's access.
Parameters:
$admin_id
(string): ID of the admin to revoke
Returns: bool - true upon success
public function delete_admin(string $admin_id): bool
Deletes an administrator.
Parameters:
$admin_id
(string): ID of the admin to delete
Returns: bool - true upon success
public function list_wlan_groups(): array
Lists all WLAN groups.
Returns: array - Array of WLAN group objects
public function list_dns_records(): ?array
Lists all DNS records configured in the UniFi controller.
Returns: array|null - Array of DNS record objects, or null if no records exist
public function create_dns_record(string $record_type, string $value, string $key, ?int $ttl = null, bool $enabled = true): ?object
Creates a new DNS record in the UniFi controller.
Parameters:
$record_type
(string): Type of DNS record (e.g., 'A', 'AAAA', 'CNAME', etc.)$value
(string): Value of the DNS record$key
(string): Key/name for the DNS record$ttl
(int|null): Time-to-live value in seconds (default: null)$enabled
(bool): Whether the record is enabled (default: true)
Returns: object|null - Created DNS record object, or null if creation failed
public function delete_dns_record(string $record_id): bool
Deletes a DNS record from the UniFi controller.
Parameters:
$record_id
(string): ID of the DNS record to delete
Returns: bool - true upon success
public function list_device_name_mappings(): array
Lists device name mappings.
Returns: array - Array of device name mapping objects
public function list_self(): array
Lists information about the current user.
Returns: array - Array containing current user information
public function stat_5minutes_site(?int $start = null, ?int $end = null, ?array $attribs = null): array
public function stat_hourly_site(?int $start = null, ?int $end = null, ?array $attribs = null): array
public function stat_daily_site(?int $start = null, ?int $end = null, ?array $attribs = null): array
public function stat_monthly_site(?int $start = null, ?int $end = null, ?array $attribs = null): array
Retrieves site statistics at different time intervals.
Parameters:
$start
(int|null): Start time in Unix timestamp$end
(int|null): End time in Unix timestamp$attribs
(array|null): Array of attributes to retrieve
Returns: array - Array containing site statistics
public function stat_5minutes_aps(?int $start = null, ?int $end = null, ?string $mac = null, ?array $attribs = null): array
public function stat_hourly_aps(?int $start = null, ?int $end = null, ?string $mac = null, ?array $attribs = null): array
public function stat_daily_aps(?int $start = null, ?int $end = null, ?string $mac = null, ?array $attribs = null): array
public function stat_monthly_aps(?int $start = null, ?int $end = null, ?string $mac = null, ?array $attribs = null): array
Retrieves access point statistics at different time intervals.
Parameters:
$start
(int|null): Start time in Unix timestamp$end
(int|null): End time in Unix timestamp$mac
(string|null): MAC address of specific AP$attribs
(array|null): Array of attributes to retrieve
Returns: array - Array containing AP statistics
public function stat_5minutes_user(?string $mac = null, ?int $start = null, ?int $end = null, ?array $attribs = null): array
public function stat_hourly_user(?string $mac = null, ?int $start = null, ?int $end = null, ?array $attribs = null): array
public function stat_daily_user(?string $mac = null, ?int $start = null, ?int $end = null, ?array $attribs = null): array
public function stat_monthly_user(?string $mac = null, ?int $start = null, ?int $end = null, ?array $attribs = null): array
Retrieves user statistics at different time intervals.
Parameters:
$mac
(string|null): MAC address of specific user$start
(int|null): Start time in Unix timestamp$end
(int|null): End time in Unix timestamp$attribs
(array|null): Array of attributes to retrieve
Returns: array - Array containing user statistics
public function stat_5minutes_gateway(?int $start = null, ?int $end = null, ?array $attribs = null): array
public function stat_hourly_gateway(?int $start = null, ?int $end = null, ?array $attribs = null): array
public function stat_daily_gateway(?int $start = null, ?int $end = null, ?array $attribs = null): array
public function stat_monthly_gateway(?int $start = null, ?int $end = null, ?array $attribs = null): array
Retrieves gateway statistics at different time intervals.
Parameters:
$start
(int|null): Start time in Unix timestamp$end
(int|null): End time in Unix timestamp$attribs
(array|null): Array of attributes to retrieve
Returns: array - Array containing gateway statistics
public function stat_speedtest_results(?int $start = null, ?int $end = null): array
Retrieves speed test results.
Parameters:
$start
(int|null): Start time in Unix timestamp$end
(int|null): End time in Unix timestamp
Returns: array - Array containing speed test results
public function stat_ips_events(?int $start = null, ?int $end = null, ?int $limit = null): array
Retrieves IPS (Intrusion Prevention System) events.
Parameters:
$start
(int|null): Start time in Unix timestamp$end
(int|null): End time in Unix timestamp$limit
(int|null): Maximum number of events to retrieve
Returns: array - Array containing IPS events
public function stat_sessions(?int $start = null, ?int $end = null, ?string $mac = null, ?string $type = 'all'): array
Retrieves session information.
Parameters:
$start
(int|null): Start time in Unix timestamp$end
(int|null): End time in Unix timestamp$mac
(string|null): MAC address of specific client$type
(string): Type of sessions to retrieve (default: 'all')
Returns: array - Array containing session information
public function stat_sta_sessions_latest(string $mac, ?int $limit = null): array
Retrieves the latest sessions for a specific client.
Parameters:
$mac
(string): MAC address of the client$limit
(int|null): Maximum number of sessions to retrieve
Returns: array - Array containing latest client sessions
public function stat_auths(?int $start = null, ?int $end = null): array
Retrieves authentication events.
Parameters:
$start
(int|null): Start time in Unix timestamp$end
(int|null): End time in Unix timestamp
Returns: array - Array containing authentication events
public function stat_allusers(int $historyhours = 8760): array
Retrieves information about all users.
Parameters:
$historyhours
(int): Hours of history to retrieve (default: 8760)
Returns: array - Array containing user information
public function stat_client(string $mac): array
Retrieves statistics for a specific client.
Parameters:
$mac
(string): MAC address of the client
Returns: array - Array containing client statistics
public function stat_status(): bool
public function stat_full_status(): array
Retrieves system status information.
Returns:
stat_status()
: bool - true if system is operationalstat_full_status()
: array - Array containing detailed system status
public function stat_voucher(?int $create_time = null): array
Retrieves voucher statistics.
Parameters:
$create_time
(int|null): Creation time of specific voucher
Returns: array - Array containing voucher statistics
public function stat_payment(?int $within = null): array
Retrieves payment statistics.
Parameters:
$within
(int|null): Time window in seconds
Returns: array - Array containing payment statistics
public function set_debug(bool $debug): void
Enables or disables debug mode.
Parameters:
$debug
(bool): Whether to enable debug mode
public function get_last_error_message(): string
Retrieves the last error message.
Returns: string - Last error message
public function get_last_results_raw(): mixed
Retrieves the last raw results from the API.
Returns: mixed - Last raw results
public function get_cookies(): string
Retrieves the current cookies.
Returns: string - Current cookies
public function get_cookies_created_at(): int
Retrieves the timestamp when the cookies were created.
Returns: int - Timestamp of cookie creation
public function get_baseurl(): string
Retrieves the base URL of the UniFi controller.
Returns: string - Base URL
public function get_site(): string
Retrieves the current site name.
Returns: string - Current site name
public function get_version(): string
Retrieves the controller version.
Returns: string - Controller version
public function get_class_version(): string
Retrieves the version of this API client class.
Returns: string - Class version