Skip to content

C# SDK & REST Examples — TemplateFox

Two ways to use the TemplateFox API from .NET:

  • SDK (TemplateFox.SDK) — typed client auto-generated from our OpenAPI spec. Recommended.
  • REST — HttpClient. Useful for minimal dependencies.

Every example on this page shows both side-by-side.

NuGet version GitHub Repository

Terminal window
dotnet add package TemplateFox.SDK
# or Package Manager:
Install-Package TemplateFox.SDK

The REST variant uses System.Net.Http (part of .NET).

Set your API key once and reuse the client.

using TemplateFox.SDK.Api;
using TemplateFox.SDK.Client;

var config = new Configuration
{
  ApiKey = new Dictionary<string, string>
  {
      { "x-api-key", Environment.GetEnvironmentVariable("TEMPLATEFOX_API_KEY")! }
  }
};

var api = new PDFApi(config);

The minimum required fields are template_id and data. Everything else has a sensible default.

using TemplateFox.SDK.Model;

var request = new CreatePdfRequest(
  templateId: "YOUR_TEMPLATE_ID",
  data: new Dictionary<string, object>
  {
      { "customer_name",  "John Doe" },
      { "invoice_number", "INV-001" },
      { "amount",         "$1,234.56" }
  }
);

var response = await api.CreatePdfAsync(request);

Console.WriteLine(response.Url);               // signed URL valid 24h
Console.WriteLine(response.CreditsRemaining);  // credits left on the team

See Create PDF for every supported parameter.

using var httpClient = new HttpClient();

var response = await api.CreatePdfAsync(request);

var pdfBytes = await httpClient.GetByteArrayAsync(response.Url);
await File.WriteAllBytesAsync("invoice.pdf", pdfBytes);

Configure your S3 integration once in the dashboard, then pass StoreS3 = true on any call.

using TemplateFox.SDK.Model;

var request = new CreatePdfRequest(
  templateId: "YOUR_TEMPLATE_ID",
  data: new Dictionary<string, object> { { "invoice_number", "INV-001" } },
  filename:   "invoice-001",            // no extension, .pdf appended
  storeS3:    true,                      // upload to your configured bucket
  s3Filepath: "invoices/2026/04/"       // key prefix (optional)
  // s3Bucket: "custom-bucket"          // override bucket from integration
);

var response = await api.CreatePdfAsync(request);
Console.WriteLine($"{response.S3Bucket}/{response.S3Key}");

For archival/legal use-cases, request a PDF/A variant.

using TemplateFox.SDK.Model;

var request = new CreatePdfRequest(
  templateId: "YOUR_TEMPLATE_ID",
  data:       new Dictionary<string, object> { { "customer_name", "John Doe" } },
  pdfVariant: "pdf/a-2b"   // "pdf/a-1b" | "pdf/a-2b" | "pdf/a-3b"
);

var response = await api.CreatePdfAsync(request);

For large documents or batch jobs, use the async endpoint. The .NET SDK exposes CreatePdfAsyncJobAsync, GetPdfJobAsync, and ListPdfJobsAsync — see Create PDF (Async) for the full flow.

using TemplateFox.SDK.Model;

var request = new CreatePdfAsyncRequest(
  templateId:    "YOUR_TEMPLATE_ID",
  data:          new Dictionary<string, object> { { "invoice_number", "INV-001" } },
  webhookUrl:    "https://example.com/webhooks/pdf",
  webhookSecret: "whk_a1b2c3d4e5f6g7h8i9j0k1l2"   // HMAC-SHA256 signing
);

var response = await api.CreatePdfAsyncJobAsync(request);
Console.WriteLine(response.JobId);
// Poll await api.GetPdfJobAsync(jobId) or wait for the webhook.
using TemplateFox.SDK.Client;

try
{
  var response = await api.CreatePdfAsync(request);
}
catch (ApiException e)
{
  Console.WriteLine($"status={e.ErrorCode} body={e.ErrorContent}");
}

See Error codes for the full list.

ClassMethodEndpoint
PDFApiCreatePdfAsyncPOST /v1/pdf/create
PDFApiCreatePdfAsyncJobAsyncPOST /v1/pdf/create-async
PDFApiGetPdfJobAsyncGET /v1/pdf/jobs/{id}
PDFApiListPdfJobsAsyncGET /v1/pdf/jobs
TemplatesApiListTemplatesAsyncGET /v1/templates
TemplatesApiGetTemplateFieldsAsyncGET /v1/templates/{id}/fields
AccountApiGetAccountAsyncGET /v1/account
AccountApiListTransactionsAsyncGET /v1/account/transactions
IntegrationsApiSaveS3ConfigAsyncPOST /v1/integrations/s3
IntegrationsApiGetS3ConfigAsyncGET /v1/integrations/s3
IntegrationsApiDeleteS3ConfigAsyncDELETE /v1/integrations/s3
IntegrationsApiTestS3ConnectionAsyncPOST /v1/integrations/s3/test

All REST endpoints are documented in the API Reference.