C#
Official .NET SDK for TemplateFox.
Installation
dotnet add package TemplateFox.SDKOr via Package Manager:
Install-Package TemplateFox.SDKGenerate 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:
| Class | Method | Description |
|---|---|---|
PDFApi | CreatePdfAsync | Generate a PDF from a template |
TemplatesApi | ListTemplatesAsync | List all templates in your team |
TemplatesApi | GetTemplateFieldsAsync | Get data fields for a template |
AccountApi | GetAccountAsync | Get account info and credit balance |
AccountApi | ListTransactionsAsync | List credit transaction history |
IntegrationsApi | SaveS3ConfigAsync | Configure S3 storage integration |
IntegrationsApi | GetS3ConfigAsync | Get current S3 configuration |
IntegrationsApi | DeleteS3ConfigAsync | Remove S3 configuration |
IntegrationsApi | TestS3ConnectionAsync | Test 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