PHP
Official PHP SDK for TemplateFox.
Installation
composer require templatefox/sdkGenerate a PDF
<?php
require_once __DIR__ . '/vendor/autoload.php';
use TemplateFox\Api\PDFApi;
use TemplateFox\Configuration;
use TemplateFox\Model\CreatePdfRequest;
// Initialize the client
$config = Configuration::getDefaultConfiguration()
->setApiKey('x-api-key', 'your-api-key');
$api = new PDFApi(null, $config);
// Generate a PDF
$request = new CreatePdfRequest([
'template_id' => 'YOUR_TEMPLATE_ID',
'data' => [
'name' => 'John Doe',
'invoice_number' => 'INV-001',
'total_amount' => 150.00,
],
]);
try {
$response = $api->createPdf($request);
echo "PDF URL: " . $response->getUrl() . "\n";
echo "Credits remaining: " . $response->getCreditsRemaining() . "\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}Save PDF to File
$response = $api->createPdf($request);
// Download and save locally
file_put_contents('invoice.pdf', file_get_contents($response->getUrl()));Error Handling
use TemplateFox\ApiException;
try {
$response = $api->createPdf($request);
} catch (ApiException $e) {
echo "Status: " . $e->getCode() . "\n";
echo "Message: " . $e->getResponseBody() . "\n";
}Available Methods
The SDK covers all TemplateFox API endpoints through four service classes:
| Class | 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
$config = Configuration::getDefaultConfiguration()
->setApiKey('x-api-key', getenv('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