### GET /v1/hosts Example Source: https://developer.ui.com/site-manager-api/gettingstarted An example of using the API key in a GET request to retrieve host information. This shows how to include the API key in the X-API-KEY header. ```APIDOC ## GET /v1/hosts ### Description Retrieves a list of hosts. ### Method GET ### Endpoint https://api.ui.com/v1/hosts ### Headers - **X-API-KEY**: YOUR_API_KEY (string) - Required - Your unique API key for authentication. - **Accept**: application/json ### Request Example ``` curl -X GET 'https://api.ui.com/v1/hosts' \ -H 'X-API-KEY: YOUR_API_KEY' \ -H 'Accept: application/json' ``` ### Response #### Success Response (200) - Returns a JSON array of host objects. #### Response Example ```json [ { "id": "host123", "name": "Example Host", "status": "online" } ] ``` ``` -------------------------------- ### Get Site SD-WAN Config API Request (Go) Source: https://developer.ui.com/site-manager-api/get-sd-wan-config-by-id This Go example demonstrates how to fetch a site's SD-WAN configuration using the `net/http` package. It constructs the request with the necessary headers, including the API key, and sends a GET request. The example includes basic error handling for the HTTP request and response. ```go package main import ( "fmt" "io/ioutil" "net/http" "strings" ) func main() { apiKey := "" configId := ":id" // Replace with the actual config ID url := fmt.Sprintf("https://api.ui.com/ea/sd-wan-configs/%s", configId) 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 } if resp.StatusCode != http.StatusOK { fmt.Printf("Error: %s - %s\n", resp.Status, string(body)) return } fmt.Println(string(body)) } ``` -------------------------------- ### 200 OK - Example Response with User Data Source: https://developer.ui.com/site-manager-api/get-host-by-id An example of a 200 OK response containing detailed user and device information. This includes hardware details, IP address, owner status, registration and connection times, and extensive user-specific data like application permissions and features. ```json { "data": { "id": "70A7419783ED0000000006797F060000000006C719490000000062ABD4EA:1261206302", "hardwareId": "e5bf13cd-98a7-5a96-9463-0d65d78cd3a4", "type": "ucore", "ipAddress": "220.130.137.169", "owner": true, "isBlocked": false, "registrationTime": "", "lastConnectionStateChange": "2024-04-16T02:52:54.193Z", "latestBackupTime": "", "userData": { "apps": [ "users" ], "consoleGroupMembers": [ { "mac": "70A7419783ED", "role": "UNADOPTED", "roleAttributes": { "applications": { "access": { "owned": false, "required": false, "supported": true }, "connect": { "owned": false, "required": false, "supported": true }, "innerspace": { "owned": false, "required": false, "supported": true }, "network": { "owned": false, "required": true, "supported": true }, "protect": { "owned": false, "required": false, "supported": true }, "talk": { "owned": false, "required": false, "supported": true } }, "candidateRoles": [ "PRIMARY" ], "connectedState": "CONNECTED", "connectedStateLastChanged": "2024-04-16T02:52:54.193Z" }, "sysId": 59925 } ], "controllers": [ "network", "protect", "access", "talk", "connect", "innerspace" ], "email": "example@ui.com", "features": { "deviceGroups": true, "floorplan": { "canEdit": true, "canView": true }, "manageApplications": true, "notifications": true, "pion": true, "webrtc": { "iceRestart": true, "mediaStreams": true, "twoWayAudio": true } }, "fullName": "UniFi User", "localId": "d4eb483d-98a7-438b-abe1-f46628dff73f", "permissions": { "access.management": [ "admin" ], "connect.management": [ "admin" ], "innerspace.management": [ "admin" ], "network.management": [ "admin" ], "protect.management": [ "admin" ], "system.management.location": [ "admin" ], "system.management.user": [ "admin" ], "talk.management": [ "admin" ] }, "role": "owner", "roleId": "c349b256-98a7-44ab-b8a1-13c437ea7742", "status": "ACTIVE" }, "reportedState": null }, "httpStatusCode": 200, "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` -------------------------------- ### Example SD-WAN Configuration Response - JSON Source: https://developer.ui.com/site-manager-api/get-sd-wan-config-by-id This is an example JSON response for a successfully retrieved SD-WAN configuration. It demonstrates a 'single' variant configuration with specific settings for spokes and one hub, including its associated network and routes. ```JSON { "data": { "id": "b344034f-2636-478c-8c7a-e3350f8ed37a", "name": "RS test", "type": "sdwan-hbsp", "variant": "single", "settings": { "hubsInterconnect": null, "spokeToHubTunnelsMode": "scalable", "spokesAutoScaleAndNatEnabled": true, "spokesAutoScaleAndNatRange": "172.16.0.0/12", "spokesIsolate": true, "spokeStandardSettingsEnabled": false, "spokeStandardSettingsValues": null, "spokeToHubRouting": "geo" }, "hubs": [ { "id": "9C05D6B1DA7100000000080A820B000000000877B4A4000000006634E113:779231894_670d14b2b4e979611b761866", "hostId": "9C05D6B1DA7100000000080A820B000000000877B4A4000000006634E113:779231894", "siteId": "670d14b2b4e979611b761866", "networkIds": [ "670d14deb4e979611b761880" ], "routes": [], "primaryWan": "WAN", "wanFailover": false } ], "spokes": [ { "id": "28704E43D00C0000000008339D3C0000000008A2F4D300000000669FE9E7:1731456649_670d153bf6db0d4204f8d150", "hostId": "28704E43D00C0000000008339D3C0000000008A2F4D300000000669FE9E7:1731456649", "siteId": "670d153bf6db0d4204f8d150", "networkIds": [], "routes": [ "172.16.1.0/24" ], "primaryWan": "WAN", "wanFailover": false } ] }, "httpStatusCode": 200, "traceId": "some-trace-id" } ``` -------------------------------- ### Get Site SD-WAN Config API Request (Python) Source: https://developer.ui.com/site-manager-api/get-sd-wan-config-by-id This Python example demonstrates how to fetch a site's SD-WAN configuration using the `requests` library. It includes setting the API key and making a GET request to the specified endpoint. Error handling for the response status code is recommended. ```python import requests api_key = "" config_id = ":id" # Replace with the actual config ID url = f"https://api.ui.com/ea/sd-wan-configs/{config_id}" headers = { "Accept": "application/json", "X-API-Key": api_key } response = requests.get(url, headers=headers) if response.status_code == 200: print(response.json()) elif response.status_code == 401: print("Unauthorized. Please check your API key.") else: print(f"Error: {response.status_code} - {response.text}") ``` -------------------------------- ### Get Site SD-WAN Config API Request (Node.js) Source: https://developer.ui.com/site-manager-api/get-sd-wan-config-by-id This Node.js example shows how to retrieve a site's SD-WAN configuration using the `node-fetch` library. It sets up the necessary headers, including the API key, and makes a GET request. Proper error handling based on the response status code should be implemented. ```javascript const fetch = require('node-fetch'); const apiKey = ''; const configId = ':id'; // Replace with the actual config ID const url = `https://api.ui.com/ea/sd-wan-configs/${configId}`; fetch(url, { method: 'GET', headers: { 'Accept': 'application/json', 'X-API-Key': apiKey } }) .then(response => { if (response.ok) { return response.json(); } else { throw new Error(`HTTP error! status: ${response.status}`); } }) .then(data => { console.log(data); }) .catch(error => { console.error('Error fetching config:', error); }); ``` -------------------------------- ### ISP Metrics API Request Example - CURL Source: https://developer.ui.com/site-manager-api/get-isp-metrics Provides an example of how to make a request to the ISP Metrics API using CURL. It shows the necessary URL, HTTP method, and headers, including the 'Accept' header for JSON and the 'X-API-Key' for authentication. ```curl curl -L 'https://api.ui.com/ea/isp-metrics/:type' \ -H 'Accept: application/json' \ -H 'X-API-Key: ' ``` -------------------------------- ### Config Not Found API Response Example (404) Source: https://developer.ui.com/site-manager-api/get-sd-wan-config-by-id This example shows the JSON response when a requested configuration is not found, resulting in a 404 HTTP status code. The response includes an error code, status, message, and trace ID. ```json { "code": "not_found", "httpStatusCode": 404, "message": "config not found", "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` -------------------------------- ### List SD-WAN Configurations (HTTP) Source: https://developer.ui.com/site-manager-api/list-sd-wan-configs This snippet demonstrates how to make an HTTP GET request to the SD-WAN configurations endpoint. It specifies the URL, required headers, and expected response types. This is a foundational example for interacting with the API. ```curl curl -L 'https://api.ui.com/ea/sd-wan-configs' \ -H 'Accept: application/json' \ -H 'X-API-Key: ' ``` -------------------------------- ### 200 OK Response Example for Site Manager API Source: https://developer.ui.com/site-manager-api/list-hosts Provides a concrete example of a 200 OK response from the Site Manager API, illustrating the format and typical values for device data, user data, and feature flags. This example includes detailed nested objects for user permissions, application roles, and device capabilities. ```json { "data": [ { "id": "70A7419783ED0000000006797F060000000006C719490000000062ABD4EA:1261206302", "hardwareId": "e5bf13cd-98a7-5a96-9463-0d65d78cd3a4", "type": "ucore", "ipAddress": "220.130.137.169", "owner": true, "isBlocked": false, "registrationTime": "", "lastConnectionStateChange": "2024-04-16T02:52:54.193Z", "latestBackupTime": "", "userData": { "apps": [ "users" ], "consoleGroupMembers": [ { "mac": "70A7419783ED", "role": "UNADOPTED", "roleAttributes": { "applications": { "access": { "owned": false, "required": false, "supported": true }, "connect": { "owned": false, "required": false, "supported": true }, "innerspace": { "owned": false, "required": false, "supported": true }, "network": { "owned": false, "required": true, "supported": true }, "protect": { "owned": false, "required": false, "supported": true }, "talk": { "owned": false, "required": false, "supported": true } }, "candidateRoles": [ "PRIMARY" ], "connectedState": "CONNECTED", "connectedStateLastChanged": "2024-04-16T02:52:54.193Z" }, "sysId": 59925 } ], "controllers": [ "network", "protect", "access", "talk", "connect", "innerspace" ], "email": "example@ui.com", "features": { "deviceGroups": true, "floorplan": { "canEdit": true, "canView": true }, "manageApplications": true, "notifications": true, "pion": true, "webrtc": { "iceRestart": true, "mediaStreams": true, "twoWayAudio": true } }, "fullName": "UniFi User", "localId": "d4eb483d-98a7-438b-abe1-f46628dff73f", "permissions": { "access.management": [ "admin" ], "connect.management": [ "admin" ], "innerspace.management": [ "admin" ], "network.management": [ "admin" ], "protect.management": [ "admin" ], "system.management.location": [ "admin" ], "system.management.user": [ "admin" ], "talk.management": [ "admin" ] } } } ], "httpStatusCode": 200, "traceId": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "nextToken": "next-page-token-12345" } ``` -------------------------------- ### List Hosts API Request - Go Source: https://developer.ui.com/site-manager-api/list-hosts Example of how to list hosts using the UI.com API with Go. This code demonstrates making an HTTP GET request to the '/v1/hosts' endpoint using the standard 'net/http' package. It sets the necessary 'Accept' and 'X-API-Key' headers for the request. ```go package main import ( "fmt" "io/ioutil" "net/http" "log" ) func main() { apiKey := "" url := "https://api.ui.com/v1/hosts" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { log.Fatalf("Failed to create request: %v", err) } req.Header.Add("Accept", "application/json") req.Header.Add("X-API-Key", apiKey) resp, err := client.Do(req) if err != nil { log.Fatalf("Failed to execute request: %v", err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatalf("Failed to read response body: %v", err) } if resp.StatusCode == http.StatusOK { fmt.Println("Hosts listed successfully:") fmt.Println(string(body)) } else { fmt.Printf("Error: %d\n", resp.StatusCode) fmt.Println(string(body)) } } ``` -------------------------------- ### API Error Response Examples Source: https://developer.ui.com/site-manager-api/get-sd-wan-config-status These examples illustrate common error responses from the UI.com API. They cover scenarios such as unauthorized access (401), resource not found (404), rate limiting (429), internal server errors (500), and bad gateway responses (502). Each example includes the HTTP status code, a trace ID, and a descriptive message. ```json { "code": "unauthorized", "httpStatusCode": 401, "message": "unauthorized", "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` ```json { "code": "not_found", "httpStatusCode": 404, "message": "config not found", "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` ```json { "code": "rate_limit", "httpStatusCode": 429, "message": "rate limit exceeded, retry after 5.372786998s", "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` ```json { "code": "server_error", "httpStatusCode": 500, "message": "failed to get network cloud SD-WAN config status by ID", "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` ```json { "code": "bad_gateway", "httpStatusCode": 502, "message": "bad gateway", "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` -------------------------------- ### Example Site Manager API Response Data Source: https://developer.ui.com/site-manager-api/get-sd-wan-config-status This is an example of the 'data' object from a Site Manager API response, illustrating populated fields for hubs and spokes. It shows specific network details, WAN status, and connection tunnel status. ```json { "data": { "id": "", "fingerprint": "85d521a1b3c8992f", "updatedAt": 1739454923342, "hubs": [ { "id": "9C05D6B1DA7100000000080A820B000000000877B4A4000000006634E113:779231894_670d14b2b4e979611b761866", "hostId": "9C05D6B1DA7100000000080A820B000000000877B4A4000000006634E113:779231894", "siteId": "670d14b2b4e979611b761866", "name": "Marlind's UDM SE", "primaryWanStatus": { "ip": "194.22.30.166", "latency": 1, "internetIssues": [], "wanId": "WAN" }, "secondaryWanStatus": { "ip": "", "latency": null, "internetIssues": null, "wanId": "" }, "errors": [], "warnings": [], "numberOfTunnelsUsedByOtherFeatures": 0, "networks": [ { "networkId": "670d14deb4e979611b761880", "name": "Default", "errors": [], "warnings": [] } ], "routes": [], "applyStatus": "OK" } ], "spokes": [ { "id": "28704E43D00C0000000008339D3C0000000008A2F4D300000000669FE9E7:1731456649_670d153bf6db0d4204f8d150", "hostId": "28704E43D00C0000000008339D3C0000000008A2F4D300000000669FE9E7:1731456649", "siteId": "670d153bf6db0d4204f8d150", "name": "Marlind's UDR", "primaryWanStatus": { "ip": "10.0.1.142", "latency": 1, "internetIssues": [], "wanId": "WAN" }, "secondaryWanStatus": { "ip": "", "latency": null, "internetIssues": null, "wanId": "" }, "errors": [], "warnings": [], "numberOfTunnelsUsedByOtherFeatures": 0, "networks": [], "routes": [ { "routeValue": "172.16.1.0/24", "errors": [], "warnings": [] } ], "connections": [ { "hubId": "9C05D6B1DA7100000000080A820B000000000877B4A4000000006634E113:779231894_670d14b2b4e979611b761866", "tunnels": [ { "spokeWanId": "WAN", "hubWanId": "WAN", "status": "connected" } ] } ], "applyStatus": "OK" }, { "id": "F4E2C61FA6000000000007D5831A00000000083CEEC600000000655DA309:763649230_66b5f02af5521234f6f28a23", "hostId": "F4E2C61FA6000000000007D5831A00000000083CEEC600000000655DA309:763649230", "siteId": "66b5f02af5521234f6f28a23", "name": "AG UCG Ultra STG", "primaryWanStatus": { "ip": "10.35.87.53", "latency": 2, "internetIssues": [], "wanId": "WAN" }, "secondaryWanStatus": { "ip": "", "latency": null, "internetIssues": null, "wanId": "" } } ], "lastGeneratedAt": 0, "generateStatus": [ "OK", "GENERATING", "GENERATE_FAILED" ], "errors": [], "warnings": [] }, "httpStatusCode": 0, "traceId": "string" } ``` -------------------------------- ### List Sites - Node.js Source: https://developer.ui.com/site-manager-api/list-sites This Node.js example utilizes the 'axios' library to make a GET request to the UI.com API for listing sites. It shows how to configure request headers for API key and content type. ```javascript const axios = require('axios'); const apiKey = ''; axios.get('https://api.ui.com/v1/sites', { headers: { 'Accept': 'application/json', 'X-API-Key': apiKey } }) .then(response => { console.log(response.data); }) .catch(error => { console.error(`Error: ${error.response.status}`); }); ``` -------------------------------- ### 200 OK Example Response with Site Metrics Source: https://developer.ui.com/site-manager-api/query-isp-metrics An example of a successful API response (HTTP 200) returning site metrics. This demonstrates how the metric data, including WAN performance, is populated with actual values. ```json { "data": { "metrics": [ { "metricType": "5m", "periods": [ { "data": { "wan": { "avgLatency": 1, "download_kbps": 0, "downtime": 0, "ispAsn": "12578", "ispName": "ISP", "maxLatency": 2, "packetLoss": 0, "upload_kbps": 0, "uptime": 100 } }, "metricTime": "2024-06-30T13:35:00Z", "version": "1" } ], "hostId": "900A6F00301100000000074A6BA90000000007A3387E0000000063EC9853:123456789", "siteId": "661900ae6aec8f548d49fd54" } ] }, "httpStatusCode": 200, "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` -------------------------------- ### ISP Metrics API 200 OK Response Schema and Example Source: https://developer.ui.com/site-manager-api/get-isp-metrics Details the structure of a successful API response for ISP metrics. The schema includes generic data with specific metrics like average latency, download/upload speeds, packet loss, and uptime, along with host and site identifiers. It also includes the HTTP status code and a trace ID for request tracking. The example provides sample data for these fields. ```json { "data": [ { "metricType": "string", "periods": [ { "data": { "wan": { "avgLatency": 0, "download_kbps": 0, "downtime": 0, "ispAsn": "string", "ispName": "string", "maxLatency": 0, "packetLoss": 0, "upload_kbps": 0, "uptime": 0 } }, "metricTime": "2024-07-29T15:51:28.071Z", "version": "string" } ], "hostId": "string", "siteId": "string" } ], "httpStatusCode": 0, "traceId": "string" } ``` ```json { "data": [ { "metricType": "5m", "periods": [ { "data": { "wan": { "avgLatency": 1, "download_kbps": 0, "downtime": 0, "ispAsn": "12578", "ispName": "ISP", "maxLatency": 2, "packetLoss": 0, "upload_kbps": 0, "uptime": 100 } }, "metricTime": "2024-06-30T13:35:00Z", "version": "1" } ], "hostId": "900A6F00301100000000074A6BA90000000007A3387E0000000063EC9853:123456789", "siteId": "661900ae6aec8f548d49fd54" } ], "httpStatusCode": 200, "traceId": "a7dc15e0eb4527142d7823515b15f87d" } ``` -------------------------------- ### List Hosts API Request - Node.js Source: https://developer.ui.com/site-manager-api/list-hosts Example of how to list hosts using the UI.com API with Node.js. This snippet shows how to make an HTTP GET request to the '/v1/hosts' endpoint using the 'axios' library. It includes essential headers for authentication ('X-API-Key') and content negotiation ('Accept'). ```javascript const axios = require('axios'); const apiKey = ''; const url = 'https://api.ui.com/v1/hosts'; const headers = { 'Accept': 'application/json', 'X-API-Key': apiKey }; axios.get(url, { headers }) .then(response => { console.log('Hosts listed successfully:'); console.log(response.data); }) .catch(error => { if (error.response) { console.error(`Error: ${error.response.status}`); console.error(error.response.data); } else { console.error('Error:', error.message); } }); ``` -------------------------------- ### List Devices API Request Examples Source: https://developer.ui.com/site-manager-api/list-devices Demonstrates how to make an API request to list devices using various client implementations. It includes authentication methods (API Key) and common parameters. Note the 'X-API-Key' header for authentication. ```curl curl -L 'https://api.ui.com/v1/devices' \\ -H 'Accept: application/json' \\ -H 'X-API-Key: ' ``` ```python import requests\n\nurl = "https://api.ui.com/v1/devices"\nheaders = {\n "Accept": "application/json",\n "X-API-Key": ""\n}\n\nresponse = requests.get(url, headers=headers)\nprint(response.json()) ``` ```nodejs const axios = require('axios');\n\nconst url = 'https://api.ui.com/v1/devices';\nconst headers = {\n 'Accept': 'application/json',\n 'X-API-Key': ''\n};\n\naxios.get(url, { headers: headers })\n .then(response => {\n console.log(response.data);\n })\n .catch(error => {\n console.error(error);\n }); ``` ```go package main\n\nimport (\n\t"fmt"\n\t"net/http"\n\t"io/ioutil"\n)\n\nfunc main() {\n\tclient := &http.Client{}\n\treq, err := http.NewRequest("GET", "https://api.ui.com/v1/devices", nil)\n\tif err != nil {\n\t\tfmt.Println("Error creating request:", err)\n\t\treturn\n\t}\n\n\treq.Header.Add("Accept", "application/json")\n\treq.Header.Add("X-API-Key", "")\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\tfmt.Println("Error sending request:", err)\n\t\treturn\n\t}\n\n\ defer resp.Body.Close()\n\tbody, err := ioutil.ReadAll(resp.Body)\n\tif err != nil {\n\t\tfmt.Println("Error reading response body:", err)\n\t\treturn\n\t}\n\n\tfmt.Println(string(body))\n} ``` -------------------------------- ### Query ISP Metrics API Request Examples Source: https://developer.ui.com/site-manager-api/query-isp-metrics Examples of how to query ISP metrics using the UI.com API. Includes cURL, Python, Node.js, and Go implementations. The request requires an API key and specifies site details such as begin and end timestamps, host ID, and site ID. ```curl curl -L 'https://api.ui.com/ea/isp-metrics/:type/query' \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -H 'X-API-Key: ' \ -d '{ "sites": [ { "beginTimestamp": "2024-07-29T15:51:28.071Z", "hostId": "string", "endTimestamp": "2024-07-29T15:51:28.071Z", "siteId": "string" } ] }' ``` ```python import requests url = "https://api.ui.com/ea/isp-metrics/:type/query" headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'X-API-Key': '' } payload = { "sites": [ { "beginTimestamp": "2024-07-29T15:51:28.071Z", "hostId": "string", "endTimestamp": "2024-07-29T15:51:28.071Z", "siteId": "string" } ] } response = requests.post(url, headers=headers, json=payload) print(response.json()) ``` ```nodejs const fetch = require('node-fetch'); const url = 'https://api.ui.com/ea/isp-metrics/:type/query'; const apiKey = ''; const payload = { "sites": [ { "beginTimestamp": "2024-07-29T15:51:28.071Z", "hostId": "string", "endTimestamp": "2024-07-29T15:51:28.071Z", "siteId": "string" } ] }; fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', 'X-API-Key': apiKey }, body: JSON.stringify(payload) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://api.ui.com/ea/isp-metrics/:type/query" apiKey := "" payload := map[string]interface{}{ "sites": []map[string]string{ { "beginTimestamp": "2024-07-29T15:51:28.071Z", "hostId": "string", "endTimestamp": "2024-07-29T15:51:28.071Z", "siteId": "string" } } } jsonPayload, err := json.Marshal(payload) if err != nil { fmt.Println("Error marshalling JSON:", err) return } req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonPayload)) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Set("Content-Type", "application/json") req.Header.Set("Accept", "application/json") req.Header.Set("X-API-Key", apiKey) client := &http.Client{} res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() var result map[string]interface{} err = json.NewDecoder(res.Body).Decode(&result) if err != nil { fmt.Println("Error decoding response:", err) return } fmt.Println(result) } ``` -------------------------------- ### Retrieve Host Information - Node.js Source: https://developer.ui.com/site-manager-api/get-host-by-id This Node.js example utilizes the `axios` library to make a GET request to the UI.com API for host information. It includes the required headers, such as the API key, and demonstrates how to process the response. ```javascript const axios = require('axios'); const apiKey = ''; const hostId = ''; const headers = { 'Accept': 'application/json', 'X-API-Key': apiKey }; const url = `https://api.ui.com/v1/hosts/${hostId}`; axios.get(url, { headers }) .then(response => { console.log(response.data); }) .catch(error => { console.error(`Error: ${error.response.status}`); console.error(error.response.data); }); ``` -------------------------------- ### API Authentication Source: https://developer.ui.com/site-manager-api/gettingstarted Describes the API key authentication method for accessing the Site Manager API. Securing the API key is essential for all requests. ```APIDOC ## Authentication An API Key serves as a unique identifier used to authenticate API requests. These keys are essential for securing access to your UniFi account and its associated devices. Each key is linked to the specific UI account that generated it, ensuring secure and personalized API interactions. ### Obtaining an API Key 1. Sign in to the UniFi Site Manager at unifi.ui.com. 2. Navigate to the API section from the left navigation bar. 3. Select \"Create API Key.\" 4. Copy the generated key and store it securely, as it will only be displayed once. 5. Ensure the key is properly hashed and securely stored. ### Use the API Key Incorporate the API key into the `X-API-Key` header for all requests. Follow the example provided, replacing `YOUR_API_KEY` with your actual API key. **Note:** The API key is currently read-only. When write endpoints become available, you'll be able to enable write access as needed, and the existing key won't be updated automatically. A manual update will be required. ``` -------------------------------- ### List SD-WAN Configurations (Node.js) Source: https://developer.ui.com/site-manager-api/list-sd-wan-configs This Node.js example uses the `axios` library to retrieve SD-WAN configurations. It demonstrates setting up request headers, including the API key, and logging the response or errors. This is suitable for backend services or scripts written in Node.js. ```javascript const axios = require('axios'); const apiKey = ''; const url = 'https://api.ui.com/ea/sd-wan-configs'; axios.get(url, { headers: { 'Accept': 'application/json', 'X-API-Key': apiKey } }) .then(response => { console.log('Success:', response.data); }) .catch(error => { if (error.response) { console.error('Error:', error.response.status, error.response.data); } else if (error.request) { console.error('Error:', 'No response received', error.request); } else { console.error('Error:', error.message); } }); ``` -------------------------------- ### 200 OK Response Schema and Examples Source: https://developer.ui.com/site-manager-api/list-devices This snippet details the schema and provides examples for a successful 200 OK response. It includes data on host devices and their managed devices, along with status and update information. The response structure is consistent across calls, but specific data will vary. ```json { "data": [ { "hostId": "string", "hostName": "string", "devices": [ { "id": "string", "mac": "string", "name": "string", "model": "string", "shortname": "string", "ip": "string", "productLine": "string", "status": "string", "version": "string", "firmwareStatus": "string", "updateAvailable": "string", "isConsole": true, "isManaged": true, "startupTime": "2024-07-29T15:51:28.071Z", "adoptionTime": "string", "note": "string" } ], "updatedAt": "2024-07-29T15:51:28.071Z" } ], "httpStatusCode": 0, "traceId": "string", "nextToken": "string" } ``` ```json { "data": [ { "hostId": "900A6F00301100000000074A6BA90000000007A3387E0000000063EC9853:123456789", "hostName": "unifi.yourdomain.com", "devices": [ { "id": "F4E2C6C23F13", "mac": "F4E2C6C23F13", "name": "unifi.yourdomain.com", "model": "UDM SE", "shortname": "UDMPROSE", "ip": "192.168.1.226", "productLine": "network", "status": "online", "version": "4.1.13", "firmwareStatus": "upToDate", "updateAvailable": null, "isConsole": true, "isManaged": true, "startupTime": "2024-06-19T13:41:43Z", "adoptionTime": null, "note": null, "uidb": { "guid": "0fd8c390-a0e8-4cb2-b93a-7b3051c83c46", "id": "e85485da-54c3-4906-8f19-3cef4116ff02", "images": { "default": "3008400039c483c496f4ad820242c447", "nopadding": "67b553529d0e523ca9dd4826076c5f3f", "topology": "8371ecdda1f00f1636a2eefadf0d7d47" } } } ], "updatedAt": "2025-06-17T02:45:58Z" } ], "httpStatusCode": 200, "traceId": "a7dc15e0eb4527142d7823515b15f87d", "nextToken": "ba8e384e-3308-4236-b344-7357657351ca" } ``` -------------------------------- ### List SD-WAN Configurations (Go) Source: https://developer.ui.com/site-manager-api/list-sd-wan-configs This Go program illustrates how to make a GET request to the SD-WAN configurations API. It utilizes the standard `net/http` package and handles the response, including JSON parsing and error checking. This is useful for Go-based applications requiring SD-WAN data. ```go package main import ( "encoding/json" "fmt" "io/ioutil" "log" "net/http" ) func main() { apiKey := "" url := "https://api.ui.com/ea/sd-wan-configs" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { log.Fatalf("Error creating request: %v", err) } req.Header.Add("Accept", "application/json") req.Header.Add("X-API-Key", apiKey) resp, err := client.Do(req) if err != nil { log.Fatalf("Error sending request: %v", err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatalf("Error reading response body: %v", err) } sif resp.StatusCode == http.StatusOK { var result map[string]interface{} if err := json.Unmarshal(body, &result); err != nil { log.Fatalf("Error unmarshaling JSON: %v", err) } fmt.Println("Success:", result) } else { fmt.Printf("Error: %d %s\n", resp.StatusCode, string(body)) } } ``` -------------------------------- ### Get Site SD-WAN Config API Request (CURL) Source: https://developer.ui.com/site-manager-api/get-sd-wan-config-by-id This example shows how to retrieve a site's SD-WAN configuration using a CURL command. It specifies the endpoint, required headers for authorization and content type, and a placeholder for the configuration ID. ```curl curl -L 'https://api.ui.com/ea/sd-wan-configs/:id' \ -H 'Accept: application/json' \ -H 'X-API-Key: ' ```