Skip to content

Webhooks

A webhook endpoint is a URL in your application that receives signed POST requests when something happens: a print job finishes, an agent goes offline or comes back, or a printer needs attention, becomes unreachable or prints again. Your application doesn’t need to poll, and you can show printer problems in your own software.

Admins manage endpoints on the portal’s Webhooks page:

  1. Choose Add endpoint, and enter the URL and the events it should receive.
  2. Copy the signing secret (whsec_…). It is shown once. Store it in your application’s secret store.

The URL must be https, without credentials in it, and resolve to a public IP address. Redirects are not followed.

Each endpoint receives the event types chosen for it. A new endpoint receives only print_job.finished unless you choose otherwise; change it later with Choose events in the endpoint’s menu. An endpoint receives at least one type; to receive none, disable it. A change applies to events from then on: deliveries already queued are still sent.

The portal also shows each endpoint’s recent deliveries, and lets you Redeliver one.

Type When data
print_job.finished A job reached a final status: succeeded, failed, cancelled, expired or indeterminate PrintJobFinished
agent.offline An active, paired agent has been out of contact for 3 minutes AgentStateChanged
agent.online An agent that was reported offline is in contact again AgentStateChanged
printer.needs_attention A printer has needed attention (paper out, head open, paused…) for 2 minutes, or what it reports changed since PrinterStateChanged
printer.unreachable A printer has been unreachable from its agent for 2 minutes, or became unreachable while it needed attention PrinterStateChanged
printer.ready A printer that needed attention or was unreachable prints again PrinterStateChanged

The agent and printer events use the same signals and waiting times as the alert emails. The waiting times keep an agent reboot or opening a printer to change labels from sending events. Each change is sent once.

  • An offline agent covers its printers. While an agent is offline, Printsluis has no current status for its printers and sends no printer events for them. When the agent is back, its printers report again: a printer that still has a problem gets its event then.
  • Changes while a problem lasts. A printer that needed attention for paper out and then reports head open, or becomes unreachable, gets a new event with the new state at once, without a new waiting time.
  • No recovery event without a recovery. An agent that is disabled or revoked while offline gets no agent.online. A printer that is disabled or removed, or whose agent is disabled or revoked, while it has a problem gets no printer.ready. Use GET /v1/agents and GET /v1/printers for the current state.
  • printer.ready and unknown availability. A printer that cannot report its status, such as a generic raw printer, is unknown once its problem is gone. It gets printer.ready with "availability": "unknown".
  • Job status changes other than finishing are not sent. Use GET /v1/print-jobs/{id} for a job’s full history.

New event types may be added. Ignore types you don’t know.

Every request is a JSON POST with these headers:

Header Value
X-Printsluis-Event The event type, such as printer.needs_attention
X-Printsluis-Delivery The delivery ID: the same as the body’s id, and the same for every retry
X-Printsluis-Timestamp Unix seconds when the request was sent
X-Printsluis-Signature v1= and the hex HMAC-SHA256 of timestamp + "." + body, with the endpoint’s secret. Two comma-separated signatures for 24 hours after a secret rotation

The body is an envelope with the event’s data:

{
"id": "0193a6f4-7c2e-7d4a-9b1e-2f6c8d0e4a11",
"type": "print_job.finished",
"createdAt": "2026-11-05T09:14:03.512+00:00",
"data": { }
}

A receiver must:

  1. Verify the signature on the raw body, before parsing it, and reject old timestamps.
  2. Ignore duplicates by id: delivery is at least once.
  3. Not rely on order. Deliveries are retried independently, so a printer.ready can arrive before an older printer.needs_attention. Keep the latest createdAt per agent or printer and ignore older events.
  4. Answer quickly with a 2xx status, within 15 seconds. Do slow work after answering.

Enums are camelCase strings, and times are ISO 8601 with an offset.

{
"id": "0193a6f4-7c2e-7d4a-9b1e-2f6c8d0e4a11",
"type": "print_job.finished",
"createdAt": "2026-11-05T09:14:03.498+00:00",
"data": {
"jobId": "0193a6f3-1b8d-7e55-8a9c-5d3e2f1a0b77",
"status": "failed",
"printerId": "0192f0c1-4a6b-7c3d-9e2f-1a2b3c4d5e6f",
"externalReference": "ORD-1042",
"metadata": { "batch": "B-17" },
"isTest": false,
"failureCode": "printer_unreachable",
"failureMessage": "The agent could not connect to the printer.",
"finishedAt": "2026-11-05T09:14:03.498+00:00"
}
}

