NginxProxyManager.SDK 2.0.1

dotnet add package NginxProxyManager.SDK --version 2.0.1
                    
NuGet\Install-Package NginxProxyManager.SDK -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NginxProxyManager.SDK" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NginxProxyManager.SDK" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="NginxProxyManager.SDK" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NginxProxyManager.SDK --version 2.0.1
                    
#r "nuget: NginxProxyManager.SDK, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=NginxProxyManager.SDK&version=2.0.1
                    
Install NginxProxyManager.SDK as a Cake Addin
#tool nuget:?package=NginxProxyManager.SDK&version=2.0.1
                    
Install NginxProxyManager.SDK as a Cake Tool

Nginx Proxy Manager SDK

A .NET SDK for interacting with the Nginx Proxy Manager API.

Features

  • Client-based approach for easy access to all resources
  • Fluent builder pattern for creating requests
  • Comprehensive error handling with OperationResult pattern
  • Automatic token management and refresh
  • Full support for all Nginx Proxy Manager API endpoints
  • Dependency injection support for ASP.NET Core applications

Installation

dotnet add package NginxProxyManager.SDK

Quick Start

using NginxProxyManager.SDK;
using NginxProxyManager.SDK.Common;

// Create credentials
var credentials = AuthenticationCredentials.FromCredentials("admin@example.com", "your-password");

// Create a client
var client = new NginxProxyManagerClient("http://your-npm-instance:81", credentials);

// List all proxy hosts
var result = await client.ProxyHosts.GetAllAsync();
if (result.IsSuccess)
{
    foreach (var proxy in result.Data)
    {
        Console.WriteLine($"Proxy: {proxy.DomainNames[0]} -> {proxy.ForwardHost}:{proxy.ForwardPort}");
    }
}

Configuration

Using Dependency Injection

// In your Program.cs or Startup.cs
using NginxProxyManager.SDK;
using NginxProxyManager.SDK.Common;

// Configure services
builder.Services.AddNginxProxyManager(options =>
{
    options.BaseUrl = "http://your-npm-instance:81";
    options.Credentials = AuthenticationCredentials.FromCredentials("admin@example.com", "your-password");
});

// In your controller or service
public class ProxyController : ControllerBase
{
    private readonly INginxProxyManagerClient _client;

    public ProxyController(INginxProxyManagerClient client)
    {
        _client = client;
    }

    public async Task<IActionResult> Index()
    {
        var result = await _client.ProxyHosts.GetAllAsync();
        if (result.IsSuccess)
        {
            return View(result.Data);
        }
        
        return BadRequest(result.Error);
    }
}

Using appsettings.json

{
  "NginxProxyManager": {
    "BaseUrl": "http://your-npm-instance:81",
    "TimeoutSeconds": 30,
    "Email": "admin@example.com",
    "Password": "your-password"
  }
}

Using Code

var config = new NPMConfiguration
{
    BaseUrl = "http://your-npm-instance:81",
    TimeoutSeconds = 30,
    Email = "admin@example.com",
    Password = "your-password"
};

services.AddNginxProxyManager(config);

Using Environment Variables

You can also configure the SDK using environment variables:

export NGINX_PROXY_MANAGER_BASE_URL="http://your-npm-instance:81"
export NGINX_PROXY_MANAGER_EMAIL="admin@example.com"
export NGINX_PROXY_MANAGER_PASSWORD="your-password"
export NGINX_PROXY_MANAGER_TIMEOUT_SECONDS="30"

Then in your code:

services.AddNginxProxyManager(); // Will use environment variables

Available Resources

The SDK provides access to all Nginx Proxy Manager resources through the client:

// Create a client
var credentials = AuthenticationCredentials.FromCredentials("admin@example.com", "your-password");
var client = new NginxProxyManagerClient("http://your-npm-instance:81", credentials);

// Access resources
var proxyHosts = client.ProxyHosts;
var streams = client.Streams;
var certificates = client.Certificates;
var accessLists = client.AccessLists;
var serverErrors = client.ServerErrors;
var auditLogs = client.AuditLogs;
var reports = client.Reports;
var deadHosts = client.DeadHosts;

Builder Pattern

The SDK uses a fluent builder pattern for creating requests:

// Create a proxy host using the builder pattern
var result = await client.ProxyHosts.CreateBuilder()
    .WithDomainNames("example.com")
    .WithForwardHost("192.168.1.100")
    .WithForwardPort(8080)
    .WithSsl(true)
    .Build()
    .CreateAsync();

if (result.IsSuccess)
{
    Console.WriteLine($"Created proxy host with ID: {result.Data.Id}");
}

Error Handling

The SDK uses the OperationResult<T> pattern for error handling:

var result = await client.ProxyHosts.CreateAsync(proxy);
if (result.IsSuccess)
{
    // Use the created item
    var item = result.Data;
}
else
{
    // Handle the error
    var error = result.Error;
    Console.WriteLine($"Error: {error.Message}");
    Console.WriteLine($"Details: {error.Details}");
}

Documentation

For detailed documentation on each resource, see:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.1 185 4/15/2025

Initial release of NginxProxyManager.SDK