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

# Get Template By Id

> Retrieves a template by its ID

The `/templates/{template_id}` endpoint retrieves a template by its unique identifier.

## Request

<ParamField header="x-api-key" type="string" required>
  Your API key for authentication.
</ParamField>

<ParamField path="template_id" type="string" required>
  The unique identifier of the template to retrieve.
</ParamField>

<ParamField query="version" type="integer">
  Optional specific version of the template to retrieve. If not specified, the latest version will be returned.
</ParamField>

## Response

<ResponseField name="id" type="string">
  The unique identifier for the template.
</ResponseField>

<ResponseField name="name" type="string">
  The name of the template.
</ResponseField>

<ResponseField name="description" type="string">
  The description of the template.
</ResponseField>

<ResponseField name="category" type="string">
  The category of the template.
</ResponseField>

<ResponseField name="tags" type="array">
  The tags associated with the template.
</ResponseField>

<ResponseField name="usage_count" type="integer">
  The number of times this template has been used.
</ResponseField>

<ResponseField name="fields" type="array">
  The field definitions for the template. Each field follows the same structure as described in the suggest-fields response.
</ResponseField>

<ResponseField name="is_public" type="boolean">
  Whether the template is public or private.
</ResponseField>

<ResponseField name="user_id" type="string">
  The ID of the user who owns this template (for private templates).
</ResponseField>

<ResponseField name="created_at" type="string">
  When the template was created (ISO 8601 format).
</ResponseField>

<ResponseField name="updated_at" type="string">
  When the template was last updated (ISO 8601 format).
</ResponseField>

## Examples

### Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET https://api.vizapi.ai/v1/templates/template_12345 \
    -H "x-api-key: YOUR_API_KEY"
  ```

  ```bash cURL (with version) theme={null}
  curl -X GET https://api.vizapi.ai/v1/templates/template_12345?version=2 \
    -H "x-api-key: YOUR_API_KEY"
  ```

  ```javascript Node.js theme={null}
  const fetch = require('node-fetch');

  async function getTemplate() {
    const response = await fetch('https://api.vizapi.ai/v1/templates/template_12345', {
      method: 'GET',
      headers: {
        'x-api-key': 'YOUR_API_KEY'
      }
    });
    
    const data = await response.json();
    console.log(data);
  }

  getTemplate();
  ```

  ```javascript Node.js (with version) theme={null}
  const fetch = require('node-fetch');

  async function getTemplateVersion() {
    const response = await fetch('https://api.vizapi.ai/v1/templates/template_12345?version=2', {
      method: 'GET',
      headers: {
        'x-api-key': 'YOUR_API_KEY'
      }
    });
    
    const data = await response.json();
    console.log(data);
  }

  getTemplateVersion();
  ```

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

  url = "https://api.vizapi.ai/v1/templates/template_12345"
  headers = {
      "x-api-key": "YOUR_API_KEY"
  }

  response = requests.get(url, headers=headers)
  data = response.json()
  print(data)
  ```

  ```python Python (with version) theme={null}
  import requests

  url = "https://api.vizapi.ai/v1/templates/template_12345"
  params = {
      "version": 2
  }
  headers = {
      "x-api-key": "YOUR_API_KEY"
  }

  response = requests.get(url, params=params, headers=headers)
  data = response.json()
  print(data)
  ```
</CodeGroup>

### Example Response

```json theme={null}
{
  "id": "template_12345",
  "name": "Plant Disease Detector",
  "description": "Template for analyzing plant health and detecting diseases",
  "category": "agriculture",
  "tags": ["farming", "disease-detection"],
  "usage_count": 25,
  "fields": [
    {
      "name": "plant_species",
      "type": "string",
      "description": "The species of plant being analyzed",
      "required": true,
      "return_as_list": false,
      "subfields": [],
      "enum_values": []
    },
    {
      "name": "disease_detected",
      "type": "boolean",
      "description": "Whether disease is present in the plant",
      "required": true,
      "return_as_list": false,
      "subfields": [],
      "enum_values": []
    },
    {
      "name": "severity_level",
      "type": "string",
      "description": "The severity level of detected disease",
      "required": false,
      "return_as_list": false,
      "subfields": [],
      "enum_values": ["mild", "moderate", "severe"]
    }
  ],
  "is_public": false,
  "user_id": "user_67890",
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-20T14:45:00Z"
}
```

## Error Codes

| Status Code | Description                                                         |
| ----------- | ------------------------------------------------------------------- |
| 401         | Unauthorized - Invalid or missing API key                           |
| 404         | Not Found - The requested template was not found                    |
| 500         | Internal Server Error - An unexpected error occurred on our servers |
