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

# Get Import Template

> Retrieve template metadata including column definitions and validation rules

# Get Import Template

Retrieve the metadata for a backend import template, including its column definitions, validation rules, and required context fields. Templates define the expected structure of an import file.

<Note>
  Templates are static configuration — not organization-specific. Any authenticated caller can fetch any template.
</Note>

## Request

### Headers

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

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

### Path Parameters

<ParamField path="template_id" type="string" required>
  Template identifier

  **Examples:** `logistics_requests`, `purchases`, `wastes`, `invoices_electricity`, `transport_routes`
</ParamField>

## Response

<ResponseField name="template_id" type="string">
  Template identifier
</ResponseField>

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

<ResponseField name="columns" type="array[object]">
  Column definitions for this template

  <Expandable title="Column Object">
    <ResponseField name="key" type="string">
      Internal column key (used in mapping)
    </ResponseField>

    <ResponseField name="label" type="string">
      Human-readable label
    </ResponseField>

    <ResponseField name="type" type="string">
      Data type: `string`, `number`, `date`, `category`, `boolean`
    </ResponseField>

    <ResponseField name="required" type="boolean">
      Whether this column must be mapped
    </ResponseField>

    <ResponseField name="aliases" type="array[string]">
      Alternative names recognized during auto-mapping (e.g. `["peso", "weight_kg"]`)
    </ResponseField>

    <ResponseField name="options" type="array[string] | null">
      Fixed list of allowed values for category columns
    </ResponseField>

    <ResponseField name="options_source" type="string | null">
      Dynamic option provider key (e.g. `fuel_types`, `countries`). Use [Get Options Source](/api-reference/imports/get-options-source) to resolve values.
    </ResponseField>

    <ResponseField name="default" type="any">
      Default value applied when the cell is empty
    </ResponseField>

    <ResponseField name="validations" type="array[object]">
      Validation rules applied to this column (e.g. `{rule: "range", params: {min: 0}}`)
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="required_context_fields" type="array[string]">
  Context fields that must be provided at session creation (e.g. `["facility_id"]` for wastes)
</ResponseField>

<ResponseField name="submit_context_fields" type="array[string]">
  Context fields that can be provided at submit time
</ResponseField>

<ResponseField name="submit_columns" type="array[string]">
  Columns included in the submitted output
</ResponseField>

<ResponseField name="defaults" type="object">
  Global default values applied across all columns
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X GET "https://api.dcycle.io/v2/imports/templates/logistics_requests" \
    -H "x-api-key: ${DCYCLE_API_KEY}"
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import requests
  import os

  headers = {"x-api-key": os.getenv("DCYCLE_API_KEY")}

  response = requests.get(
      "https://api.dcycle.io/v2/imports/templates/logistics_requests",
      headers=headers,
  )

  template = response.json()
  print(f"Template: {template['template_id']}")
  print(f"Columns ({len(template['columns'])}):")
  for col in template["columns"]:
      req = " (required)" if col["required"] else ""
      print(f"  {col['key']} [{col['type']}]{req} — {col['label']}")
  ```

  ```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const axios = require('axios');

  const headers = { 'x-api-key': process.env.DCYCLE_API_KEY };

  axios.get('https://api.dcycle.io/v2/imports/templates/logistics_requests', { headers })
    .then(response => {
      const { template_id, columns } = response.data;
      console.log(`Template: ${template_id}, ${columns.length} columns`);
      columns.forEach(c => {
        console.log(`  ${c.key} [${c.type}]${c.required ? ' (required)' : ''}`);
      });
    });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "template_id": "logistics_requests",
  "description": "Logistics transport requests",
  "columns": [
    {
      "key": "origin",
      "label": "Origin",
      "type": "string",
      "required": true,
      "aliases": ["from", "origen", "departure"],
      "options": null,
      "options_source": null,
      "default": null,
      "validations": []
    },
    {
      "key": "destination",
      "label": "Destination",
      "type": "string",
      "required": true,
      "aliases": ["to", "destino", "arrival"],
      "options": null,
      "options_source": null,
      "default": null,
      "validations": []
    },
    {
      "key": "weight",
      "label": "Weight (kg)",
      "type": "number",
      "required": true,
      "aliases": ["peso", "weight_kg"],
      "options": null,
      "options_source": null,
      "default": null,
      "validations": [{"rule": "range", "params": {"min": 0}}]
    },
    {
      "key": "vehicle_type",
      "label": "Vehicle Type",
      "type": "category",
      "required": false,
      "aliases": ["tipo_vehiculo"],
      "options": null,
      "options_source": "toc_types",
      "default": null,
      "validations": []
    }
  ],
  "required_context_fields": [],
  "submit_context_fields": [],
  "submit_columns": ["origin", "destination", "weight", "vehicle_type", "date"],
  "defaults": {}
}
```

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Invalid API key for organization", "code": "INVALID_API_KEY"}
```

### 403 Forbidden

**Cause:** The authenticated user is not a member of the organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Logged User is not Member of Organization", "code": "LOGGED_USER_NOT_MEMBER"}
```

### 404 Not Found

**Cause:** Template does not exist

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Template 'invalid_template' not found."
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Create Session" icon="upload" href="/api-reference/imports/create-session">
    Use the template\_id when creating an import session
  </Card>

  <Card title="Get Options Source" icon="list" href="/api-reference/imports/get-options-source">
    Resolve dynamic option values for category columns
  </Card>
</CardGroup>