status is succeeded, failed, cancelled, expired or indeterminate; see Job states. failureCode and failureMessage are set for failed and indeterminate jobs only.

{
"id": "0193a6f5-0a1b-7c2d-8e3f-4a5b6c7d8e9f",
"type": "agent.offline",
"createdAt": "2026-11-05T09:20:15.002+00:00",
"data": {
"agentId": "0192f0b8-2c4d-7e6f-8a9b-0c1d2e3f4a5b",
"name": "Tilburg warehouse",
"hostname": "TLB-PRINT-01",
"isOnline": false,
"lastSeenAt": "2026-11-05T09:16:58.731+00:00"
}
}
{
"id": "0193a6fb-5e6f-7a0b-8c1d-2e3f4a5b6c7d",
"type": "agent.online",
"createdAt": "2026-11-05T09:42:30.118+00:00",
"data": {
"agentId": "0192f0b8-2c4d-7e6f-8a9b-0c1d2e3f4a5b",
"name": "Tilburg warehouse",
"hostname": "TLB-PRINT-01",
"isOnline": true,
"lastSeenAt": "2026-11-05T09:42:21.640+00:00"
}
}

lastSeenAt is null when the agent was never in contact after pairing. While an agent is offline, its printers receive no jobs, unless another agent reaches them through a route.

printer.needs_attention, printer.unreachable and printer.ready

Section titled “printer.needs_attention, printer.unreachable and printer.ready”
{
"id": "0193a6f6-1b2c-7d3e-8f4a-5b6c7d8e9f0a",
"type": "printer.needs_attention",
"createdAt": "2026-11-05T09:31:45.120+00:00",
"data": {
"printerId": "0192f0c1-4a6b-7c3d-9e2f-1a2b3c4d5e6f",
"friendlyName": "Dock 1 labels",
"location": "Dock 1",
"agentId": "0192f0b8-2c4d-7e6f-8a9b-0c1d2e3f4a5b",
"availability": "needsAttention",
"availabilityDetail": "Paper out",
"availabilityChangedAt": "2026-11-05T09:29:30.004+00:00"
}
}
{
"id": "0193a6f8-3d4e-7f5a-8b6c-7d8e9f0a1b2c",
"type": "printer.unreachable",
"createdAt": "2026-11-05T09:35:00.441+00:00",
"data": {
"printerId": "0192f0c1-4a6b-7c3d-9e2f-1a2b3c4d5e6f",
"friendlyName": "Dock 1 labels",
"location": "Dock 1",
"agentId": "0192f0b8-2c4d-7e6f-8a9b-0c1d2e3f4a5b",
"availability": "unreachable",
"availabilityDetail": "No connection could be made because the target machine actively refused it.",
"availabilityChangedAt": "2026-11-05T09:34:47.912+00:00"
}
}
{
"id": "0193a6f9-4e5f-7a6b-8c7d-8e9f0a1b2c3d",
"type": "printer.ready",
"createdAt": "2026-11-05T09:38:15.776+00:00",
"data": {
"printerId": "0192f0c1-4a6b-7c3d-9e2f-1a2b3c4d5e6f",
"friendlyName": "Dock 1 labels",
"location": "Dock 1",
"agentId": "0192f0b8-2c4d-7e6f-8a9b-0c1d2e3f4a5b",
"availability": "ready",
"availabilityDetail": null,
"availabilityChangedAt": "2026-11-05T09:38:02.310+00:00"
}
}

availability is needsAttention, unreachable, ready or unknown. availabilityDetail is what the printer or its Windows driver reports, such as “Paper out”, “Head open”, “Ribbon out” or “Paused”. It is text to show to people, not a stable code. agentId is the printer’s own agent.

The signature is v1= followed by the lowercase hex HMAC-SHA256 of the timestamp header, a period, and the raw request body, keyed with the endpoint’s whole secret (including whsec_) as UTF-8:

X-Printsluis-Signature: v1=hex(HMAC-SHA256(secret, timestamp + "." + body))

To verify a request:

  1. Read the raw body as bytes or text, exactly as received. Don’t parse and re-serialize it first.
  2. Reject the request if X-Printsluis-Timestamp is more than 5 minutes from your clock. This stops replays of old requests.
  3. Compute the expected signature and compare it, in constant time, with each comma-separated value in X-Printsluis-Signature. The request is genuine if any of them matches.
  4. Answer 401 if it doesn’t match, and don’t process it.

