Guides Editors API Reference
Help
Documentation

Get a Single Template

Get a single template

To retrieve a specific template, send a GET request to /api/templates/{template}, where {template} is the unique identifier of the template you want to retrieve. You will receive a JSON response containing the details of the requested template.

GET /api/templates/{template}

Headers

Authorization*

The Authorization header is used to authenticate the request. You need to provide a valid API key in the format Bearer {token}. You can generate an API token from the API Tokens page. Read more about API Authentication for detailed instructions.

Content-Type Default: application/json

The Content-Type header is used to specify the format of the request payload. This must be application/json or null.

Example Request

Here's an example of a GET request to retrieve a specific template. In this example, we're using the curl command-line tool to send a GET request to the API.

curl -X GET "https://pdf-api.io/api/templates/1234567890" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer {token}"

Example Response

The response will be a JSON object containing the details of the requested template. The template object includes the following fields:

  • id: The unique identifier of the template
  • name: The name of the template
  • type: The type of the template (e.g., "editor" or "html")
  • created_at: The creation date of the template
  • meta: Additional metadata associated with the template
  • variables: An array of variables used in the template

Here's an example of the response structure:

{
  "id": "1234567890",
  "name": "Invoice Template",
  "type": "editor",
  "created_at": "2023-04-15T10:30:00Z",
  "meta": {
    "description": "A simple invoice template"
  },
  "variables": [
    {
      "name": "customer_name",
      "type": "string"
    },
    {
      "name": "invoice_items",
      "type": "array"
    },
    {
      "name": "invoice_items[]",
      "type": "object"
    },
    {
      "name": "invoice_items[].description",
      "type": "string"
    },
    {
      "name": "invoice_items[].amount",
      "type": "string"
    }
  ]
}

Understanding the variables Field

The variables field provides information about the dynamic content that can be inserted into the template. Each variable object in the array contains:

  • name: The name of the variable, which can be used to populate the template with data
  • type: The expected data type of the variable (e.g., "string", "array", or "object")

For array variables, you'll notice three related entries:

  1. The array itself (e.g., invoice_items)
  2. An entry for the array items (e.g., invoice_items[])
  3. Individual fields within the array items (e.g., invoice_items[].description)

This structure allows you to understand how to format your data when using the template, especially for complex structures like tables or repeatable sections.