From de68207f48caa83fb8c2ba34ac04fc64f7024de7 Mon Sep 17 00:00:00 2001 From: Brain of Reese Date: Tue, 1 Sep 2026 09:29:52 -0400 Subject: [PATCH] docs: Give me some unifi api examples --- docs/unifi-examples.md | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 docs/unifi-examples.md diff --git a/docs/unifi-examples.md b/docs/unifi-examples.md new file mode 100644 index 0000000..f87d41e --- /dev/null +++ b/docs/unifi-examples.md @@ -0,0 +1,69 @@ +Based on the scripts in your homelab, here are the Unifi API examples you're looking for. The code uses the **Network Integration API** (`/proxy/network/integration/v1/...`) and the **Static DNS API** (`/proxy/network/v2/api/...`). + +### 1. Authentication +Both scripts use a Bearer-style header `X-API-Key`. +* **Source:** `active/device_unifi/update_dns.py` & `active/aws_route53/unifi_to_aws.py` + +```python +headers = { + "Accept": "application/json", + "X-API-Key": os.environ.get("API_KEY") +} +``` + +### 2. List All Sites +Used to find the `site_id` required for other calls. +* **Endpoint:** `GET /proxy/network/integration/v1/sites` +* **Source:** `active/device_unifi/update_dns.py` + +```python +# Example from update_dns.py +response = requests.get( + f"{UNIFI_API_ENDPOINT}/proxy/network/integration/v1/sites", + headers={"X-API-Key": UNIFI_API_KEY}, + verify=False +) +sites = response.json().get("data") +``` + +### 3. Fetch Static DNS Devices +Returns a list of devices with hostnames and IPs. +* **Endpoint:** `GET /proxy/network/v2/api/site/default/static-dns/devices` +* **Source:** `active/aws_route53/unifi_to_aws.py` + +```python +# Example from unifi_to_aws.py +devices_url = "https://10.1.0.1/proxy/network/v2/api/site/default/static-dns/devices" +devices_data = requests.get(devices_url, headers=headers, verify=False).json() +# Result format: [{"hostname": "...", "ip_address": "..."}, ...] +``` + +### 4. Fetch DNS Policies +Returns DNS records (policies) for a specific site. +* **Endpoint:** `GET /proxy/network/integration/v1/sites/{site_id}/dns/policies` +* **Source:** `active/device_unifi/update_dns.py` & `active/aws_route53/unifi_to_aws.py` + +```python +# Example from unifi_to_aws.py +site_id = "88f7af54-98f8-306a-a1c7-c9349722b1f6" +policies_url = f"https://10.1.0.1/proxy/network/integration/v1/sites/{site_id}/dns/policies" +policies_data = requests.get(policies_url, headers=headers, verify=False).json() +# Result format: {"data": [{"domain": "...", "ipv4Address": "..."}, ...]} +``` + +### 5. DNS Record Structure +If you are creating or updating records (like in `unifi_to_aws.py`), the expected payload structure is: + +```json +{ + "Action": "UPSERT", + "ResourceRecordSet": { + "Name": "mydevice.reeselink.com", + "Type": "A", + "TTL": 60, + "ResourceRecords": [ + {"Value": "192.168.1.50"} + ] + } +} +``` \ No newline at end of file