Skip to Content

C# SDK

An async .NET client built on HttpClient. It requires .NET 8 or later, or a platform implementing .NET Standard 2.0, like .NET Framework 4.6.1 or later.

dotnet add package LicenseMan.Sdk

NuGet  · GitHub  · API Reference 

How it works

The SDK has one class per section of the API Reference , like LicensesApi or CustomersApi, and one method per endpoint, named after it: Create a license is CreateLicenseAsync, with a synchronous CreateLicense too. Each method takes the path parameters and the body, then the optional parameters, best passed by name, and returns the response as a model.

The API Reference lists every endpoint with its parameters and response: the SDK’s methods take and return the same ones.

Authentication

Pass a Configuration to the classes:

using LicenseManager.Api; using LicenseManager.Client; var configuration = new Configuration(); // With an API key, from your backend: configuration.AddApiKey("x-api-key", Environment.GetEnvironmentVariable("LICENSEMANAGER_API_KEY")); // Or with a token scoped to a customer, license or machine: configuration.AccessToken = token; var licenses = new LicensesApi(configuration);

Never ship an API key in your application: anyone could extract it. Keep it on your servers.

Examples

Create a license after a sale, and email its key to the customer:

using LicenseManager.Model; var license = await licenses.CreateLicenseAsync( "x7Kp2QaZ", new CreateLicense(email: "jane@example.com", sendKey: true) );

Validate a key from your application, which needs no credentials:

var licenseToken = await new LicensesApi().ValidateKeyAsync( "x7Kp2QaZ", new ValidateKey( key: "7KQ2M-X9ZPA-H4TRC-WN6EY-B3JDF", fingerprint: "4c:32:75:8f:9a:1e", varVersion: "1.4.2" ) ); // licenseToken.License is the signed license token.

The SDK reserves a few names, which it prefixes with var: the version field is varVersion.

List the licenses of a product, one page at a time:

var page = await licenses.ListLicensesAsync("x7Kp2QaZ", page: 2, pageSize: 50, sort: "-createdAt"); // page.Data holds the licenses, page.Pagination the totals.

Errors

A failed request throws an ApiException, holding the status and the body with the error’s stable code:

try { await licenses.GetLicenseAsync("l3Nv8KwB"); } catch (ApiException error) { // The body is { "error": { "code", "message" } }. Console.Error.WriteLine($"{error.ErrorCode} {error.ErrorContent}"); }