> ## Documentation Index
> Fetch the complete documentation index at: https://docs.curatepdf.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Template

> Retrieve a specific PDF template by its unique identifier

## Overview

The Get Template endpoint allows you to retrieve a specific PDF template using its unique identifier. This is useful for viewing template details, editing existing templates, or preparing to generate PDFs from a specific template.

<Info>
  Use this endpoint to fetch template configuration data before generating PDFs or when building template management interfaces.
</Info>

## Path Parameters

The endpoint requires a single path parameter to identify the template:

<ParamField path="id" type="string" required>
  The unique identifier of the template you want to retrieve.

  **Example:** `template_123abc`
</ParamField>

## Response Structure

The response contains the complete template object with all configuration details:

<ResponseField name="success" type="boolean">
  Indicates whether the request was successful
</ResponseField>

<ResponseField name="template" type="object">
  The complete template object containing all template data

  <Expandable title="Template Object Properties">
    <ResponseField name="id" type="string">
      Unique identifier for the template
    </ResponseField>

    <ResponseField name="name" type="string">
      Human-readable name of the template
    </ResponseField>

    <ResponseField name="template" type="object">
      The template configuration object containing layout, styling, and element definitions
    </ResponseField>

    <ResponseField name="created_at" type="string">
      ISO 8601 timestamp when the template was created
    </ResponseField>

    <ResponseField name="updated_at" type="string">
      ISO 8601 timestamp when the template was last modified
    </ResponseField>

    <ResponseField name="user_id" type="string">
      ID of the user who owns the template
    </ResponseField>
  </Expandable>
</ResponseField>

