Printsluis.Client 2.0.0

Prefix Reserved
dotnet add package Printsluis.Client --version 2.0.0
                    
NuGet\Install-Package Printsluis.Client -Version 2.0.0
                    
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="Printsluis.Client" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Printsluis.Client" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Printsluis.Client" />
                    
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 Printsluis.Client --version 2.0.0
                    
#r "nuget: Printsluis.Client, 2.0.0"
                    
#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.
#:package Printsluis.Client@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Printsluis.Client&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Printsluis.Client&version=2.0.0
                    
Install as a Cake Tool

Printsluis.Client

.NET client for the Printsluis public API (/v1): submit print jobs, follow their status, and list printers, aliases and agents. The request and response types are in Printsluis.Contracts, which comes with it.

Targets net10.0. MIT licensed.

Install

From nuget.org:

dotnet add package Printsluis.Client

Configure

{
  "Printsluis": {
    "BaseAddress": "https://api.printsluis.nl/",
    "ApiKey": "pgw_..."
  }
}
builder.Services.AddPrintsluisClient(builder.Configuration);

ApiKey is the organization's API key from the portal. Keep it in a secret store. The options are validated at startup; Timeout defaults to 30 seconds. AddPrintsluisClient returns the IHttpClientBuilder, so you can add handlers such as AddStandardResilienceHandler(). If requests are retried, always pass an idempotency key (see below).

Documents are encrypted end to end by default; see Encryption for the Encryption section and pinning agents.

Print

Inject PrintsluisClient:

var job = await printGateway.PrintAsync(
    new SubmitPrintJobRequest(
        Target: PrintTarget.ByPrinter(user.LabelPrinterId, fallbackAlias: "labels"),
        Document: PrintDocument.Zpl(zpl),
        ExternalReference: order.Number),
    idempotencyKey: $"order-{order.Id}-label",
    cancellationToken);
  • The idempotency key makes a retry safe: the same key and request return the existing job instead of printing twice. The same key with a different request fails with idempotency_key_reused.
  • ExternalReference and Metadata are stored as plain text and are searchable. Never put personal data in them.
  • GetJobAsync, SearchJobsAsync and CancelJobAsync follow a job. ListPrintersAsync, ListAliasesAsync and ListAgentsAsync support printer selection and health checks; ListAlertsAsync returns the open alerts (printers that need attention, agents out of contact). TestPrintAsync prints a test label.

Encryption

