POST
/
api
/
templates
/
by-name
/
{templateName}
/
pdf
Generate PDF from template by name
curl --request POST \
  --url https://peedief.com/api/templates/by-name/{templateName}/pdf \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '{
  "contextJson": {},
  "fileName": "<string>"
}'
{
  "success": true,
  "downloadUrl": "<string>",
  "fileName": "<string>",
  "fileSize": 123,
  "templateId": "<string>",
  "templateName": "<string>"
}

Generate PDF from Template

Create a PDF using your custom template and structured JSON data. This is the primary endpoint for template-based PDF generation.

Path Parameters

  • templateName (string, required): The name of your custom template created in the dashboard

Request Headers

  • x-api-key (string, required): Your API key for authentication
  • Content-Type: application/json

Request Body

{
  "contextJson": {
    // Your template data - structure depends on your template
    "customerName": "John Doe",
    "invoiceNumber": "INV-001",
    "amount": 150.00
  },
  "fileName": "optional-filename.pdf"
}

Response

Success (200):
{
  "success": true,
  "downloadUrl": "https://peedief.com/download/abc123...",
  "fileName": "invoice-001.pdf",
  "fileSize": 245760,
  "templateId": "tpl_abc123",
  "templateName": "invoice"
}
Error (400/401/404):
{
  "success": false,
  "error": "Template not found",
  "code": "TEMPLATE_NOT_FOUND"
}

Example Request

curl -X POST "https://peedief.com/api/templates/by-name/my-invoice-template/pdf" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contextJson": {
      "companyName": "Acme Corp",
      "customerInfo": {
        "name": "Jane Smith",
        "email": "jane@example.com",
        "address": "123 Main St, City, State 12345"
      },
      "items": [
        {
          "description": "Product A",
          "quantity": 2,
          "price": 50.00
        }
      ],
      "total": 100.00,
      "dueDate": "2024-02-15"
    },
    "fileName": "invoice-jane-smith.pdf"
  }'

Template Data Structure

The contextJson object structure depends entirely on your template design. Common patterns include: Certificate Template:
{
  "contextJson": {
    "recipientName": "John Smith",
    "courseName": "Advanced JavaScript",
    "completionDate": "2024-01-30",
    "instructor": "Dr. Sarah Wilson",
    "grade": "A+"
  }
}
Invoice Template:
{
  "contextJson": {
    "invoiceNumber": "INV-2024-001",
    "customerName": "TechStart Inc",
    "services": [
      {
        "description": "Web Development",
        "hours": 40,
        "rate": 125.00
      }
    ],
    "subtotal": 5000.00,
    "taxRate": 0.08,
    "total": 5400.00
  }
}

Error Codes

  • TEMPLATE_NOT_FOUND: Template with specified name doesn’t exist
  • INVALID_API_KEY: API key is invalid or expired
  • MISSING_TEMPLATE_DATA: Required template fields are missing
  • QUOTA_EXCEEDED: Account has exceeded PDF generation limits

Authorizations

x-api-key
string
header
required

Path Parameters

templateName
string
required

URL-encoded name of the template to use for PDF generation

Body

application/json
contextJson
object
required

JSON object containing the data to populate the template variables

fileName
string

Optional filename for the generated PDF (defaults to templateName-timestamp.pdf)

Response

PDF generated successfully

success
boolean

Whether the PDF generation was successful

Example:

true

downloadUrl
string

Signed URL to download the generated PDF (expires in 1 hour)

fileName
string

Name of the generated PDF file

fileSize
integer

Size of the generated PDF in bytes

templateId
string

ID of the template used for generation

templateName
string

Name of the template used for generation