Printsluis.Client has WebhookSignature.Verify, which does all of the above with 5 minutes’ tolerance, and WebhookEventParser, which returns the right envelope for any event type. An ASP.NET Core receiver:

using Printsluis.Client;
using Printsluis.Contracts;
app.MapPost("/webhooks/printsluis", async (HttpRequest request, IConfiguration configuration) =>
{
using var reader = new StreamReader(request.Body);
var body = await reader.ReadToEndAsync();
if (!WebhookSignature.Verify(configuration["Printsluis:WebhookSecret"]!,
request.Headers[WebhookNames.TimestampHeader], body,
request.Headers[WebhookNames.SignatureHeader], DateTimeOffset.UtcNow))
return Results.Unauthorized();
switch (WebhookEventParser.Parse(body))
{
case WebhookEvent finished: // print_job.finished
await jobs.CompleteAsync(finished.Data.JobId, finished.Data.Status);
break;
case WebhookEvent<PrinterStateChanged> printer: // printer.needs_attention, .unreachable, .ready
await printers.ShowAsync(printer.Data.PrinterId, printer.Data.Availability, printer.Data.AvailabilityDetail, printer.CreatedAt);
break;
case WebhookEvent<AgentStateChanged> agent: // agent.offline, agent.online
await agents.ShowAsync(agent.Data.AgentId, agent.Data.IsOnline, agent.CreatedAt);
break;
default: // a newer event type: ignore it
break;
}
return Results.Ok();
});

jobs, printers and agents stand for your own code. An unknown type parses to WebhookEvent<JsonElement>, so Id, Type and CreatedAt are still available.

import crypto from 'node:crypto';
// rawBody: the request body as a Buffer or string, exactly as received.
export function verifyPrintsluisWebhook(secret, timestamp, rawBody, signatureHeader, toleranceSeconds = 300) {
if (!/^\d+$/.test(timestamp ?? '') || !signatureHeader) return false;
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > toleranceSeconds) return false;
const expected = Buffer.from(
'v1=' + crypto.createHmac('sha256', secret).update(`${timestamp}.`).update(rawBody).digest('hex'),
);
return signatureHeader
.split(',')
.map((signature) => Buffer.from(signature.trim()))
.some((signature) => signature.length === expected.length && crypto.timingSafeEqual(signature, expected));
}

With Express, read the raw body with express.raw({ type: 'application/json' }) on the webhook route.

import hashlib
import hmac
import time
def verify_printsluis_webhook(secret: str, timestamp: str | None, raw_body: bytes,
signature_header: str | None, tolerance: int = 300) -> bool:
if not timestamp or not timestamp.isascii() or not timestamp.isdigit() or not signature_header:
return False
if abs(time.time() - int(timestamp)) > tolerance:
return False
digest = hmac.new(secret.encode(), timestamp.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
expected = "v1=" + digest
return any(hmac.compare_digest(expected, signature.strip()) for signature in signature_header.split(","))

Answer with a 2xx status within 15 seconds. Anything else, including a timeout or a redirect, counts as a failure and is retried with backoff:

Attempt After the previous one
1 Right away
2 30 seconds
3 2 minutes
4 10 minutes
5 30 minutes
6 1 hour
7 3 hours
8 6 hours

After the eighth attempt, about 11 hours after the first, the delivery is failed. An admin can redeliver it from the portal, for example after fixing the receiving application. Every attempt and redelivery has the same delivery ID, so your duplicate check still works.

  • Delivery is at least once. The same delivery can arrive more than once, for example when your answer was lost. Store the id of handled deliveries and ignore repeats.
  • Deliveries are not ordered. Each is retried on its own schedule. Compare createdAt with the latest event you handled for the same job, agent or printer, and ignore older ones.
  • For the current state, ask the API: GET /v1/print-jobs/{id}, GET /v1/printers, GET /v1/agents or GET /v1/alerts.

Rotate an endpoint’s secret with Rotate signing secret in the endpoint’s menu, for example when it may have leaked or when someone who knew it leaves. You get a new secret, shown once.

For 24 hours after a rotation, every request carries two signatures in X-Printsluis-Signature, one with the old secret and one with the new, separated by a comma. That gives you a day to deploy the new secret without missing events:

  1. Rotate the secret in the portal and copy the new one.
  2. Deploy it to your application. Requests verify with the old secret until then, and with the new one after.
  3. After 24 hours, requests are signed with the new secret only.

Verifiers that check every comma-separated signature, as above and as WebhookSignature.Verify does, need no change for this.