# Template parameters

> The values a render can change in a template, with their type, page and current value.

<Endpoint method="GET" path="/v1/templates/{id}/parameters" />

<CodeTabs>

```bash tab="cURL"
curl https://api.muzekit.com/v1/templates/product-card/parameters \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY"
```

```javascript tab="Node"
const res = await fetch(
  "https://api.muzekit.com/v1/templates/product-card/parameters",
  { headers: { Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}` } },
);
const { data: parameters } = await res.json();
```

```python tab="Python"
import os
import requests

parameters = requests.get(
    "https://api.muzekit.com/v1/templates/product-card/parameters",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
).json()["data"]
```

</CodeTabs>

`{id}` is the template's `tpl_…` id or its key. Use the `key`s as `modifications` when you [create a render](/docs/api-reference/renders-create). A single-page template's keys are bare (`headline`). On a multi-page template every key carries its page, page 1 included (`page1@headline`, `page2@headline`); send them that way.

Each parameter is a layer your team marked as a field. `type` is what the value changes: `text`, `image` and `video` take new content, and color parameters (`fill`, `color`, `stroke`, `backgroundColor`) take a color. `default` is the layer's value in the template now, `layer` its name in the editor, and `hidden` is `true` when the layer is hidden in the design. A text with `{{name}}` in it adds a key of its own, `headline:name`, for that word alone.

## Examples

### Check your data against a template before rendering

Your app sends values under its own field names. Read the keys once and compare, so a renamed field shows up as a clear error in your app instead of a render that ignored a value.

<CodeTabs>

```bash tab="cURL"
# Print each key with its type
curl -s https://api.muzekit.com/v1/templates/product-card/parameters \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  | jq -r '.data[] | "\(.key)\t\(.type)"'
```

```javascript tab="Node"
const res = await fetch(
  "https://api.muzekit.com/v1/templates/product-card/parameters",
  { headers: { Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}` } },
);
const keys = new Set((await res.json()).data.map((p) => p.key));

const values = { headline: "Blue mug", photo: "https://example.com/mug.jpg" };
const unknown = Object.keys(values).filter((k) => !keys.has(k));
if (unknown.length) throw new Error(`Not in the template: ${unknown}`);
```

```python tab="Python"
import os
import requests

data = requests.get(
    "https://api.muzekit.com/v1/templates/product-card/parameters",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
).json()["data"]
keys = {p["key"] for p in data}

values = {"headline": "Blue mug", "photo": "https://example.com/mug.jpg"}
unknown = [k for k in values if k not in keys]
if unknown:
    raise ValueError(f"Not in the template: {unknown}")
```

</CodeTabs>

A render with an unknown key still renders and lists the key in `warnings`.

### Build a form from a template's fields

Show one input per parameter in your own app, filled with the template's current values, and send what the user typed as `modifications`.

<CodeTabs>

```bash tab="cURL"
# The template's values as a modifications object
curl -s https://api.muzekit.com/v1/templates/product-card/parameters \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  | jq '[.data[] | {(.key): .default}] | add'
```

```javascript tab="Node"
const res = await fetch(
  "https://api.muzekit.com/v1/templates/product-card/parameters",
  { headers: { Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}` } },
);
const fields = (await res.json()).data.map((p) => ({
  name: p.key,
  label: p.layer ?? p.key,
  input: p.type === "image" || p.type === "video" ? "url" : "text",
  value: p.default ?? "",
}));
```

```python tab="Python"
import os
import requests

data = requests.get(
    "https://api.muzekit.com/v1/templates/product-card/parameters",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
).json()["data"]

fields = [
    {
        "name": p["key"],
        "label": p["layer"] or p["key"],
        "input": "url" if p["type"] in ("image", "video") else "text",
        "value": p["default"] or "",
    }
    for p in data
]
```

</CodeTabs>

### Read the keys of a multi-page template

Every key on a multi-page template names its page. Here a two-page flyer has a headline on each page and a `{{name}}` word in page 1's greeting.

```json
{
  "object": "list",
  "template": "tpl_Vk1t4l9xvQv",
  "data": [
    {
      "object": "parameter",
      "key": "page1@greeting",
      "type": "text",
      "page": 1,
      "default": "Hello {{name}}",
      "layer": "Greeting",
      "hidden": false
    },
    {
      "object": "parameter",
      "key": "page1@greeting:name",
      "type": "text",
      "page": 1,
      "default": "",
      "layer": null,
      "hidden": false
    },
    {
      "object": "parameter",
      "key": "page2@headline",
      "type": "text",
      "page": 2,
      "default": "See you there",
      "layer": "Headline",
      "hidden": false
    }
  ]
}
```

Render it with the keys as they are:

```json
{
  "template": "tpl_Vk1t4l9xvQv",
  "format": "pdf",
  "modifications": {
    "page1@greeting:name": "Maya",
    "page2@headline": "Doors open at 7"
  }
}
```

## Response

```json
{
  "object": "list",
  "template": "tpl_Vk1t4l9xvQv",
  "data": [
    {
      "object": "parameter",
      "key": "headline",
      "type": "text",
      "page": 1,
      "default": "Summer sale",
      "layer": "Headline",
      "hidden": false
    },
    {
      "object": "parameter",
      "key": "hero",
      "type": "image",
      "page": 1,
      "default": "https://…/hero.jpg",
      "layer": "Photo",
      "hidden": false
    }
  ]
}
```
