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.
Installation
Section titled “Installation”dotnet add package TemplateFox.SDK# or Package Manager:Install-Package TemplateFox.SDKThe REST variant uses System.Net.Http (part of .NET).
Configuration
Section titled “Configuration”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); Generate a PDF
Section titled “Generate a PDF”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.
Save the PDF to a file
Section titled “Save the PDF to a file”using var httpClient = new HttpClient();
var response = await api.CreatePdfAsync(request);
var pdfBytes = await httpClient.GetByteArrayAsync(response.Url);
await File.WriteAllBytesAsync("invoice.pdf", pdfBytes); Upload straight to your S3 bucket
Section titled “Upload straight to your S3 bucket”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}"); PDF/A compliance
Section titled “PDF/A compliance”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); Async generation with webhooks
Section titled “Async generation with webhooks”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. Error handling
Section titled “Error handling”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.
Available SDK methods
Section titled “Available SDK methods”| Class | Method | Endpoint |
|---|---|---|
PDFApi | CreatePdfAsync | POST /v1/pdf/create |
PDFApi | CreatePdfAsyncJobAsync | POST /v1/pdf/create-async |
PDFApi | GetPdfJobAsync | GET /v1/pdf/jobs/{id} |
PDFApi | ListPdfJobsAsync | GET /v1/pdf/jobs |
TemplatesApi | ListTemplatesAsync | GET /v1/templates |
TemplatesApi | GetTemplateFieldsAsync | GET /v1/templates/{id}/fields |
AccountApi | GetAccountAsync | GET /v1/account |
AccountApi | ListTransactionsAsync | GET /v1/account/transactions |
IntegrationsApi | SaveS3ConfigAsync | POST /v1/integrations/s3 |
IntegrationsApi | GetS3ConfigAsync | GET /v1/integrations/s3 |
IntegrationsApi | DeleteS3ConfigAsync | DELETE /v1/integrations/s3 |
IntegrationsApi | TestS3ConnectionAsync | POST /v1/integrations/s3/test |
All REST endpoints are documented in the API Reference.
Next steps
Section titled “Next steps”- Create PDF — every parameter in detail
- Create PDF Async — webhooks + polling
- GitHub repository — source, changelog, issues
- Postman collection — test endpoints interactively