From 2.0, PrintAsync encrypts every document so that only the agents that can print it can read it. The gateway stores and routes the encrypted document but cannot read it, nor can anyone who gets hold of its storage or backups. Your code doesn't change:

  1. Before submitting, the client fetches the encryption keys of the agents that can print the target (GET /v1/encryption-keys; the printer's agent, its routes and the agents behind the fallback alias). It caches them for 5 minutes per target.
  2. It drops every key that is not signed by its agent's identity key and, when you pin agents, every key of an agent you don't trust.
  3. It encrypts the document for the remaining agents and submits it with Encrypted = true. The job's PrintJobResponse.Encrypted is true.

It never falls back to sending the document unencrypted. When no key is left, it throws before anything is submitted (see Errors). When an agent rotated its key since the keys were fetched, the gateway answers encryption_keys_stale; the client fetches the keys again and retries once, with the same idempotency key.

Only the content is encrypted. Format, size, printer, copies, print options, ExternalReference and Metadata stay readable for the gateway.

Agents need a version that supports encryption; older agents have no key, and printing to a target whose agents are all too old fails with encryption_unavailable.

Pinning agents

Without pinning, the client trusts the keys the gateway hands out (after checking their signatures). That protects against leaks of stored data, but not against a gateway that is compromised while it runs and hands out a key of its own. To rule that out, list the agents you trust by their identity fingerprint:

{
  "Printsluis": {
    "BaseAddress": "https://api.printsluis.nl/",
    "ApiKey": "pgw_...",
    "Encryption": {
      "TrustedAgents": [ "SHA256:A5BYxvLAy0ksUzsKTRTvd8wPeKvMztUofYShogEc+4E" ]
    }
  }
}
  • Get a fingerprint on the agent's machine: the agent prints it after pair, and diagnose shows it at any time. Don't copy it from the portal or from the gateway's API: pinning only helps when the fingerprint did not come through the gateway.
  • The client then only encrypts for agents in the list. A target whose agents are partly trusted is encrypted for the trusted ones only; a job that the gateway then routes to an untrusted agent's printer fails with encryption_keys_stale.
  • When you add an agent (a new site, a route, a replacement PC) or an agent pairs again, add its fingerprint. Until then, printing to its printers fails with encryption_untrusted; the exception's message lists the agents' ids and fingerprints to compare with diagnose.
  • Fingerprints are checked at startup: an entry that is not SHA256: followed by 43 base64 characters stops the application.
  • An agent's encryption key rotates every 90 days. That needs no change: the fingerprint is of the identity key, which signs each new encryption key.

GetEncryptionKeysAsync(target) returns the keys as the gateway hands them out, for example to show the fingerprints in an admin screen:

var keys = await printGateway.GetEncryptionKeysAsync(PrintTarget.ByAlias("labels"));
foreach (var key in keys.Keys)
    Console.WriteLine($"{key.AgentId}: {AgentKeyCertificate.Fingerprint(Convert.FromBase64String(key.IdentityKey))}");

Those keys are not verified or filtered; PrintAsync does that itself.

Turning encryption off

"Encryption": { "Mode": "Off" }

Mode is Required (the default) or Off. Off sends documents unencrypted, as 1.x did, for example while agents are being updated. An organization can refuse unencrypted documents (encryption_required). A document you encrypted yourself (PrintDocument with Encrypted: true) is always submitted as it is.

Without dependency injection, pass the options to the constructor: new PrintsluisClient(httpClient, new PrintsluisEncryptionOptions { Mode = EncryptionMode.Off }). Create the client once and reuse it, so the key cache works.

Partners: customer organizations

A partner (a software vendor that runs printing for its customers) uses a partner API key with organizations:read and organizations:write. Organizations creates and manages its customer organizations; ForOrganization acts inside one of them by sending the X-Organization-Id header, so the partner needs no key per customer:

var customer = await printGateway.Organizations.FindByExternalReferenceAsync(account.Number)
    ?? await printGateway.Organizations.CreateAsync(new CreateCustomerOrganizationRequest(account.Name, account.Number));

// The agent's install commands, with a one-time pairing code.
var pairing = await printGateway.Organizations.CreatePairingCodeAsync(customer.Id, new CreatePairingCodeRequest("Warehouse PC"));

// Print in the customer's organization; the key needs print:create.
var job = await printGateway.ForOrganization(customer.Id).PrintAsync(request, idempotencyKey: $"order-{order.Id}-label");
  • A partner key reaches only its own organizations. Anything else is organization_not_found, as is a deleted organization.
  • UpdateAsync renames or suspends an organization; a suspended organization rejects new jobs with organization_suspended. DeleteAsync revokes its keys and agents.
  • CreateApiKeyAsync creates an ordinary key of one customer organization, for software that should reach only that customer.
  • GetUsageAsync lists the organizations that printed in a month (active organizations).

Errors

A rejected request throws PrintsluisException. Its Code, such as printer_unavailable, job_not_cancellable or idempotency_key_reused, is stable and safe to branch on; Status is the HTTP status.

plan_limit (403) means the organization's plan does not allow the request: a PDF document on a plan without PDF printing, or a new job on the free plan once its monthly prints are used (printing resumes the next month). Paid plans never refuse a job for the number of prints. Retrying does not help; the organization's plan has to change.

Encryption codes (422). The client throws the first two itself, before submitting anything:

Code Meaning What to do
encryption_unavailable No agent that can print the target has an encryption key, or none of the keys is signed by its agent. Update the agents; check the target.
encryption_untrusted Keys exist, but none of their agents is in TrustedAgents. The message lists the agents' ids and fingerprints. Compare a fingerprint with diagnose on the agent's machine, then add it.
encryption_keys_stale The keys changed and still did after one retry, or the job was routed to an agent the document is not encrypted for. Retry later; with pinning, check that every agent of the target is trusted.
encryption_required The organization only accepts encrypted documents and Mode is Off. Turn encryption on.

Webhooks

A webhook endpoint receives the event types chosen for it in the portal: print_job.finished (the default), and agent and printer state such as agent.offline and printer.needs_attention. Verify the raw body before you parse it:

var valid = WebhookSignature.Verify(
    secret,
    request.Headers[WebhookNames.TimestampHeader],
    body,
    request.Headers[WebhookNames.SignatureHeader],
    timeProvider.GetUtcNow());

Then WebhookEventParser.Parse(body) returns the envelope for the event type: WebhookEvent for print_job.finished, WebhookEvent<AgentStateChanged> for agent.*, WebhookEvent<PrinterStateChanged> for printer.*, and WebhookEvent<JsonElement> for a type this version doesn't know. Deliveries can repeat (ignore a known Id) and arrive out of order (compare CreatedAt). The event types and example payloads are in the webhooks guide.

Debugging

The assemblies have embedded PDBs, so stack traces through the SDK show file names and line numbers.

Versions and compatibility

The SDK follows semantic versioning. Changes are listed in the changelog.

Within a major version (2.x; the same held for 1.x):

  • The public API of both packages only grows. Types and members are not removed, renamed or changed in a way that breaks code compiled against an earlier release of that major version. This includes source and binary compatibility. A new field on a request or response record gets a new constructor; the existing one stays.
  • Observable behavior stays. This covers defaults, configuration keys, the problem codes in PrintsluisException.Code, JSON names, and the webhook signature format.
  • Enums and codes can gain values. PrintJobStatus, DocumentFormat, other enums, problem codes and webhook event types may get new values in a minor release. Handle unknown values, for example with a default branch.
  • The gateway stays compatible. Every 1.x and 2.x client works against the current gateway. The gateway changes /v1 only in ways those clients tolerate, such as new optional request fields or new response fields.
  • Dependencies. Adding a target framework is a minor release. Dropping one, or raising a Microsoft.Extensions.* dependency to a new major version, is a major release.

Not covered: the Printsluis.Contracts.Agents namespace. It is the protocol between the gateway and its own agent, and changes with them.

A breaking change means a new major version of the SDK and, for HTTP changes, a new API version (/v2). The gateway keeps serving /v1 until the consuming applications have moved. 2.0 changed the SDK's behavior, not the HTTP API: it still uses /v1.

Upgrading from 1.x

2.0 encrypts documents by default (Encryption). The code that calls the SDK compiles unchanged; what changes is what happens when you print:

  1. Update the agents first. Every agent that can print a target (including routes and fallback aliases) needs a version that registers an encryption key. Until then, printing there fails with encryption_unavailable. GetEncryptionKeysAsync shows which agents have a key.
  2. Decide on pinning. Optionally list the agents' fingerprints in TrustedAgents (Pinning agents).
  3. Handle the new codes encryption_unavailable, encryption_untrusted and encryption_keys_stale where you handle printer_unavailable (Errors).
  4. If you can't update the agents yet, set Encryption:Mode to Off to keep 1.x behavior, and remove it once they are updated.

Other changes:

  • New names. 1.x was PrintGateway.Client and PrintGateway.Contracts on GitHub Packages; 2.0 is Printsluis.Client and Printsluis.Contracts on nuget.org. Replace the package references, change PrintGateway to Printsluis in the using directives, type names (PrintsluisClient, PrintsluisException, …) and the registration call (AddPrintsluisClient), and rename the configuration section PrintGateway to Printsluis. Webhook requests carry X-Printsluis-* headers; WebhookNames has them.
  • The API key needs print:create for GET /v1/encryption-keys, which a key that prints already has.
  • AddPrintsluisClient registers the client on a named HttpClient (PrintsluisClient, the same name as before) with a factory, and a singleton key cache. If you resolve a TimeProvider from the container, the cache uses it.
  • An encrypted document grows by 181 bytes for one agent, plus 145 bytes per further agent. The gateway's size limits apply to the document, not to that overhead.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.0 0 11/24/2026