Skip to main content
The Caretly package is async throughout and has no runtime dependencies. It targets netstandard2.0 and net8.0, so it runs on .NET Framework 4.6.1+, .NET Core and .NET 5+.

Install

Quickstart

Create a test key in the console and set it in your environment:
Render a label to PDF and save it:
You can also pass the key directly: new CaretlyClient("zpl_test_...").

Render a page as PNG

A PNG holds one page. Choose it with Page, starting at 1:
client.RenderPdfAsync(zpl) is the matching shorthand for a PDF.

Render several files

RenderFilesAsync sends the files as multipart/form-data. Each file starts from a fresh printer state, and pages follow the given order:
ZplFile takes a name and the ZPL as a string or byte[]. ZplFile.FromPath reads a file from disk.

Render options

An invalid Page, Dpmm or IdempotencyKey throws an ArgumentException before sending.

Read the result

RenderResult exposes:

Handle errors

Every error derives from CaretlyException. Error responses throw a CaretlyApiException subclass with StatusCode, ResponseBody (the server’s message) and RetryAfter:
Every method takes an optional CancellationToken. Cancelling it throws an OperationCanceledException, not a CaretlyTimeoutException.

Retries and idempotency

The client retries 429 and 503 responses and connection errors up to MaxRetries times, 2 by default. It waits Retry-After when the server sends it. Otherwise it backs off 0.5 s, 1 s, 2 s, up to 8 s. Timeouts and other errors aren’t retried. When retries are on and you don’t set IdempotencyKey, the client generates a UUID once per call and sends it with every attempt, so a retried request is never billed twice. Set your own key, such as an order number, to make retries across calls or processes safe too:

Configuration

Inject an HttpClient

Pass your own HttpClient, for example from IHttpClientFactory. The Caretly client doesn’t dispose it. When BaseUrl isn’t set, it uses the HttpClient.BaseAddress if there is one.

Health check