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

# Get Template Variables

> Retrieves the variable schema for a specific template. This endpoint extracts all variables (data placeholders) that can be used when rendering the template.

GET [https://api.pdfnoodle.com/v1/integration/templates/:templateId/variables](https://api.pdfnoodle.com/v1/integration/templates/:templateId/variables)

## Request

```bash cURL theme={null}
curl --location 'https://api.pdfnoodle.com/v1/integration/templates/invoice-template-001/variables' \
--header 'Authorization: Bearer pdfnoodle_api_123456789'
```

```javascript JavaScript theme={null}
const response = await fetch(
  "https://api.pdfnoodle.com/v1/integration/templates/invoice-template-001/variables",
  {
    method: "GET",
    headers: {
      Authorization: "Bearer pdfnoodle_api_123456789",
    },
  }
);

const result = await response.json();
```

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

response = requests.get(
    'https://api.pdfnoodle.com/v1/integration/templates/invoice-template-001/variables',
    headers={
        'Authorization': 'Bearer pdfnoodle_api_123456789'
    }
)

result = response.json()
```

## Response

```json Success (200 OK) theme={null}
{
  "invoice_number": "your invoice_number here",
  "company_info": {
    "name": "your company_info.name here",
    "address_line_1": "your company_info.address_line_1 here",
    "city": "your company_info.city here",
    "email": "your company_info.email here"
  },
  "billing_to": {
    "name": "your billing_to.name here",
    "address_line_1": "your billing_to.address_line_1 here",
    "city": "your billing_to.city here"
  },
  "total_value": "your total_value here",
  "items": [
    {
      "description": "your row.description here",
      "quantity": "your row.quantity here",
      "price": "your row.price here"
    }
  ]
}
```

This endpoint responds with `200 OK` and returns all variables from the template. The response structure matches the variables used in the template, including nested objects and arrays.

> [!NOTE]
>
> The example above shows a variable schema from an invoice template. The actual
> response will vary depending on the template's structure and variables.

## Path Parameters

**templateId** `string` *required*

Template identifier (the `name` field from the template, same as `id` from
list templates response, or the `templateId` returned from create template
endpoint)

## Response Fields

The response contains all variables from the template. The structure will vary depending on the template, but will include all variables, nested objects, and arrays that are used in the template.

## Usage

This endpoint is essential for:

* Understanding what data fields are required to render a template
* Building dynamic forms for template data input
* Validating data before rendering
* Generating API documentation for template-specific data structures
* Discovering available variables programmatically

> [!NOTE]
>
> The response structure matches the variables used in the template. Use this
> endpoint to discover what data fields are required when rendering a template
> with the generate-pdf-from-template endpoint.

## Usage Example

Here's a complete example of fetching template variables and using them to build a data payload:

> [tab] Node.js
>
> ```javascript theme={null}
> // Get variables for a specific template
> const templateId = "invoice-template-001";
> const variablesResponse = await fetch(
>   `https://api.pdfnoodle.com/v1/integration/templates/${templateId}/variables`,
>   {
>     headers: { Authorization: "Bearer pdfnoodle_api_123456789" },
>   }
> );
>
> const { variables } = await variablesResponse.json();
>
> console.log("Required variables:", variables);
>
> // Use variables to build data payload for rendering
> const templateData = {
>   companyName: "Acme Corp",
>   invoiceNumber: "INV-001",
>   lineItems: [
>     {
>       description: "Product A",
>       quantity: 2,
>       price: 50.0,
>     },
>     {
>       description: "Product B",
>       quantity: 1,
>       price: 30.0,
>     },
>   ],
>   totalAmount: 130.0,
> };
>
> // Now you can use templateData with the generate-pdf-from-template endpoint
> ```

> [tab] Python
>
> ```python theme={null}
> import requests
>
> # Get variables for a specific template
> template_id = 'invoice-template-001'
> variables_response = requests.get(
>     f'https://api.pdfnoodle.com/v1/integration/templates/{template_id}/variables',
>     headers={'Authorization': 'Bearer pdfnoodle_api_123456789'}
> )
>
> result = variables_response.json()
> variables = result['variables']
>
> print('Required variables:', variables)
>
> # Use variables to build data payload for rendering
> template_data = {
>     'companyName': 'Acme Corp',
>     'invoiceNumber': 'INV-001',
>     'lineItems': [
>         {
>             'description': 'Product A',
>             'quantity': 2,
>             'price': 50.0
>         },
>         {
>             'description': 'Product B',
>             'quantity': 1,
>             'price': 30.0
>         }
>     ],
>     'totalAmount': 130.0
> }
>
> # Now you can use template_data with the generate-pdf-from-template endpoint
> ```

## Error Responses

### 401 Unauthorized

```json theme={null}
{
  "message": "Unauthorized"
}
```

**Occurs when:** The API key is missing or invalid.

### 404 Not Found

```json theme={null}
{
  "message": "Couldnt find this template."
}
```

**Occurs when:** The requested template doesn't exist or isn't fully created yet.

### 500 Internal Server Error

```json theme={null}
{
  "message": "Error message describing what went wrong"
}
```

**Occurs when:** Variable extraction fails or an internal server error prevents the operation from completing.

> [!WARNING]
>
> The template must be fully created and available before you can fetch its
> variables. If you try to fetch variables for a template that's still being
> created (status `ONGOING`), you'll receive a `404 Not Found` error.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.