go-unifi-api-integration-v1
Fork of ubiquiti-community/go-unifi with fixes for UniFi Network API 9.x+

This Go SDK provides API clients for managing UniFi Network devices. This fork includes critical fixes for UniFi Network API 9.x+ compatibility.
Key Differences from Original
Fixed Endpoints (Network API 9.x+)
| Resource |
Original Endpoint |
Fixed Endpoint |
Status |
| DNS Policies |
v2/api/site/{site}/static-dns |
integration/v1/sites/{site}/dns/policies |
✅ Fixed v1.33.44+ |
| Firewall Policies |
v2/api/site/{site}/firewall-policies |
integration/v1/sites/{site}/firewall/policies |
✅ Fixed v1.33.47+ |
Breaking Changes
Usage
import "github.com/svilendotorg/go-unifi-api-integration-v1/unifi"
// Create API client
client, err := unifi.NewApiClient("https://controller-url", "api-key", true)
// List DNS policies
policies, err := client.ListDNSPolicy(context.Background(), "site-id")
// Create firewall policy
policy := &unifi.FirewallPolicy{
Name: "Allow Internal Traffic",
Enabled: true,
Action: &unifi.FirewallPolicyAction{
Type: "ALLOW",
},
// ... more fields
}
result, err := client.CreateFirewallPolicy(context.Background(), "site-id", policy)
Versioning
- v1.33.51+: Firewall policy JSON parsing fixes:
- ID field:
"id" not "_id"
- List response:
{data: [...]} wrapper support
- ConnectionStateFilter:
interface{} for array/object flexibility
- v1.33.47+: Firewall policy integration/v1 API support
- v1.33.44+: DNS policy integration/v1 API support
- Based on original go-unifi v1.33.43
Compatibility
- UniFi Network API: 9.x, 10.x, 10.2.105+
- Go: 1.21+
UniFi API Documentation
Official UniFi API Documentation
Additional sources
This SDK is used by the terraform-provider-unifi fork.
Note on Code Generation
The data models and basic REST methods are "generated" from JSON files in the JAR that show all fields and the associated regex/validation information.
To regenerate the code, you can bump the Unifi Controller version number in [unifi/gen.go] and run go generate inside the unifi directory.
This code generation is kind of gross, I wanted to switch to using the java classes in the jar like scala2go but the jar is obfuscated and I couldn't find a way to extract that information from anywhere else. Maybe it exists somewhere in the web UI, but I was unable to find it in there in a way that was extractable in a practical way.
Still planning to dig through the bits some more later on.
License
Apache 2.0 (same as original go-unifi)