## Usage Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.curatepdf.com/api/templates/template_123abc" \
    -H "x-api-key: YOUR_API_KEY"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.curatepdf.com/api/templates/template_123abc', {
    method: 'GET',
    headers: {
      'x-api-key': 'YOUR_API_KEY'
    }
  });

  const result = await response.json();
  console.log('Template:', result.template);
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.curatepdf.com/api/templates/template_123abc"
  headers = {
      "x-api-key": "YOUR_API_KEY"
  }

  response = requests.get(url, headers=headers)
  template_data = response.json()

  print(f"Template Name: {template_data['template']['name']}")
  ```

  ```php PHP theme={null}
  <?php
  $templateId = 'template_123abc';
  $url = "https://api.curatepdf.com/api/templates/{$templateId}";

  $headers = [
      'x-api-key: YOUR_API_KEY'
  ];

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  $response = curl_exec($ch);
  $templateData = json_decode($response, true);

  echo "Template Name: " . $templateData['template']['name'];
  curl_close($ch);
  ?>
  ```

  ```go Go theme={null}
  package main

  import (
      "fmt"
      "io"
      "net/http"
      "encoding/json"
  )

  func main() {
      templateID := "template_123abc"
      url := fmt.Sprintf("https://api.curatepdf.com/api/templates/%s", templateID)
      
      req, _ := http.NewRequest("GET", url, nil)
      req.Header.Add("x-api-key", "YOUR_API_KEY")
      
      client := &http.Client{}
      resp, err := client.Do(req)
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()
      
      body, _ := io.ReadAll(resp.Body)
      
      var result map[string]interface{}
      json.Unmarshal(body, &result)
      
      template := result["template"].(map[string]interface{})
      fmt.Printf("Template Name: %s\n", template["name"])
  }
  ```
</CodeGroup>

## Response Example

```json Example Response theme={null}
{
  "success": true,
  "template": {
    "id": "template_123abc",
    "name": "Invoice Template",
    "template": {
      "size": {
        "width": 595,
        "height": 842,
        "orientation": "portrait"
      },
      "margins": {
        "top": 72,
        "right": 72,
        "bottom": 72,
        "left": 72
      },
      "sections": {
        "header": {
          "visible": true,
          "height": 100,
          "elements": [
            {
              "type": "text",
              "content": "{{company.name}}",
              "position": {
                "x": 50,
                "y": 20,
                "width": 300,
                "height": 40
              },
              "style": {
                "fontSize": 24,
                "fontWeight": "bold",
                "color": "#000000"
              }
            }
          ]
        },
        "content": {
          "visible": true,
          "elements": [
            {
              "type": "text",
              "content": "Invoice #{{invoiceNumber}}",
              "position": {
                "x": 50,
                "y": 50,
                "width": 200,
                "height": 30
              },
              "style": {
                "fontSize": 18,
                "fontWeight": "bold"
              }
            }
          ]
        },
        "footer": {
          "visible": false,
          "elements": []
        }
      }
    },
    "created_at": "2024-01-01T00:00:00.000Z",
    "updated_at": "2024-01-02T12:30:00.000Z",
    "user_id": "user_123"
  }
}
```

## Error Responses

The endpoint may return the following responses:

<ResponseExample>
  ```json 200 - Success theme={null}
  {
    "success": true,
    "template": {
      "id": "template_123abc",
      "name": "Invoice Template",
      "template": {
        "size": {
          "width": 595,
          "height": 842,
          "orientation": "portrait"
        },
        "margins": {
          "top": 72,
          "right": 72,
          "bottom": 72,
          "left": 72
        },
        "sections": {
          "header": {
            "visible": true,
            "height": 100,
            "elements": [
              {
                "type": "text",
                "content": "{{company.name}}",
                "position": {
                  "x": 50,
                  "y": 20,
                  "width": 300,
                  "height": 40
                },
                "style": {
                  "fontSize": 24,
                  "fontWeight": "bold",
                  "color": "#000000"
                }
              }
            ]
          },
          "content": {
            "visible": true,
            "elements": [
              {
                "type": "text",
                "content": "Invoice #{{invoiceNumber}}",
                "position": {
                  "x": 50,
                  "y": 50,
                  "width": 200,
                  "height": 30
                },
                "style": {
                  "fontSize": 18,
                  "fontWeight": "bold"
                }
              }
            ]
          },
          "footer": {
            "visible": false,
            "elements": []
          }
        }
      },
      "created_at": "2024-01-01T00:00:00.000Z",
      "updated_at": "2024-01-02T12:30:00.000Z",
      "user_id": "user_123"
    }
  }
  ```

  ```json 401 - Authentication Failed theme={null}
  {
    "success": false,
    "error": {
      "code": "UNAUTHORIZED",
      "message": "Authentication required"
    }
  }
  ```

  ```json 404 - Template Not Found theme={null}
  {
    "success": false,
    "error": {
      "code": "TEMPLATE_NOT_FOUND",
      "message": "Template not found"
    }
  }
  ```

  ```json 500 - Database Error theme={null}
  {
    "success": false,
    "error": {
      "code": "DATABASE_ERROR",
      "message": "An error occurred while retrieving the template"
    }
  }
  ```
</ResponseExample>

## Use Cases

<CardGroup cols={2}>
  <Card title="Template Preview" icon="eye">
    **Display Templates**

    Fetch template details to show previews in your application's template gallery or management interface.
  </Card>

  <Card title="PDF Generation" icon="file-pdf">
    **Pre-Generation Setup**

    Retrieve template configuration before generating PDFs to validate data requirements or show generation options.
  </Card>

  <Card title="Template Editing" icon="pen-to-square">
    **Modification Workflow**

    Load existing template data into your template editor for users to modify layouts and styling.
  </Card>

  <Card title="Data Field Analysis" icon="magnifying-glass">
    **Dynamic Content Planning**

    Analyze template structure to determine what data fields are required for successful PDF generation.
  </Card>
</CardGroup>

## Next Steps

After retrieving a template, you can:

* **Generate PDFs** using the [Generate PDF](/api-reference/auto-generated/pdf-generation/generate-pdf) endpoint
* **Update the template** using the template update endpoint
* **Extract data fields** to understand what data is needed for PDF generation
* **Create template variations** by copying and modifying the template configuration

<Tip>
  Keep template IDs accessible in your application for quick retrieval. Consider caching frequently used templates to improve performance.
</Tip>


## OpenAPI

````yaml get /api/templates/{id}
openapi: 3.1.0
info:
  title: Docurate PDF API
  description: Generate PDFs from JSON templates with data binding
  version: 1.0.0
servers:
  - url: https://api.curatepdf.com
    description: Production
security:
  - apiKeyAuth: []
paths:
  /api/templates/{id}:
    get:
      tags:
        - Templates
      summary: Get Template by ID
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Template ID
          example: template_123
      responses:
        '200':
          description: Template retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  template:
                    type: object
                    properties:
                      id:
                        type: string
                        example: template_123
                      name:
                        type: string
                        example: My Template
                      template:
                        type: object
                        description: Template configuration object
                        example:
                          size:
                            width: 595
                            height: 842
                          pages:
                            - elements:
                                - type: text
                                  content: Hello {{data.name}}
                      created_at:
                        type: string
                        format: date-time
                        example: '2024-01-01T00:00:00.000Z'
                      updated_at:
                        type: string
                        format: date-time
                        example: '2024-01-01T00:00:00.000Z'
                      user_id:
                        type: string
                        example: user_123
        '401':
          description: Authentication failed
        '404':
          description: Template not found
        '500':
          description: Database error
      security:
        - apiKeyAuth: []
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: API key for accessing the Docurate PDF API

````