Skip to main content

.NET SDK

Use the official Pritset .NET SDK to manage DOCX templates and generate PDFs from your .NET application.

View the official .NET SDK repository on GitHub

Requirementsโ€‹

  • .NET 8 or .NET 10 for fully supported builds
  • .NET 5, 6, and 7 are supported on a best-effort basis through netstandard2.0
  • A Pritset access token and secret from the Profile page

The package targets netstandard2.0 and net8.0 and works with Task, CancellationToken, Stream, and an optional caller-owned HttpClient.

Compatibilityโ€‹

This page documents SDK version 0.1.5, which implements Pritset SDK contract 1.0.0.

Install the packageโ€‹

Install version 0.1.5 from NuGet:

dotnet add package Pritset --version 0.1.5

Create a clientโ€‹

Store your credentials in environment variables rather than source code. Pritset sends the access token directly in the Authorization header and the secret in X-Secret; do not add a Bearer prefix.

using Pritset;

string token = Environment.GetEnvironmentVariable("PRITSET_ACCESS_TOKEN")
?? throw new InvalidOperationException("Set PRITSET_ACCESS_TOKEN.");
string secret = Environment.GetEnvironmentVariable("PRITSET_SECRET")
?? throw new InvalidOperationException("Set PRITSET_SECRET.");

using var client = new PritsetClient(token, secret);

The client redacts credentials in its ToString() output. Do not commit or log either credential.

Generate a PDFโ€‹

Upload a DOCX template first and copy its ID. See Template management for upload requirements and the portal workflow.

using Pritset;

using BinaryResponse pdf = await client.Documents.GenerateAsync(
"YOUR_TEMPLATE_ID",
new
{
invoice = new { number = "INV-1042", customer = "Ada Lovelace" },
});

await pdf.SaveToFileAsync("invoice.pdf");

GenerateAsync streams the response. Dispose the returned BinaryResponse after saving it or copying pdf.Stream to your own destination stream. Response metadata is available through ContentType, ContentLength, and Trace.

The object passed as the second argument becomes the template data. Its shape must match the placeholders and loops in your DOCX file; see Templating syntax.

Manage templatesโ€‹

Use client.Templates to list, retrieve, create, update, download, validate, and delete templates.

using Pritset;
using Pritset.Models;

TemplatePage page = await client.Templates.ListAsync(new ListTemplatesOptions
{
Query = "invoice",
Page = 1,
PageSize = 25,
SortBy = "name",
SortDirection = SortDirection.Ascending,
});

using Upload document = Upload.FromPath("invoice.docx");
Template created = await client.Templates.CreateAsync(new CreateTemplateRequest
{
Name = "Monthly invoice",
Tags = "invoice,monthly",
Template = document,
});

Retrieve the complete template record, including file metadata, then update its name and tags. The Template upload is optional on update; provide one to replace the DOCX file.

TemplateDetails details = await client.Templates.GetAsync(created.Id);
Console.WriteLine($"{details.FileInfo.ObjectName}: {details.FileInfo.Size}");

using Upload replacement = Upload.FromPath("invoice-2026.docx");
Template updated = await client.Templates.UpdateAsync(created.Id, new UpdateTemplateRequest
{
Name = "Monthly invoice 2026",
Tags = "invoice,monthly,2026",
Template = replacement, // optional replacement file
});

Upload.FromPath owns the opened file stream, so dispose the Upload after the request. Uploads created from a caller-provided stream leave that stream open by default.

using BinaryResponse source = await client.Templates.DownloadAsync(created.Id);
await source.SaveToFileAsync("invoice.docx");

using Upload validationDocument = Upload.FromPath("invoice.docx");
bool valid = await client.Templates.ValidateAsync(
validationDocument,
new { invoice = new { number = "INV-1042" } });

await client.Templates.DeleteAsync(created.Id);

For endpoint behavior and limits, see the Template management API reference.

Raw JSONโ€‹

Pass a JSON string when data is already encoded. Invalid JSON is rejected before a request is sent.

using BinaryResponse pdf = await client.Documents.GenerateAsync(
"YOUR_TEMPLATE_ID",
"{\"name\":\"Ada\"}");

Generate through a webhookโ€‹

Use GenerateWebhookAsync when Pritset should send the generation result to your endpoint. The webhook URL must be an absolute HTTP(S) URL without embedded credentials.

using Pritset.Models;

WebhookJob job = await client.Documents.GenerateWebhookAsync(
"YOUR_TEMPLATE_ID",
new { invoice = new { number = "INV-1042" } },
new Uri("https://example.com/webhooks/pritset"));

The SDK submits the URL to Pritset; it does not call the webhook itself. See Direct and webhook processing for the API workflow.

Handle errors and cancellationโ€‹

The SDK raises PritsetApiException for API responses with an error status and PritsetTransportException for timeouts, cancellation, and transport failures. It does not retry automatically.

using Pritset;
using Pritset.Exceptions;

using var cancellation = new CancellationTokenSource();

try
{
using BinaryResponse pdf = await client.Documents.GenerateAsync(
"YOUR_TEMPLATE_ID",
new { name = "Ada Lovelace" },
cancellation.Token);
}
catch (PritsetApiException exception)
{
Console.WriteLine($"HTTP {exception.StatusCode}; trace ID: {exception.TraceId}");
}
catch (PritsetTransportException exception)
{
Console.WriteLine($"Timed out: {exception.IsTimeout}; canceled: {exception.IsCanceled}");
}

Set a custom timeout when creating the client:

using var client = new PritsetClient(token, secret, new PritsetClientOptions
{
Timeout = TimeSpan.FromSeconds(90),
});

See API errors for status codes and retry guidance.

Local development and custom HTTP clientsโ€‹

The SDK uses https://api.pritset.com by default and disables automatic redirects on the HTTP client it creates. HTTP is allowed only for exact loopback development endpoints such as http://127.0.0.1:8080.

If you inject an HttpClient, you own its lifetime. Disable redirects on its handler and set HttpClientIsRedirectSafe to acknowledge that configuration:

var handler = new HttpClientHandler { AllowAutoRedirect = false };
var httpClient = new HttpClient(handler);

using var client = new PritsetClient(token, secret, new PritsetClientOptions
{
HttpClient = httpClient,
HttpClientIsRedirectSafe = true,
Timeout = TimeSpan.FromSeconds(90),
});

Next stepsโ€‹