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
<PackageReference Include="Printsluis.Client" Version="2.0.0" />
<PackageVersion Include="Printsluis.Client" Version="2.0.0" />
<PackageReference Include="Printsluis.Client" />
paket add Printsluis.Client --version 2.0.0
#r "nuget: Printsluis.Client, 2.0.0"
#:package Printsluis.Client@2.0.0
#addin nuget:?package=Printsluis.Client&version=2.0.0
#tool nuget:?package=Printsluis.Client&version=2.0.0
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.
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. ExternalReferenceandMetadataare stored as plain text and are searchable. Never put personal data in them.GetJobAsync,SearchJobsAsyncandCancelJobAsyncfollow a job.ListPrintersAsync,ListAliasesAsyncandListAgentsAsyncsupport printer selection and health checks;ListAlertsAsyncreturns the open alerts (printers that need attention, agents out of contact).TestPrintAsyncprints 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:
- 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. - 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.
- It encrypts the document for the remaining agents and submits it with
Encrypted = true. The job'sPrintJobResponse.Encryptedistrue.
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, anddiagnoseshows 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 withdiagnose. - 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. UpdateAsyncrenames or suspends an organization; a suspended organization rejects new jobs withorganization_suspended.DeleteAsyncrevokes its keys and agents.CreateApiKeyAsynccreates an ordinary key of one customer organization, for software that should reach only that customer.GetUsageAsynclists 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 adefaultbranch. - The gateway stays compatible. Every 1.x and 2.x client works against the current
gateway. The gateway changes
/v1only 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:
- 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.GetEncryptionKeysAsyncshows which agents have a key. - Decide on pinning. Optionally list the agents' fingerprints in
TrustedAgents(Pinning agents). - Handle the new codes
encryption_unavailable,encryption_untrustedandencryption_keys_stalewhere you handleprinter_unavailable(Errors). - If you can't update the agents yet, set
Encryption:ModetoOffto keep 1.x behavior, and remove it once they are updated.
Other changes:
- New names. 1.x was
PrintGateway.ClientandPrintGateway.Contractson GitHub Packages; 2.0 isPrintsluis.ClientandPrintsluis.Contractson nuget.org. Replace the package references, changePrintGatewaytoPrintsluisin theusingdirectives, type names (PrintsluisClient,PrintsluisException, …) and the registration call (AddPrintsluisClient), and rename the configuration sectionPrintGatewaytoPrintsluis. Webhook requests carryX-Printsluis-*headers;WebhookNameshas them. - The API key needs
print:createforGET /v1/encryption-keys, which a key that prints already has. AddPrintsluisClientregisters the client on a namedHttpClient(PrintsluisClient, the same name as before) with a factory, and a singleton key cache. If you resolve aTimeProviderfrom 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 | Versions 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. |
-
net10.0
- Microsoft.Extensions.Configuration.Binder (>= 10.0.15)
- Microsoft.Extensions.Http (>= 10.0.15)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.15)
- Printsluis.Contracts (>= 2.0.0)
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 |