A comprehensive collection of .NET SDKs for interacting with Ubiquiti UniFi APIs and services. This solution provides strongly-typed, async-first client libraries for UniFi's ecosystem, with built-in resilience and dependency injection support.
Package | Description | Status | NuGet |
---|---|---|---|
Unifi.NET.Access | SDK for UniFi Access API - Door access control, user management, NFC/PIN credentials | π§ In Development | - |
Unifi.NET.Network | SDK for UniFi Network Controller API - Network device management, configuration, statistics | π Planned | - |
Unifi.NET.Protect | SDK for UniFi Protect API - Video surveillance, camera management, event detection | π Planned | - |
Unifi.NET.SiteManager | SDK for UniFi Site Manager API - Multi-site management, centralized control | π Planned | - |
- Native AOT Compatible - Full support for Native AOT compilation for optimal performance and size
- Strongly Typed Models - Full request/response models for all API endpoints
- Async/Await Support - Built for modern async programming patterns
- Dependency Injection - Native integration with Microsoft.Extensions.DependencyInjection
- Resilience & Retry Logic - Built-in Polly policies for transient fault handling
- RestSharp Based - Leveraging RestSharp for robust HTTP client functionality
- API Token Authentication - Secure authentication using UniFi API tokens
- Comprehensive Error Handling - Detailed exception types and error codes
- IntelliSense Support - Full XML documentation for all public APIs
- Trimming Safe - Optimized for trimming to reduce application size
- .NET 9.0 or later
- UniFi Console with the respective service installed
- API Token from UniFi Portal (for authentication)
- Network access to your UniFi Console (default port: 12445 for Access)
- .NET 9 SDK for building
- Target platform runtime identifier (e.g.,
linux-x64
,win-x64
,osx-arm64
) - No additional runtime dependencies needed for deployment
Install the SDK for the UniFi service you need via NuGet:
# For UniFi Access
dotnet add package Unifi.NET.Access
# For UniFi Network
dotnet add package Unifi.NET.Network
# For UniFi Protect
dotnet add package Unifi.NET.Protect
# For UniFi Site Manager
dotnet add package Unifi.NET.SiteManager
using Microsoft.Extensions.DependencyInjection;
using Unifi.NET.Access;
var services = new ServiceCollection();
// Configure UniFi SDKs
services.AddUnifi(options =>
{
options.BaseUrl = "https://your-console-ip:12445";
options.ApiToken = "your-api-token-here";
options.ValidateSsl = false; // Set to true in production with valid certificates
})
.AddAccess() // Add UniFi Access SDK
.AddNetwork() // Add UniFi Network SDK
.AddProtect(); // Add UniFi Protect SDK
var serviceProvider = services.BuildServiceProvider();
// Resolve the Access client from DI
var accessClient = serviceProvider.GetRequiredService<IUnifiAccessClient>();
// Get all users
var users = await accessClient.Users.GetAllAsync();
// Get a specific door
var door = await accessClient.Doors.GetAsync("door-id");
// Unlock a door remotely
await accessClient.Doors.UnlockAsync("door-id");
// Create a new user
var newUser = await accessClient.Users.CreateAsync(new CreateUserRequest
{
FirstName = "John",
LastName = "Doe",
Email = "john.doe@example.com",
EmployeeNumber = "EMP001"
});
// Assign an access policy to a user
await accessClient.Users.AssignAccessPolicyAsync(newUser.Id, "policy-id");
using Unifi.NET.Access;
var config = new UnifiConfiguration
{
BaseUrl = "https://your-console-ip:12445",
ApiToken = "your-api-token-here"
};
var accessClient = new UnifiAccessClient(config);
// Use the client
var users = await accessClient.Users.GetAllAsync();
The SDKs are designed for full Native AOT compatibility in .NET 9:
<!-- In your project file -->
<PropertyGroup>
<PublishAot>true</PublishAot>
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
<IsAotCompatible>true</IsAotCompatible>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<OptimizationPreference>Speed</OptimizationPreference>
</PropertyGroup>
The SDK uses ASP.NET Core-style JSON serialization patterns for optimal Native AOT performance:
// Internal implementation uses service-specific JsonSerializerContext classes
// Combined with TypeInfoResolver for runtime type resolution
// Following Microsoft's recommended patterns for Native AOT applications
// All JSON serialization is handled internally - no configuration needed!
services.AddUnifi(options =>
{
options.BaseUrl = "https://your-console-ip:12445";
options.ApiToken = "your-api-token-here";
})
.AddAccess(); // Serialization is automatically configured for AOT
# Publish with Native AOT
dotnet publish -c Release -r linux-x64
# Verify AOT compatibility (produces zero warnings)
dotnet publish -c Release -r linux-x64 --verbosity detailed | grep -i warning
All UniFi SDKs use API Token authentication. To obtain an API token:
- Sign in to your UniFi Portal
- Select the UniFi Console where the service is installed
- Navigate to the respective service settings:
- Access: Access > Settings > General > Advanced > API Token
- Network: Settings > System > Advanced > API
- Protect: Settings > Advanced > API
- Create a new API token with appropriate permissions
- Copy and securely store the token (it's only shown once)
Service | Minimum Version | Recommended Version |
---|---|---|
UniFi Access | 1.9.1 | Latest |
UniFi Network Controller | 7.0.0 | Latest |
UniFi Protect | 2.0.0 | Latest |
UniFi Site Manager | 1.0.0 | Latest |
Note: API availability may vary based on your UniFi service version and license type. Identity Enterprise users should check API availability for their specific configuration.
The solution follows Clean Architecture principles with a modular design:
Unifi.NET/
βββ Unifi.NET.Access/ # UniFi Access SDK
β βββ Models/ # Request/Response DTOs
β βββ Services/ # API service implementations
β βββ Extensions/ # DI extensions
β βββ Exceptions/ # Custom exceptions
βββ Unifi.NET.Network/ # UniFi Network SDK
βββ Unifi.NET.Protect/ # UniFi Protect SDK
βββ Unifi.NET.SiteManager/ # UniFi Site Manager SDK
βββ Unifi.NET.Common/ # Shared utilities (planned)
All SDKs follow .NET 9 Native AOT best practices:
- System.Text.Json with source generators (no reflection)
- Microsoft.Extensions.DependencyInjection
- Microsoft.Extensions.Http with IHttpClientFactory
- Polly v8+ for resilience (via Microsoft.Extensions.Http.Resilience)
- No runtime reflection for serialization
- No dynamic code generation (System.Reflection.Emit)
- No runtime type discovery
- No dynamic assembly loading
- Service-specific
JsonSerializerContext
classes for organized type registration JsonTypeInfoResolver.Combine()
pattern for merging contexts (ASP.NET Core style)JsonTypeInfo<T>
andGetTypeInfo()
for runtime type resolution- All models use
[JsonSerializable]
source generation - Configuration uses source-generated binding
- RestSharp configured with System.Text.Json and AOT-safe serializers
- Zero AOT warnings policy enforced
Each SDK includes comprehensive unit and integration tests:
# Run all tests
dotnet test
# Run tests for a specific SDK
dotnet test Unifi.NET.Access.Tests
# Run with coverage
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
Package versions follow the UniFi API version they wrap, with an additional revision suffix for SDK updates:
3.3.21
- Matches UniFi Access API v3.3.21, first SDK release3.3.21.1
- Same API version, SDK bug fixes or improvements3.4.0
- New UniFi Access API version
We welcome contributions! Please see our Contributing Guidelines for details on:
- Code style and standards
- Pull request process
- Bug reporting
- Feature requests
- Development setup
This project is licensed under the MIT License - see the LICENSE file for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Wiki
- Project structure setup
- Native AOT-compatible HTTP client with RestSharp
- System.Text.Json source generators with ASP.NET Core patterns
- User management endpoints (10/10 core endpoints)
- User group management (10/10 endpoints)
- NFC card management (9/9 endpoints)
- PIN code management (3/3 endpoints)
- Door and access control endpoints (7/7 endpoints)
- Access policy management (5/5 endpoints)
- Device management (1/3 endpoints)
- Comprehensive sample application
- Integration tested with production UniFi Access
- Remaining endpoints (75/120 to implement)
- Webhook/WebSocket support for real-time events
- Complete unit test coverage
- NuGet package publication
- Device management
- Network configuration
- Statistics and monitoring
- Guest management
- Camera management
- Recording and playback
- Event detection
- Live streaming support
- Multi-site management
- Centralized configuration
- Cross-site operations
- Ubiquiti Networks for creating the UniFi ecosystem
- The .NET community for continuous support and feedback
- Contributors and users of this project
This is an unofficial SDK and is not affiliated with, officially maintained, or endorsed by Ubiquiti Networks. Use at your own risk.
Note: This project is currently in active development. APIs may change before the first stable release. We recommend using preview versions with caution in production environments.