Go
Official Go SDK for TemplateFox.
Installation
go get github.com/TemplateFoxPDF/gosdkGenerate a PDF
package main
import (
"context"
"fmt"
"log"
templatefox "github.com/TemplateFoxPDF/gosdk"
)
func main() {
// Initialize the client
config := templatefox.NewConfiguration()
config.AddDefaultHeader("x-api-key", "your-api-key")
client := templatefox.NewAPIClient(config)
ctx := context.Background()
// Generate a PDF
request := templatefox.CreatePdfRequest{
TemplateId: "YOUR_TEMPLATE_ID",
Data: map[string]interface{}{
"name": "John Doe",
"invoice_number": "INV-001",
"total_amount": 150.00,
},
}
response, _, err := client.PDFApi.CreatePdf(ctx, request)
if err != nil {
log.Fatal(err)
}
fmt.Printf("PDF URL: %s\n", *response.Url)
fmt.Printf("Credits remaining: %d\n", *response.CreditsRemaining)
}Save PDF to File
import (
"io"
"net/http"
"os"
)
response, _, err := client.PDFApi.CreatePdf(ctx, templatefox.CreatePdfRequest{
TemplateId: "YOUR_TEMPLATE_ID",
Data: map[string]interface{}{"name": "Jane Doe"},
})
if err != nil {
log.Fatal(err)
}
// Download and save locally
resp, _ := http.Get(*response.Url)
defer resp.Body.Close()
file, _ := os.Create("invoice.pdf")
defer file.Close()
io.Copy(file, resp.Body)Error Handling
response, httpResp, err := client.PDFApi.CreatePdf(ctx, request)
if err != nil {
if apiErr, ok := err.(templatefox.GenericOpenAPIError); ok {
fmt.Printf("Status: %d\n", httpResp.StatusCode)
fmt.Printf("Message: %s\n", apiErr.Body())
}
log.Fatal(err)
}Available Methods
The SDK covers all TemplateFox API endpoints through four service groups:
| Service | Method | Description |
|---|---|---|
PDFApi | CreatePdf | Generate a PDF from a template |
TemplatesApi | ListTemplates | List all templates in your team |
TemplatesApi | GetTemplateFields | Get data fields for a template |
AccountApi | GetAccount | Get account info and credit balance |
AccountApi | ListTransactions | List credit transaction history |
IntegrationsApi | SaveS3Config | Configure S3 storage integration |
IntegrationsApi | GetS3Config | Get current S3 configuration |
IntegrationsApi | DeleteS3Config | Remove S3 configuration |
IntegrationsApi | TestS3Connection | Test S3 bucket connectivity |
Configuration
import "os"
config := templatefox.NewConfiguration()
config.AddDefaultHeader("x-api-key", os.Getenv("TEMPLATEFOX_API_KEY"))
client := templatefox.NewAPIClient(config)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