### List SD-WAN Configurations (Node.js) Source: https://developer.ui.com/site-manager/v1.0.0/listsdwanconfigs Provides a Node.js example for fetching SD-WAN configurations. It utilizes the 'https' module to make a GET request to the UniFi API, including the API key in the headers. ```javascript const https = require('https'); const options = { hostname: 'api.ui.com', port: 443, path: '/v1/sd-wan-configs', method: 'GET', headers: { 'Accept': 'application/json', 'X-API-Key': '' } }; const req = https.request(options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log(JSON.parse(data)); }); }).on('error', (err) => { console.error('Error: ' + err.message); }); req.end(); ``` -------------------------------- ### Get SD-WAN Config Status using Node.js Source: https://developer.ui.com/site-manager/v1.0.0/getsdwanconfigstatus Provides a Node.js example for fetching the status of an SD-WAN configuration. It utilizes the 'https' module to make the GET request, including the necessary API key and accept headers. ```javascript const https = require('https'); const options = { hostname: 'api.ui.com', port: 443, path: '/v1/sd-wan-configs/{id}/status', method: 'GET', headers: { 'Accept': 'application/json', 'X-API-Key': '' } }; const req = https.request(options, (res) => { console.log('Status Code:', res.statusCode); let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log('Response Body:', data); }); }); req.on('error', (error) => { console.error('Error:', error); }); req.end(); ``` -------------------------------- ### List Hosts using Node.js Source: https://developer.ui.com/site-manager/v1.0.0/listhosts Provides a Node.js example for fetching a list of hosts from the UniFi API. This code snippet illustrates making an HTTP GET request with appropriate headers. ```javascript const https = require('https'); const options = { hostname: 'api.ui.com', port: 443, path: '/v1/hosts?pageSize=10&nextToken=602232A870250000000006C514FF00000000073DD8DB000000006369FDA2%3A1467082514', method: 'GET', headers: { 'Accept': 'application/json', 'X-API-Key': '' } }; const req = https.request(options, (res) => { console.log('statusCode:', res.statusCode); console.log('headers:', res.headers); let body = ''; res.on('data', (chunk) => { body += chunk; }); res.on('end', () => { console.log(body); }); }); req.on('error', (e) => { console.error(e); }); req.end(); ``` -------------------------------- ### Get SD-WAN Config by ID (cURL) Source: https://developer.ui.com/site-manager/v1.0.0/getsdwanconfigbyid Retrieves detailed information about a specific SD-WAN configuration using its unique identifier. This example uses cURL and requires an API key. ```shell curl -L -g "https://api.ui.com/v1/sd-wan-configs/{id}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### Get SD-WAN Config Status using Go Source: https://developer.ui.com/site-manager/v1.0.0/getsdwanconfigstatus Demonstrates how to retrieve the status of a specific SD-WAN configuration using Go. This involves making an HTTP GET request to the UniFi API endpoint with appropriate headers for authentication and content type. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.ui.com/v1/sd-wan-configs/{id}/status" apiKey := "" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Add("Accept", "application/json") req.Header.Add("X-API-Key", apiKey) resp, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println("Status Code:", resp.StatusCode) fmt.Println("Response Body:", string(body)) } ``` -------------------------------- ### List Hosts using cURL Source: https://developer.ui.com/site-manager/v1.0.0/listhosts Example of how to retrieve a list of hosts using the cURL command-line tool. It demonstrates the necessary URL, headers, and API key for authentication. ```bash curl -L "https://api.ui.com/v1/hosts?pageSize=10&nextToken=602232A870250000000006C514FF00000000073DD8DB000000006369FDA2%3A1467082514" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### List SD-WAN Configurations (Go) Source: https://developer.ui.com/site-manager/v1.0.0/listsdwanconfigs Demonstrates how to retrieve a list of SD-WAN configurations using Go. This involves making an HTTP GET request to the UniFi API endpoint with the necessary headers. ```go package main import ( "fmt" "io/ioutil" "net/http" "strings" ) func main() { url := "https://api.ui.com/v1/sd-wan-configs" apiKey := "" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Printf("Error creating request: %s\n", err) return } req.Header.Add("Accept", "application/json") req.Header.Add("X-API-Key", apiKey) resp, err := client.Do(req) if err != nil { fmt.Printf("Error sending request: %s\n", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Printf("Error reading response body: %s\n", err) return } fmt.Println(string(body)) } ``` -------------------------------- ### List Sites API Call Examples (cURL, Go, Node.js, Python) Source: https://developer.ui.com/site-manager/v1.0.0/listsites Demonstrates how to call the UniFi API's '/v1/sites' endpoint to retrieve a list of sites. Supports pagination via 'pageSize' and 'nextToken' query parameters. The API key is required for authentication. ```curl curl -L "https://api.ui.com/v1/sites?pageSize=10&nextToken=602232A870250000000006C514FF00000000073DD8DB000000006369FDA2%3A1467082514" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { client := &http.Client{} req, err := http.NewRequest("GET", "https://api.ui.com/v1/sites?pageSize=10&nextToken=602232A870250000000006C514FF00000000073DD8DB000000006369FDA2%3A1467082514", nil) if err != nil { fmt.Println(err) return } req.Header.Add("Accept", "application/json") req.Header.Add("X-API-Key", "") resp, err := client.Do(req) if err != nil { fmt.Println(err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` ```node.js const axios = require('axios'); const options = { method: 'GET', url: 'https://api.ui.com/v1/sites', params: { pageSize: '10', nextToken: '602232A870250000000006C514FF00000000073DD8DB000000006369FDA2%3A1467082514' }, headers: { 'Accept': 'application/json', 'X-API-Key': '' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` ```python import requests url = "https://api.ui.com/v1/sites" params = { "pageSize": "10", "nextToken": "602232A870250000000006C514FF00000000073DD8DB000000006369FDA2%3A1467082514" } headers = { "Accept": "application/json", "X-API-Key": "" } response = requests.get(url, params=params, headers=headers) print(response.json()) ``` -------------------------------- ### List UniFi Devices using cURL Source: https://developer.ui.com/site-manager/v1.0.0/listdevices Example of how to retrieve a list of UniFi devices using cURL. This command demonstrates the use of query parameters for filtering and pagination, and requires an API key for authentication. ```bash curl -L -g "https://api.ui.com/v1/devices?hostIds[]=900A6F00301100000000074A6BA90000000007A3387E0000000063EC9853%3A123456789%2C900A6F00301100000000074A6BA90000000007A3387E0000000063EC9853%3A987654321&time=2025-10-30T01%3A52%3A51Z&pageSize=10&nextToken=602232A870250000000006C514FF00000000073DD8DB000000006369FDA2%3A1467082514" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### Get SD-WAN Config by ID Source: https://developer.ui.com/site-manager/v1.0.0/getsdwanconfigbyid Retrieves detailed information about a specific SD-WAN configuration using its unique identifier. ```APIDOC ## GET /v1/sd-wan-configs/{id} ### Description Retrieves detailed information about a specific SD-WAN configuration by ID. ### Method GET ### Endpoint `/v1/sd-wan-configs/{id}` ### Parameters #### Path Parameters - **id** (string) - Required - Unique identifier of the SD-WAN configuration ### Request Example ```bash curl -L -g "https://api.ui.com/v1/sd-wan-configs/{id}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` ### Response #### Success Response (200) - **dataExpand** (object) - Generic response data, specific schema depends on the endpoint - **httpStatusCode** (integer) - HTTP status code - **traceId** (string) - Request trace identifier #### Response Example ```json { "dataExpand": {}, "httpStatusCode": 200, "traceId": "some-trace-id" } ``` ``` -------------------------------- ### Get Host by ID Source: https://developer.ui.com/site-manager/v1.0.0/gethostbyid Retrieves detailed information about a specific host by its unique identifier. ```APIDOC ## GET /v1/hosts/{id} ### Description Retrieves detailed information about a specific host by ID. **Note**: The structure of the `userData` and `reportedState` fields may vary depending on the UniFi OS or Network Server version. The example provided is based on UniFi OS 4.1.13. ### Method GET ### Endpoint `/v1/hosts/{id}` ### Parameters #### Path Parameters - **id** (string) - Required - Unique identifier of the host ### Request Example ```bash curl -L -g "https://api.ui.com/v1/hosts/{id}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` ### Response #### Success Response (200) - **dataExpand** (object) - Generic response data, specific schema depends on the endpoint - **httpStatusCode** (integer) - HTTP status code - **traceId** (string) - Request trace identifier #### Response Example ```json { "dataExpand": {}, "httpStatusCode": 200, "traceId": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ``` -------------------------------- ### List SD-WAN Configurations (Python) Source: https://developer.ui.com/site-manager/v1.0.0/listsdwanconfigs Shows how to retrieve SD-WAN configurations using Python's 'requests' library. This script sends a GET request to the specified API endpoint with the required authentication header. ```python import requests url = "https://api.ui.com/v1/sd-wan-configs" api_key = "" headers = { "Accept": "application/json", "X-API-Key": api_key } response = requests.get(url, headers=headers) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") print(response.text) ``` -------------------------------- ### Get Host by ID - Go Source: https://developer.ui.com/site-manager/v1.0.0/gethostbyid Retrieves detailed information about a specific host using its unique identifier via a Go program. Requires an API key for authentication. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.ui.com/v1/hosts/{id}" apiKey := "" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Add("Accept", "application/json") req.Header.Add("X-API-Key", apiKey) res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println("Status Code:", res.StatusCode) fmt.Println("Response Body:", string(body)) } ``` -------------------------------- ### Get SD-WAN Config Status Source: https://developer.ui.com/site-manager/v1.0.0/getsdwanconfigstatus Retrieves the status of a specific SD-WAN configuration, including deployment progress, errors, and associated hubs. ```APIDOC ## GET /v1/sd-wan-configs/{id}/status ### Description Retrieves the status of a specific SD-WAN configuration, including deployment progress, errors, and associated hubs. ### Method GET ### Endpoint `/v1/sd-wan-configs/{id}/status` ### Parameters #### Path Parameters - **id** (string) - Required - Unique identifier of the SD-WAN configuration ### Request Example ```curl curl -L -g "https://api.ui.com/v1/sd-wan-configs/{id}/status" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` ### Response #### Success Response (200) - **dataExpand** (object) - Generic response data, specific schema depends on the endpoint - **httpStatusCode** (integer) - HTTP status code - **traceId** (string) - Request trace identifier #### Response Example ```json { "dataExpand": {}, "httpStatusCode": 200, "traceId": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ``` -------------------------------- ### Get SD-WAN Config Status using Python Source: https://developer.ui.com/site-manager/v1.0.0/getsdwanconfigstatus Illustrates how to obtain the status of a specific SD-WAN configuration using Python's 'requests' library. This method simplifies HTTP requests, handling headers and response parsing efficiently. ```python import requests url = "https://api.ui.com/v1/sd-wan-configs/{id}/status" api_key = "" headers = { "Accept": "application/json", "X-API-Key": api_key } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes print("Status Code:", response.status_code) print("Response Body:", response.json()) except requests.exceptions.RequestException as e: print(f"Error: {e}") ``` -------------------------------- ### Site Manager API v1.0 - Get Hosts Source: https://developer.ui.com/site-manager/v1.0.0/gettingstarted This endpoint retrieves a list of hosts within the UniFi network. It requires an API key for authentication and specifies the desired response format. ```APIDOC ## GET /v1/hosts ### Description Retrieves a list of hosts within the UniFi network. ### Method GET ### Endpoint /v1/hosts ### Parameters #### Headers - **X-API-KEY** (string) - Required - Your UniFi API key. - **Accept** (string) - Required - Specifies the desired response format, typically 'application/json'. ### Request Example ```bash curl -X GET 'https://api.ui.com/v1/hosts' \ -H 'X-API-KEY: YOUR_API_KEY' \ -H 'Accept: application/json' ``` ### Response #### Success Response (200) - **hosts** (array) - A list of host objects, each containing details about a UniFi device. #### Response Example ```json { "hosts": [ { "mac": "00:11:22:33:44:55", "ip": "192.168.1.10", "model": "USW-Pro-24-PoE", "version": "5.64.100" } ] } ``` ``` -------------------------------- ### Get Host by ID - Node.js Source: https://developer.ui.com/site-manager/v1.0.0/gethostbyid Retrieves detailed information about a specific host using its unique identifier via a Node.js script. Requires an API key for authentication. ```javascript const https = require('https'); const options = { hostname: 'api.ui.com', port: 443, path: '/v1/hosts/{id}', method: 'GET', headers: { 'Accept': 'application/json', 'X-API-Key': '' } }; const req = https.request(options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log('Status Code:', res.statusCode); console.log('Response Body:', JSON.parse(data)); }); }); req.on('error', (error) => { console.error('Error:', error); }); req.end(); ``` -------------------------------- ### Get Host by ID - cURL Source: https://developer.ui.com/site-manager/v1.0.0/gethostbyid Retrieves detailed information about a specific host using its unique identifier via a cURL request. Requires an API key for authentication. ```bash curl -L -g "https://api.ui.com/v1/hosts/{id}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### Get Host by ID - Python Source: https://developer.ui.com/site-manager/v1.0.0/gethostbyid Retrieves detailed information about a specific host using its unique identifier via a Python script. Requires an API key for authentication. ```python import requests url = "https://api.ui.com/v1/hosts/{id}" api_key = "" headers = { "Accept": "application/json", "X-API-Key": api_key } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes print(f"Status Code: {response.status_code}") print(f"Response Body: {response.json()}") except requests.exceptions.RequestException as e: print(f"Error: {e}") ``` -------------------------------- ### GET /v1/isp-metrics/{type} Source: https://developer.ui.com/site-manager/v1.0.0/getispmetrics Retrieves ISP metrics data for all sites linked to the UI account's API key. 5-minute interval metrics are available for at least 24 hours, and 1-hour interval metrics are available for at least 30 days. ```APIDOC ## GET /v1/isp-metrics/{type} ### Description Retrieves ISP metrics data for all sites linked to the UI account's API key. 5-minute interval metrics are available for at least 24 hours, and 1-hour interval metrics are available for at least 30 days. ### Method GET ### Endpoint `/v1/isp-metrics/{type}` ### Parameters #### Path Parameters - **type** (string) - Required - Specifies whether metrics are returned using `5m` or `1h` intervals #### Query Parameters - **beginTimestamp** (string) - Optional - The earliest timestamp to retrieve data from (RFC3339 format) - **endTimestamp** (string) - Optional - The latest timestamp to retrieve data up to (RFC3339 format) - **duration** (string) - Optional - Specifies the time range of metrics to retrieve, starting from when the request is made. Supports `24h` for 5-minute metrics, and `7d` or `30d` for 1-hour metrics. This parameter **cannot** be used with `beginTimestamp` or `endTimestamp`. ### Request Example ```bash curl -L -g "https://api.ui.com/v1/isp-metrics/{type}?beginTimestamp=2024-06-30T13%3A35%3A00Z&endTimestamp=2024-06-30T15%3A35%3A00Z&duration={duration}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` ### Response #### Success Response (200) - **dataExpand** (Array of object) - Generic response data, specific schema depends on the endpoint - **httpStatusCode** (integer) - HTTP status code - **traceId** (string) - Request trace identifier #### Response Example ```json { "dataExpand": [ { "timestamp": "2024-06-30T13:35:00Z", "download_speed": 100000000, "upload_speed": 50000000, "latency": 15 } ], "httpStatusCode": 200, "traceId": "a1b2c3d4e5f6" } ``` ``` -------------------------------- ### Get SD-WAN Config Status using cURL Source: https://developer.ui.com/site-manager/v1.0.0/getsdwanconfigstatus Retrieves the status of a specific SD-WAN configuration using a cURL command. Requires the configuration ID and an API key for authentication. The response includes deployment progress, errors, and associated hubs. ```shell curl -L -g "https://api.ui.com/v1/sd-wan-configs/{id}/status" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### List Sites Source: https://developer.ui.com/site-manager/v1.0.0/listsites Retrieves a list of all sites associated with the UI account making the API call. This endpoint is useful for getting an overview of all available sites managed by your UniFi Network application. ```APIDOC ## GET /v1/sites ### Description Retrieves a list of all sites (from hosts running the UniFi Network application) associated with the UI account making the API call. ### Method GET ### Endpoint `/v1/sites` ### Query Parameters - **pageSize** (string) - Optional - Number of items to return per page - **nextToken** (string) - Optional - Token for pagination to retrieve the next set of results ### Response #### Success Response (200) - **code** (any) - Error code from upstream - **dataExpand** (Array of object) - Generic response data, specific schema depends on the endpoint - **httpStatusCode** (integer) - HTTP status code - **traceId** (string) - Request trace identifier - **nextToken** (string) - Pagination token for fetching the next set of results #### Response Example ```json { "dataExpand": [ { "_id": "602232a870250000000006c5", "name": "Site 1", "state": "running", "version": "6.5.62", "firmware": "6.5.62", "is_default": true, "unifi_os_migration_state": "none", "cloud_key_gen": "gen2", "device_count": 5, "uptime": 123456, "cpu": 10, "memory": 20, "disk": 30, "network_count": 3, "ssid_count": 5, "client_count": 100, "rogue_ap_count": 0, "wlan_count": 4, "hotspot_count": 0, "alarm_count": 0, "inform_url": "https://192.168.1.1:8443", "last_backup": "2023-10-27T10:00:00Z", "created_at": "2023-10-27T09:00:00Z", "updated_at": "2023-10-27T10:00:00Z" } ], "meta": { "rc": 0, "message": "OK" }, "nextToken": "602232A870250000000006C514FF00000000073DD8DB000000006369FDA2:1467082514" } ``` ``` -------------------------------- ### List Hosts using Go Source: https://developer.ui.com/site-manager/v1.0.0/listhosts Demonstrates how to call the UniFi API's /v1/hosts endpoint using the Go programming language. This snippet shows how to construct the request and handle the response. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.ui.com/v1/hosts?pageSize=10&nextToken=602232A870250000000006C514FF00000000073DD8DB000000006369FDA2%3A1467082514" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Accept", "application/json") req.Header.Add("X-API-Key", "") client := &http.Client{} res, err := client.Do(req) if err != nil { panic(err) } defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### List Hosts using Python Source: https://developer.ui.com/site-manager/v1.0.0/listhosts A Python script demonstrating how to interact with the UniFi API to list hosts. It includes setting up the request with headers and printing the response. ```python import requests url = "https://api.ui.com/v1/hosts" params = { "pageSize": "10", "nextToken": "602232A870250000000006C514FF00000000073DD8DB000000006369FDA2%3A1467082514" } headers = { "Accept": "application/json", "X-API-Key": "" } response = requests.get(url, params=params, headers=headers) print(response.status_code) print(response.json()) ``` -------------------------------- ### List SD-WAN Configurations (cURL) Source: https://developer.ui.com/site-manager/v1.0.0/listsdwanconfigs Retrieves a list of all SD-WAN configurations using a cURL command. Requires an API key for authentication. The response is in JSON format. ```shell curl -L "https://api.ui.com/v1/sd-wan-configs" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### List SD-WAN Configs Source: https://developer.ui.com/site-manager/v1.0.0/listsdwanconfigs Retrieves a list of all SD-WAN configurations associated with the UI account making the API call. ```APIDOC ## GET /v1/sd-wan-configs ### Description Retrieves a list of all SD-WAN configurations associated with the UI account making the API call. ### Method GET ### Endpoint `/v1/sd-wan-configs` ### Parameters #### Query Parameters - **dataExpand** (string) - Optional - Used to expand the response data. ### Request Example ```bash curl -L "https://api.ui.com/v1/sd-wan-configs" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` ### Response #### Success Response (200) - **data** (Array of object) - Generic response data, specific schema depends on the endpoint. - **httpStatusCode** (integer) - HTTP status code. - **traceId** (string) - Request trace identifier. #### Response Example ```json { "data": [ { "id": "sdwan_config_1", "name": "Config A", "status": "active" }, { "id": "sdwan_config_2", "name": "Config B", "status": "inactive" } ], "httpStatusCode": 200, "traceId": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ``` -------------------------------- ### Retrieve Hosts using API Key (cURL) Source: https://developer.ui.com/site-manager This snippet demonstrates how to retrieve a list of hosts from the UniFi Site Manager API using cURL. It requires an API key to be included in the 'X-API-KEY' header for authentication. The 'Accept' header is set to 'application/json' to specify the desired response format. ```shell curl -X GET 'https://api.ui.com/v1/hosts' \ -H 'X-API-KEY: YOUR_API_KEY' \ -H 'Accept: application/json' ``` -------------------------------- ### Query ISP Metrics using cURL Source: https://developer.ui.com/site-manager/v1.0.0/queryispmetrics This snippet demonstrates how to retrieve ISP metrics data using cURL. It requires an API key and specifies query parameters like time intervals and site information. Note that partial access to sites may result in a partial success status. ```bash curl -L -g "https://api.ui.com/v1/isp-metrics/{type}/query" \ -H "Accept: application/json" \ -H "X-API-Key: " \ -H "Content-Type: application/json" \ -d "{ \"sites\": [ { \"beginTimestamp\": \"2024-06-30T13:35:00Z\", \"hostId\": \"900A6F0030110000000000000000000000000000000000000000000000000000:123456789\", \"endTimestamp\": \"2024-06-30T15:35:00Z\", \"siteId\": \"661900ae6aec8f548d49fd54\" } ] }" ``` -------------------------------- ### List Hosts Source: https://developer.ui.com/site-manager/v1.0.0/listhosts Retrieves a list of all hosts associated with the UI account making the API call. Supports pagination. ```APIDOC ## GET /v1/hosts ### Description Retrieves a list of all hosts associated with the UI account making the API call. The structure of `userData` and `reportedState` fields may vary depending on the UniFi OS or Network Server version. ### Method GET ### Endpoint `/v1/hosts` ### Parameters #### Query Parameters - **pageSize** (string) - Optional - Number of items to return per page - **nextToken** (string) - Optional - Token for pagination to retrieve the next set of results ### Request Example ```json { "example": "curl -L \"https://api.ui.com/v1/hosts?pageSize=10&nextToken=602232A870250000000006C514FF00000000073DD8DB000000006369FDA2%3A1467082514\" \ -H \"Accept: application/json\" \ -H \"X-API-Key: \"" } ``` ### Response #### Success Response (200) - **code** (any) - Error code from upstream - **dataExpand** (Array of object) - Generic response data, specific schema depends on the endpoint - **httpStatusCode** (integer) - HTTP status code - **traceId** (string) - Request trace identifier - **nextToken** (string) - Pagination token for fetching the next set of results #### Response Example ```json { "example": "{\n \"data\": [\n {\n \"host\": \"192.168.1.1\",\n \"mac\": \"AA:BB:CC:DD:EE:FF\",\n \"version\": \"6.5.62\"\n }\n ],\n \"meta\": {\n \"total\": 1,\n \"nextToken\": \"some_next_token\"\n }\n}" } ``` ``` -------------------------------- ### Retrieve ISP Metrics (cURL) Source: https://developer.ui.com/site-manager/v1.0.0/getispmetrics This snippet demonstrates how to retrieve ISP metrics data using cURL. It specifies the type of interval (e.g., '5m' or '1h'), and optionally allows filtering by timestamp or duration. Ensure you replace placeholders like '{type}', '{duration}', and '' with your actual values. ```bash curl -L -g "https://api.ui.com/v1/isp-metrics/{type}?beginTimestamp=2024-06-30T13%3A35%3A00Z&endTimestamp=2024-06-30T15%3A35%3A00Z&duration={duration}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### POST /v1/isp-metrics/{type}/query Source: https://developer.ui.com/site-manager/v1.0.0/queryispmetrics Retrieves ISP metrics data based on specific query parameters. Supports 5-minute and 1-hour interval metrics. ```APIDOC ## POST /v1/isp-metrics/{type}/query ### Description Retrieves ISP metrics data based on specific query parameters. 5-minute interval metrics are available for at least 24 hours, and 1-hour interval metrics are available for at least 30 days. ### Method POST ### Endpoint `/v1/isp-metrics/{type}/query` ### Parameters #### Path Parameters - **type** (string) - Required - Specifies whether metrics are returned using `5m` or `1h` intervals #### Query Parameters None #### Request Body - **sites** (array of object) - Required - An array of site objects, each containing `beginTimestamp`, `hostId`, `endTimestamp`, and `siteId`. - **beginTimestamp** (string) - Required - The start of the time range for the query. - **hostId** (string) - Required - The unique identifier for the host. - **endTimestamp** (string) - Required - The end of the time range for the query. - **siteId** (string) - Required - The identifier of the site. ### Request Example ```json { "sites": [ { "beginTimestamp": "2024-06-30T13:35:00Z", "hostId": "900A6F00301100000000074A6BA90000000007A3387E0000000063EC9853:123456789", "endTimestamp": "2024-06-30T15:35:00Z", "siteId": "661900ae6aec8f548d49fd54" } ] } ``` ### Response #### Success Response (200) - **dataExpand** (object) - Generic response data, specific schema depends on the endpoint. - **httpStatusCode** (integer) - HTTP status code. - **traceId** (string) - Request trace identifier. #### Response Example ```json { "dataExpand": {}, "httpStatusCode": 200, "traceId": "some-trace-id" } ``` #### Error Responses - **400**: Bad Request - **401**: Unauthorized - **429**: Too Many Requests - **500**: Internal Server Error - **502**: Bad Gateway (Returned if the UI account lacks access to all requested sites) **Note:** If partial access is granted, the response will include `status: partialSuccess`. ``` -------------------------------- ### List Devices Source: https://developer.ui.com/site-manager/v1.0.0/listdevices Retrieves a list of UniFi devices managed by hosts where the UI account making the API call is the owner or a super admin. ```APIDOC ## GET /v1/devices ### Description Retrieves a list of UniFi devices managed by hosts where the UI account making the API call is the owner or a super admin. ### Method GET ### Endpoint `/v1/devices` ### Parameters #### Query Parameters - **hostIds[]** (Array of string) - Optional - List of host IDs to filter the results - **time** (string) - Optional - Last processed timestamp of devices in RFC3339 format - **pageSize** (string) - Optional - Number of items to return per page - **nextToken** (string) - Optional - Token for pagination to retrieve the next set of results ### Request Example ```curl curl -L -g "https://api.ui.com/v1/devices?hostIds[]=900A6F00301100000000074A6BA90000000007A3387E0000000063EC9853%3A123456789%2C900A6F00301100000000074A6BA90000000007A3387E0000000063EC9853%3A987654321&time=2025-10-30T01%3A52%3A51Z&pageSize=10&nextToken=602232A870250000000006C514FF00000000073DD8DB000000006369FDA2%3A1467082514" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` ### Response #### Success Response (200) - **code** (any) - Error code from upstream - **data** (Array of object) - Generic response data, specific schema depends on the endpoint - **httpStatusCode** (integer) - HTTP status code - **traceId** (string) - Request trace identifier - **nextToken** (string) - Pagination token for fetching the next set of results #### Response Example ```json { "data": [ { "host": { "hostId": "900A6F00301100000000074A6BA90000000007A3387E0000000063EC9853:123456789" }, "device": { "uid": "some_device_uid", "mac": "AA:BB:CC:DD:EE:FF", "model": "UAP-AC-PRO", "version": "5.43.35.12675" } } ], "meta": { "nextToken": "some_next_token" } } ``` ``` -------------------------------- ### Response Formats Source: https://developer.ui.com/site-manager/v1.0.0/responseformat Details the standard JSON structure for API responses, covering both successful and error cases. ```APIDOC ## Response Format All Site Manager API responses follow a consistent JSON structure to ensure predictable handling across different endpoints. ### Success Response Structure A successful API response will have the following format: ```json { "data": [], "httpStatusCode": 200, "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` * The `data` object/array contains the actual response payload, which varies by endpoint. * The `httpStatusCode` field indicates the HTTP status of the response (usually 200 for success). * The `traceId` is a unique identifier for the request useful for troubleshooting. ### Error Response Structure All error responses follow this consistent format: ```json { "code": "NOT_FOUND", "httpStatusCode": 404, "message": "thing not found: 942A6F00301100000000074A6BA90000000007A3387E0000000063EC9853:714694", "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` * `code`: A machine-readable error code (uppercase string) * `httpStatusCode`: The HTTP status code (as a number) * `message`: A detailed description of the error * `traceId`: A unique identifier for the request (useful for troubleshooting). ### Common Error Codes | HTTP Status | Error Code | Description | Example Message | |-------------|---------------|------------------------------------------------------------|---------------------------------------------------------------------------------| | 400 | BAD_REQUEST | The request was improperly formatted or contained invalid parameters | "invalid request parameters" | | 401 | UNAUTHORIZED | Authentication failed or credentials are missing | "unauthorized" | | 403 | FORBIDDEN | The authenticated user lacks permission to access the resource | "insufficient permissions" | | 404 | NOT_FOUND | The requested resource does not exist | "thing not found: {id}" | | 429 | RATE_LIMIT | The request exceeds the rate limit | "rate limit exceeded, retry after 5.372786998s" | | 500 | SERVER_ERROR | An unexpected error occurred on the server | "failed to get resource by ID" | | 502 | BAD_GATEWAY | The server received an invalid response from an upstream server | "bad gateway" | ### Handling Errors When handling errors from the API, we recommend: 1. **Check the HTTP status code** first to determine the general category of error 2. **Parse the error code** for programmatic handling of specific error conditions 3. **Log the traceId** for all errors to assist with troubleshooting 4. **Implement retries** with exponential backoff for 429 and 5xx errors 5. **Extract retry information** from the header for rate limit errors 6. **Display user-friendly messages** based on the error's message For rate limit errors, parse the retry time from the header and wait at least that long before retrying. ``` -------------------------------- ### UniFi API Error Response Structure Source: https://developer.ui.com/site-manager/v1.0.0/responseformat Outlines the consistent JSON format for API error responses. It includes a machine-readable 'code', the 'httpStatusCode', a detailed 'message', and a 'traceId' for troubleshooting. This structure allows for programmatic handling of different error scenarios. ```json { "code": "NOT_FOUND", "httpStatusCode": 404, "message": "thing not found: 942A6F00301100000000074A6BA90000000007A3387E0000000063EC9853:714694", "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` -------------------------------- ### UniFi API Success Response Structure Source: https://developer.ui.com/site-manager/v1.0.0/responseformat Defines the standard JSON structure for successful API responses. It includes a 'data' field for the payload, an 'httpStatusCode', and a 'traceId' for tracking. The 'data' field's content varies based on the specific API endpoint. ```json { "data": [], "httpStatusCode": 200, "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.