Skip to Content

Go

Official Go SDK for TemplateFox.

Go Reference GitHub Repository 

Installation

go get github.com/TemplateFoxPDF/gosdk

Generate 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:

ServiceMethodDescription
PDFApiCreatePdfGenerate a PDF from a template
TemplatesApiListTemplatesList all templates in your team
TemplatesApiGetTemplateFieldsGet data fields for a template
AccountApiGetAccountGet account info and credit balance
AccountApiListTransactionsList credit transaction history
IntegrationsApiSaveS3ConfigConfigure S3 storage integration
IntegrationsApiGetS3ConfigGet current S3 configuration
IntegrationsApiDeleteS3ConfigRemove S3 configuration
IntegrationsApiTestS3ConnectionTest 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