### Get Firewall Zone - Go Example Source: https://developer.ui.com/network/v10.1.68/getfirewallzone Example of how to retrieve a firewall zone using Go. This code snippet demonstrates making a GET request to the UniFi API endpoint. It requires the UniFi Connector and appropriate authentication. ```go // Go example not provided in the source text. ``` -------------------------------- ### Install ubiquiti.unifi_api Ansible Collection Source: https://developer.ui.com/network/v10.1.68/quick_start Downloads and installs the `ubiquiti.unifi_api` Ansible collection from a provided URL. This collection contains the necessary modules for interacting with the UniFi API. ```bash curl -L -o ubiquiti-unifi_api-latest.tar.gz https://apidoc-cdn.ui.com/ansible-module/ubiquiti-unifi_api-latest.tar.gz ansible-galaxy collection install ubiquiti-unifi_api-latest.tar.gz ``` -------------------------------- ### Get UniFi Application Info using Go Source: https://developer.ui.com/network/v10.1.68/getinfo Demonstrates how to retrieve general information about the UniFi Network application using Go. This example utilizes the UniFi Connector, requiring a firewall version of 5.0.3 or higher. ```go // Go example for retrieving application info would go here. ``` -------------------------------- ### List Devices Pending Adoption - Go.js Source: https://developer.ui.com/network/v10.1.68/getpendingdevicepage Demonstrates how to list devices pending adoption using Go.js. This example assumes the UniFi Connector is set up and the firmware is version 5.0.3 or newer. It shows how to make a GET request to the API endpoint. ```javascript // Go.js example for listing pending devices would go here. // This is a placeholder as the specific Go.js code was not provided in the input. ``` -------------------------------- ### Get Voucher Details using Go Source: https://developer.ui.com/network/v10.1.68/getvoucher This Go code snippet illustrates how to call the UniFi API to get voucher details. It assumes the use of a UniFi Connector and requires appropriate versions of the UniFi Controller firmware. The example shows how to construct the request and handle the JSON response. ```go // Go example omitted as it was not present in the provided text. ``` -------------------------------- ### Get UniFi Application Info using Ansible Source: https://developer.ui.com/network/v10.1.68/getinfo Illustrates how to retrieve general information about the UniFi Network application using Ansible. This example leverages the UniFi Connector and requires a firewall version of 5.0.3 or higher. ```yaml # Ansible example for retrieving application info would go here. ``` -------------------------------- ### Get UniFi Application Info using Python Source: https://developer.ui.com/network/v10.1.68/getinfo Provides a Python example for obtaining general information about the UniFi Network application. This method employs the UniFi Connector, which requires a firewall version of 5.0.3 or above. ```python # Python example for retrieving application info would go here. ``` -------------------------------- ### Quick Start: UniFi Network API with Ansible Source: https://developer.ui.com/network/v10.1.68/quick_start A basic Ansible playbook demonstrating how to use the `ubiquiti.unifi_api.network` module. It sets default variables like `base_url` and `token` for subsequent tasks and retrieves application information. ```yaml --- name: Using ubiquiti.unifi_api.network with this API hosts: localhost gather_facts: false vars: site_id: "12341234-5656-7878-9090-123456789012" # Replace with your site ID module_defaults: group/ubiquiti.unifi_api.common: base_url: "https://10.2.0.0" # Replace with your console IP token: "{{ lookup('env', 'UBIQUITI_API_TOKEN') }}" # export UBIQUITI_API_TOKEN=... in your shell tasks: - name: Get application info ubiquiti.unifi_api.network: path: "/v1/info" method: GET register: info - debug: var: site_info.data ``` -------------------------------- ### Create Traffic Matching List - Go Example Source: https://developer.ui.com/network/v10.1.68/createtrafficmatchinglist Demonstrates how to create a traffic matching list using Go. This example would typically involve making an HTTP POST request to the UniFi API endpoint with the necessary headers and JSON body. ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/traffic-matching-lists" apiKey := "" payload := map[string]string{ "type": "string", "name": "Allowed port list|Protected IP list", } jsonPayload, err := json.Marshal(payload) if err != nil { fmt.Println("Error marshaling JSON:", err) return } headers := map[string]string{ "Accept": "application/json", "X-API-Key": apiKey, "Content-Type": "application/json", } req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonPayload)) if err != nil { fmt.Println("Error creating request:", err) return } for key, value := range headers { req.Header.Set(key, value) } client := &http.Client{} res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() fmt.Println("Response Status:", res.Status) // Further processing of the response body can be done here } ``` -------------------------------- ### Get Voucher Details using Node.js Source: https://developer.ui.com/network/v10.1.68/getvoucher This Node.js example shows how to fetch voucher details from the UniFi API. It leverages the UniFi Connector and requires a firmware version of 5.0.3 or higher. The code would typically involve making an HTTP request and parsing the JSON response. ```javascript // Node.js example omitted as it was not present in the provided text. ``` -------------------------------- ### Get Application Info Source: https://developer.ui.com/network/v10.1.68/quick_start Retrieves general information about the UniFi Network application. ```APIDOC ## GET /v1/info ### Description Retrieves general information about the UniFi Network application. ### Method GET ### Endpoint /v1/info ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **data** (object) - Contains application information. #### Response Example ```json { "data": { "version": "10.1.68", "state": "running" } } ``` ``` -------------------------------- ### List Firewall Policies via cURL Source: https://developer.ui.com/network/v10.1.68/getfirewallpolicies Example of how to list firewall policies using cURL. This requires the UniFi Connector and a firewall version of 5.0.3 or later. It demonstrates making a GET request to the firewall policies endpoint with query parameters. ```bash curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/firewall/policies?offset={offset}&limit={limit}&filter={filter}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### List Local Sites - cURL Example Source: https://developer.ui.com/network/v10.1.68/getsiteoverviewpage This cURL command retrieves a paginated list of local sites managed by the UniFi Network application. It requires the console ID, offset, limit, and filter parameters. The UniFi Connector must be installed and have a firmware version of 5.0.3 or higher. ```shell curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites?offset={offset}&limit={limit}&filter={filter}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### List Traffic Matching Lists (Go, Node.js, Python, Ansible) Source: https://developer.ui.com/network/v10.1.68/gettrafficmatchinglists This snippet provides examples for retrieving traffic matching lists using Go, Node.js, Python, and Ansible. These examples leverage the UniFi Connector and require firmware version 5.0.3 or later. ```go // Go example not provided in the text. ``` ```javascript // Node.js example not provided in the text. ``` ```python # Python example not provided in the text. ``` ```yaml # Ansible example not provided in the text. ``` -------------------------------- ### Get UniFi Application Info using cURL Source: https://developer.ui.com/network/v10.1.68/getinfo Retrieves general information about the UniFi Network application using a cURL command. This example requires the UniFi Connector and a firewall version of 5.0.3 or higher. ```shell curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/info" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### Create Traffic Matching List - Ansible Example Source: https://developer.ui.com/network/v10.1.68/createtrafficmatchinglist An Ansible playbook example for creating a traffic matching list. This leverages the UniFi Connector module within Ansible to automate the process of configuring traffic matching lists on UniFi devices. ```yaml - name: Create Traffic Matching List unifi_connector: host: "{{ unifi_host }}" username: "{{ unifi_username }}" password: "{{ unifi_password }}" site_id: "{{ site_id }}" command: "create_traffic_matching_list" parameters: type: "string" # e.g., __PORTS, __IPV4_ADDRESSES, __IPV6_ADDRESSES name: "My Custom List" itemsExpand: [] # Optional: Add port matching details if needed ``` -------------------------------- ### Retrieve Connected Clients using Node.js Source: https://developer.ui.com/network/v10.1.68/getconnectedclientoverviewpage Example Node.js code to retrieve a paginated list of connected clients from a UniFi site. This snippet demonstrates how to make the GET request using a library like 'axios' and requires console ID, site ID, and authentication. ```javascript // Node.js example would go here, demonstrating the API call. // It would typically involve setting up request parameters and headers. // Example: // const axios = require('axios'); // const options = { // method: 'GET', // url: `https://api.ui.com/v1/connector/consoles/${consoleId}/proxy/network/integration/v1/sites/${siteId}/clients`, // params: { offset: '{offset}', limit: '{limit}', filter: '{filter}' }, // headers: { // 'Accept': 'application/json', // 'X-API-Key': '' // } // }; // axios(options).then(response => console.log(response.data)).catch(error => console.error(error)); ``` -------------------------------- ### Get Firewall Policy Ordering (Ansible) Source: https://developer.ui.com/network/v10.1.68/getfirewallpolicyordering Ansible module example for retrieving user-defined firewall policy ordering. This leverages the UniFi Connector and requires FW version >= 5.0.3. It accepts siteId, sourceFirewallZoneId, and destinationFirewallZoneId as parameters. ```yaml --- - name: Get Firewall Policy Ordering hosts: localhost tasks: - name: Retrieve firewall policy ordering ansible.network.unifi_firewall_policy_ordering: site_id: "{siteId}" source_firewall_zone_id: "{sourceFirewallZoneId}" destination_firewall_zone_id: "{destinationFirewallZoneId}" api_endpoint: "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy" api_key: "" register: firewall_policy_ordering - name: Print firewall policy ordering debug: var: firewall_policy_ordering.ordered_firewall_policy_ids ``` -------------------------------- ### Ansible: Idempotent Voucher Creation with UniFi API Source: https://developer.ui.com/network/v10.1.68/quick_start An Ansible example showing how to ensure voucher idempotency. It first checks if a voucher exists and only creates it if no existing voucher matches the specified name. ```yaml tasks: - name: Check if vouchers exist ubiquiti.unifi_api.network: path: "/v1/sites/{{ site_id }}/hotspot/vouchers" method: GET query: filter: "name.eq('test_voucher')" register: vouchers - name: Create vouchers if none exist when: vouchers.data.totalCount == 0 ubiquiti.unifi_api.network: path: "/v1/sites/{{ site_id }}/hotspot/vouchers" method: POST body: timeLimitMinutes: 3600 name: "test_voucher" ``` -------------------------------- ### GET /v1/info - Get Application Info Source: https://developer.ui.com/network/v10.1.68/getinfo Retrieve general information about the UniFi Network application, including the application version. ```APIDOC ## GET /v1/info ### Description Retrieve general information about the UniFi Network application. ### Method GET ### Endpoint /v1/info ### Parameters #### Query Parameters None #### Request Body None ### Request Example ``` curl -g "https://:8443/v1/info" ``` ### Response #### Success Response (200) - **applicationVersion** (string) - The current version of the UniFi Network application. #### Response Example ```json { "applicationVersion": "string" } ``` ``` -------------------------------- ### Connector - GET Source: https://developer.ui.com/network/v10.1.68/connectorget Forward GET requests to UniFi applications using RESTful HTTP methods. The request is proxied through api.ui.com to the remote console. ```APIDOC ## GET /v1/connector/consoles/{id}/*path ### Description Forward GET requests to UniFi applications using RESTful HTTP methods. The request is proxied through `api.ui.com` cloud endpoint to the remote console at `http://127.0.0.1/proxy/[path]` with GET method. ### Method GET ### Endpoint `/v1/connector/consoles/{id}/*path` ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the console. - **path** (string) - Required - The specific path within the UniFi application to access. ### Request Example ``` GET /v1/connector/consoles/CONSOLE_ID/network/integration/v1/sites ``` ### Response #### Success Response (200) On success, the upstream API response is passed through directly. #### Response Example ```json { "example": "Upstream API response" } ``` #### Error Responses - **400**: Bad Request - **401**: Unauthorized - **403**: Forbidden - **408**: Request Timeout - **429**: Too Many Requests - **500**: Internal Server Error - **502**: Bad Gateway ### Requirements - Console firmware version must be >= 5.0.3. - For non-organization API keys: Limited to API key owner's consoles only. - For organization API keys: Can access any console within the organization. ``` -------------------------------- ### List Adopted Devices - cURL Example Source: https://developer.ui.com/network/v10.1.68/getadopteddeviceoverviewpage Example cURL command to retrieve a paginated list of adopted devices from a UniFi site. It includes placeholders for console ID, site ID, offset, limit, filter, and API key. Ensure FW version is 5.0.3+ and UniFi Connector is used. ```shell curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/devices?offset={offset}&limit={limit}&filter={filter}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### Create Traffic Matching List - Python Example Source: https://developer.ui.com/network/v10.1.68/createtrafficmatchinglist Provides a Python example for creating a traffic matching list. This code uses the 'requests' library to make the HTTP POST request, sending the necessary headers and JSON payload to the UniFi API. ```python import requests import json url = "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/traffic-matching-lists" api_key = "" payload = { "type": "string", "name": "Allowed port list|Protected IP list" } headers = { "Accept": "application/json", "X-API-Key": api_key, "Content-Type": "application/json" } response = requests.post(url, headers=headers, data=json.dumps(payload)) print(f"Status Code: {response.status_code}") print(f"Response Body: {response.json()}") ``` -------------------------------- ### Get Firewall Zone - cURL Example Source: https://developer.ui.com/network/v10.1.68/getfirewallzone Example of how to retrieve a firewall zone using cURL. This request targets the UniFi API's proxy endpoint and requires API key authentication. Ensure the correct consoleId, siteId, and firewallZoneId are provided. ```shell curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/firewall/zones/{firewallZoneId}" \-H "Accept: application/json" \-H "X-API-Key: " ``` -------------------------------- ### Get ACL Rule Example - cURL Source: https://developer.ui.com/network/v10.1.68/getaclrule Example of how to retrieve an ACL rule using cURL. This requires the console ID, site ID, and ACL rule ID, along with an API key for authentication. Ensure the UniFi Connector requires FW version >= 5.0.3. ```bash curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/acl-rules/{aclRuleId}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### String Pattern Matching with 'like' Function Source: https://developer.ui.com/network/v10.1.68/filtering Provides examples of using the `like` function for pattern matching on string properties. Supports wildcards for flexible searching. ```text type.like('type.') name.like('guest*') ``` -------------------------------- ### Get Voucher Details using Python Source: https://developer.ui.com/network/v10.1.68/getvoucher This Python code snippet demonstrates how to interact with the UniFi API to retrieve voucher information. It requires the UniFi Connector and a compatible firmware version. The example would typically involve making an HTTP GET request and processing the resulting JSON data. ```python # Python example omitted as it was not present in the provided text. ``` -------------------------------- ### Install Python Dependencies for UniFi API Ansible Module Source: https://developer.ui.com/network/v10.1.68/quick_start Installs the required `httpx` and `urllib3` Python packages using pip. These libraries are necessary for the Ansible module to make HTTP requests to the UniFi API. ```bash pip install httpx urllib3 ``` -------------------------------- ### List Devices Pending Adoption - Python Source: https://developer.ui.com/network/v10.1.68/getpendingdevicepage Provides a Python example for fetching a list of devices pending adoption from the UniFi API. Ensure UniFi Connector is active and firmware is at least version 5.0.3. The code outlines the request structure including headers and URL parameters. ```python # Python example for listing pending devices would go here. # This is a placeholder as the specific Python code was not provided in the input. ``` -------------------------------- ### Get Network References (cURL) Source: https://developer.ui.com/network/v10.1.68/getnetworkreferences Example cURL command to retrieve references for a specific network. Requires the UniFi Connector and a firewall version of 5.0.3 or higher. The command takes the console ID, site ID, and network ID as parameters. ```shell curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/networks/{networkId}/references" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### Get ACL Rule Example - Response Schema Source: https://developer.ui.com/network/v10.1.68/getaclrule This is a sample JSON response for a successful retrieval of an ACL rule. It details the structure and types of data returned, including rule ID, name, description, action, index, and filter configurations. ```json { "type": "string", "id": "00000000-0000-0000-0000-000000000000", "enabled": true, "name": "string", "description": "string", "action": "ALLOW", "enforcingDeviceFilter": { "type": "string" }, "index": 0, "sourceFilter": null, "destinationFilter": null, "metadata": { "origin": "string" } } ``` -------------------------------- ### List WAN Interfaces using Go Source: https://developer.ui.com/network/v10.1.68/getwansoverviewpage Provides a Go language example for fetching WAN interface definitions from the UniFi API. This function requires the UniFi Connector and specifies parameters like siteId, offset, and limit. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/wans?offset={offset}&limit={limit}" 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", "") 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(string(body)) } ``` -------------------------------- ### Adopt Devices Source: https://developer.ui.com/network/v10.1.68/adoptdevice Adopts a device to a specified UniFi site. This endpoint allows for the programmatic addition of devices to your network. ```APIDOC ## POST /v1/sites/{siteId}/devices ### Description Adopt a device to a site. ### Method POST ### Endpoint `/v1/sites/{siteId}/devices` ### Parameters #### Path Parameters - **siteId** (string) - Required - The ID of the site to which the device will be adopted. #### Query Parameters None #### Request Body (Structure not provided in the input) ### Request Example ```json { "example": "request body" } ``` ### Response #### Success Response (200) - **Response Schema**: application/json #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Get ACL Rule Ordering with cURL Source: https://developer.ui.com/network/v10.1.68/getaclruleordering Retrieves the user-defined ACL rule ordering for a specific site using a cURL command. This example demonstrates how to make a GET request to the UniFi API endpoint, including necessary headers for authentication and content type. ```curl curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/acl-rules/ordering" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### Retrieve Connected Clients using Python Source: https://developer.ui.com/network/v10.1.68/getconnectedclientoverviewpage Example Python script to fetch connected clients from a UniFi site. This snippet illustrates making the API call using the 'requests' library, specifying necessary parameters like console ID, site ID, and authentication headers. ```python # Python example would go here, demonstrating the API call. # It would typically involve using the 'requests' library. # Example: # import requests # # url = f"https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/clients" # params = {'offset': '{offset}', 'limit': '{limit}', 'filter': '{filter}'} # headers = { # 'Accept': 'application/json', # 'X-API-Key': '' # } # # response = requests.get(url, params=params, headers=headers) # if response.status_code == 200: # print(response.json()) # else: # print(f"Error: {response.status_code}") ``` -------------------------------- ### Get Latest Adopted Device Statistics using Go Source: https://developer.ui.com/network/v10.1.68/getadopteddevicelateststatistics Provides an example of how to retrieve the latest real-time statistics for a specific adopted UniFi device using the Go programming language. This snippet would typically involve making an HTTP GET request to the specified API endpoint. ```go // Go code snippet for fetching device statistics would go here. // This would involve using the net/http package to make a GET request // to the API endpoint with appropriate headers and parameters. ``` -------------------------------- ### Get DNS Policy via cURL Source: https://developer.ui.com/network/v10.1.68/getdnspolicy Example of retrieving a specific DNS policy using cURL. This command requires the console ID, site ID, and DNS policy ID. It also needs an API key for authentication. Ensure your UniFi Connector firmware is version 5.0.3 or higher. ```curl curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/dns/policies/{dnsPolicyId}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### Get Voucher Details using Ansible Source: https://developer.ui.com/network/v10.1.68/getvoucher This Ansible module example shows how to integrate UniFi API calls for fetching voucher details into automated workflows. It utilizes the UniFi Connector and requires specific firmware versions. The module simplifies the process of retrieving voucher data within Ansible playbooks. ```yaml # Ansible example omitted as it was not present in the provided text. ``` -------------------------------- ### Get Adopted Device Details - cURL Example Source: https://developer.ui.com/network/v10.1.68/getadopteddevicedetails This cURL command demonstrates how to retrieve detailed information for a specific adopted UniFi device. It requires the console ID, site ID, device ID, and an API key. Ensure you are using a UniFi Connector with firmware version 5.0.3 or later. ```curl curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/devices/{deviceId}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### Execute Adopted Device Action - cURL Example Source: https://developer.ui.com/network/v10.1.68/executeadopteddeviceaction This cURL command demonstrates how to perform an action on a specific adopted UniFi device. It requires the console ID, site ID, device ID, an API key, and the action to be performed in the request body. The UniFi Connector must be version 5.0.3 or higher. ```shell curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/devices/{deviceId}/actions" \ -H "Accept: application/json" \ -H "X-API-Key: " \ -H "Content-Type: application/json" \ -d "{ \"action\": \"string\"}" ``` -------------------------------- ### List WAN Interfaces using Node.js Source: https://developer.ui.com/network/v10.1.68/getwansoverviewpage Illustrates how to retrieve WAN interface details using Node.js and the UniFi API. This example requires the UniFi Connector and uses parameters such as siteId, offset, and limit. ```javascript const fetch = require('node-fetch'); async function listWanInterfaces(siteId, offset, limit, apiKey, consoleId) { const url = `https://api.ui.com/v1/connector/consoles/${consoleId}/proxy/network/integration/v1/sites/${siteId}/wans?offset=${offset}&limit=${limit}`; try { const response = await fetch(url, { method: 'GET', headers: { 'Accept': 'application/json', 'X-API-Key': apiKey } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); return data; } catch (error) { console.error('Error fetching WAN interfaces:', error); return null; } } // Example usage: const siteId = '{siteId}'; const offset = 0; const limit = 10; const apiKey = ''; const consoleId = '{consoleId}'; listWanInterfaces(siteId, offset, limit, apiKey, consoleId).then(data => { if (data) { console.log(data); } }); ``` -------------------------------- ### List WAN Interfaces using cURL Source: https://developer.ui.com/network/v10.1.68/getwansoverviewpage Demonstrates how to list available WAN interface definitions for a given site using a cURL command. This requires the UniFi Connector and an API key. It takes siteId, offset, and limit as parameters. ```bash curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/wans?offset={offset}&limit={limit}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### Create Firewall Policy using cURL Source: https://developer.ui.com/network/v10.1.68/createfirewallpolicy Example of creating a firewall policy using cURL. This demonstrates the HTTP request structure, headers, and JSON payload required to interact with the UniFi API. Ensure the UniFi Connector version is 5.0.3 or higher. ```bash curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/firewall/policies" \ -H "Accept: application/json" \ -H "X-API-Key: " \ -H "Content-Type: application/json" \ -d "{ \"enabled\": true, \"name\": \"My firewall policy\", \"description\": \"A description for my firewall policy\", \"action\": { \"type\": \"string\" }, \"source\": { \"firewallZoneId\": \"string\", \"trafficFilter\": { \"type\": \"string\" } }, \"destination\": { \"firewallZoneId\": \"string\", \"trafficFilter\": { \"type\": \"string\" } }, \"ipProtocolScope\": { \"ipVersion\": \"string\" }, \"connectionStateFilter\": [ \"NEW\" ], \"ipsecFilter\": \"MATCH_ENCRYPTED\", \"loggingEnabled\": true, \"schedule\": { \"mode\": \"string\" }}" ``` -------------------------------- ### Get UniFi Application Info using Node.js Source: https://developer.ui.com/network/v10.1.68/getinfo Shows how to fetch general information about the UniFi Network application using Node.js. The UniFi Connector is used, necessitating a firewall version of 5.0.3 or greater. ```javascript // Node.js example for retrieving application info would go here. ``` -------------------------------- ### Get Firewall Policy Ordering (cURL) Source: https://developer.ui.com/network/v10.1.68/getfirewallpolicyordering Example call to retrieve user-defined firewall policy ordering using cURL. Requires FW version >= 5.0.3 and the UniFi Connector. It takes siteId, sourceFirewallZoneId, and destinationFirewallZoneId as parameters. ```curl curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/firewall/policies/ordering?sourceFirewallZoneId={sourceFirewallZoneId}&destinationFirewallZoneId={destinationFirewallZoneId}" \ -H "Accept: application/json" \ -H "X-API-Key: " ``` -------------------------------- ### Retrieve Connected Clients using cURL Source: https://developer.ui.com/network/v10.1.68/getconnectedclientoverviewpage Example cURL command to fetch a list of connected clients from a UniFi site. Requires the console ID, site ID, and optionally offset, limit, and filter parameters. An API key is necessary for authentication. ```bash curl -L -g "https://api.ui.com/v1/connector/consoles/{consoleId}/proxy/network/integration/v1/sites/{siteId}/clients?offset={offset}&limit={limit}&filter={filter}" \-H "Accept: application/json" \-H "X-API-Key: " ``` -------------------------------- ### List Devices Pending Adoption - Ansible Source: https://developer.ui.com/network/v10.1.68/getpendingdevicepage Illustrates how to use Ansible modules to list devices pending adoption. This leverages the UniFi API for customized workflow automation. Requires UniFi Connector and firmware version 5.0.3+. ```yaml --- - name: List UniFi devices pending adoption hosts: localhost tasks: - name: Get pending devices community.general.unifi_api: controller_host: "" controller_port: "" username: "" password: "" method: "GET" path: "/network/integration/v1/pending-devices" params: offset: 0 limit: 100 register: pending_devices_result - name: Print pending devices debug: var: pending_devices_result.json ``` -------------------------------- ### List ACL Rules (Ansible) Source: https://developer.ui.com/network/v10.1.68/getaclrulepage This Ansible snippet shows how to integrate with the UniFi API to list ACL rules. It leverages the UniFi Connector, requiring a minimum firmware version of 5.0.3. The example demonstrates how to define the task to fetch ACL rules, specifying the site ID and relevant parameters. ```yaml # Ansible example not provided in the source text. ``` -------------------------------- ### Get Latest Adopted Device Statistics using Ansible Source: https://developer.ui.com/network/v10.1.68/getadopteddevicelateststatistics Shows how to integrate fetching the latest real-time statistics for a specific adopted UniFi device into an Ansible workflow. This example utilizes Ansible modules to interact with the UniFi API. ```yaml # Ansible playbook snippet for fetching device statistics would go here. # This would involve using a custom or community Ansible module for UniFi API integration. ``` -------------------------------- ### List Hotspot Vouchers (Node.js) Source: https://developer.ui.com/network/v10.1.68/getvouchers This Node.js example illustrates fetching Hotspot vouchers via the UniFi API. It uses the `axios` library for making HTTP requests and includes necessary headers for API key authentication and content type. ```javascript // Node.js code example for listing vouchers would go here. This requires a specific Node.js SDK or HTTP client implementation. ```