Skip to Content
SDKs and Code ExamplesTypeScript SDK

TypeScript

Official TypeScript/Node.js SDK for TemplateFox.

npm version GitHub Repository 

Installation

npm install @templatefox/sdk

Or with yarn:

yarn add @templatefox/sdk

Generate a PDF

import { Configuration, PDFApi, CreatePdfRequest } from '@templatefox/sdk'; // Initialize the client const config = new Configuration({ apiKey: 'your-api-key', }); const api = new PDFApi(config); // Generate a PDF async function generatePdf() { const response = await api.createPdf({ templateId: 'YOUR_TEMPLATE_ID', data: { name: 'John Doe', invoiceNumber: 'INV-001', totalAmount: 150.00, }, }); console.log('PDF URL:', response.url); console.log('Credits remaining:', response.creditsRemaining); } generatePdf();

Save PDF to File

import * as fs from 'fs'; const response = await api.createPdf({ templateId: 'YOUR_TEMPLATE_ID', data: { name: 'Jane Doe', invoiceNumber: 'INV-042' }, }); // Download and save locally const pdfResponse = await fetch(response.url); const buffer = Buffer.from(await pdfResponse.arrayBuffer()); fs.writeFileSync('invoice.pdf', buffer);

Error Handling

import { ResponseError } from '@templatefox/sdk'; try { const response = await api.createPdf({ templateId: 'INVALID_ID', data: {} }); } catch (error) { if (error instanceof ResponseError) { console.error(`Status: ${error.response.status}`); const body = await error.response.json(); console.error(`Message: ${body.detail}`); } }

Available Methods

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

ClassMethodDescription
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

const config = new Configuration({ apiKey: process.env.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