Skip to Content

C#

Official .NET SDK for TemplateFox.

NuGet version GitHub Repository 

Installation

dotnet add package TemplateFox.SDK

Or via Package Manager:

Install-Package TemplateFox.SDK

Generate a PDF

using TemplateFox.SDK.Api; using TemplateFox.SDK.Client; using TemplateFox.SDK.Model; // Initialize the client var config = new Configuration { ApiKey = new Dictionary<string, string> { { "x-api-key", "your-api-key" } } }; var api = new PDFApi(config); // Generate a PDF var request = new CreatePdfRequest( templateId: "YOUR_TEMPLATE_ID", data: new Dictionary<string, object> { { "name", "John Doe" }, { "invoice_number", "INV-001" }, { "total_amount", 150.00 } } ); try { var response = await api.CreatePdfAsync(request); Console.WriteLine($"PDF URL: {response.Url}"); Console.WriteLine($"Credits remaining: {response.CreditsRemaining}"); } catch (ApiException e) { Console.WriteLine($"Error: {e.Message}"); }

Save PDF to File

using var httpClient = new HttpClient(); var response = await api.CreatePdfAsync(request); // Download and save locally var pdfBytes = await httpClient.GetByteArrayAsync(response.Url); await File.WriteAllBytesAsync("invoice.pdf", pdfBytes);

Error Handling

using TemplateFox.SDK.Client; try { var response = await api.CreatePdfAsync(request); } catch (ApiException e) { Console.WriteLine($"Status: {e.ErrorCode}"); Console.WriteLine($"Message: {e.ErrorContent}"); }

Available Methods

The SDK covers all TemplateFox API endpoints through four service classes:

ClassMethodDescription
PDFApiCreatePdfAsyncGenerate a PDF from a template
TemplatesApiListTemplatesAsyncList all templates in your team
TemplatesApiGetTemplateFieldsAsyncGet data fields for a template
AccountApiGetAccountAsyncGet account info and credit balance
AccountApiListTransactionsAsyncList credit transaction history
IntegrationsApiSaveS3ConfigAsyncConfigure S3 storage integration
IntegrationsApiGetS3ConfigAsyncGet current S3 configuration
IntegrationsApiDeleteS3ConfigAsyncRemove S3 configuration
IntegrationsApiTestS3ConnectionAsyncTest S3 bucket connectivity

Configuration

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

Quick Testing

Want to test the API before integrating the SDK? Use our Postman collection  to try all endpoints interactively.

Full SDK Reference

For the complete API coverage including templates, account, S3 integration, and error handling, see the GitHub repository README .

Last updated on