# Get a document

> A template’s current content and its revision.

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

<CodeTabs>

```bash tab="cURL"
curl -i https://api.muzekit.com/v1/templates/tpl_Vk1t4l9xvQv/document \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY"
```

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

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

body = requests.get(
    "https://api.muzekit.com/v1/templates/tpl_Vk1t4l9xvQv/document",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
).json()
document, revision = body["document"], body["revision"]
```

</CodeTabs>

`{id}` is the template's `tpl_…` id or its key. The answer is always the current version; the [document format](/docs/templates#documents) is the same one you send to [create a template](/docs/api-reference/templates-create) or [update a document](/docs/api-reference/templates-document-update).

The `ETag` header carries the revision too. Send it back as `If-Match` when you save.

## Examples

### Export a template to a file

Keep a design in your own storage or in version control. The file is a complete document: you can create a template from it later.

<CodeTabs>

```bash tab="cURL"
curl -s https://api.muzekit.com/v1/templates/product-card/document \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  | jq '.document' > product-card.json
```

```javascript tab="Node"
import { writeFile } from "node:fs/promises";

const res = await fetch(
  "https://api.muzekit.com/v1/templates/product-card/document",
  { headers: { Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}` } },
);
const { document } = await res.json();
await writeFile("product-card.json", JSON.stringify(document, null, 2));
```

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

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

with open("product-card.json", "w") as f:
    json.dump(document, f, indent=2)
```

</CodeTabs>

### Copy a template into another environment

Read the document with one environment's key and create a template from it with the other's. Give it the same key, so your code names it the same way in both. **Copy to Live** in the dashboard does this for many templates at once.

<CodeTabs>

```bash tab="cURL"
curl -s https://api.muzekit.com/v1/templates/product-card/document \
  -H "Authorization: Bearer $MUZEKIT_TEST_SECRET_KEY" \
  | jq '{ name: "Product card", external_id: "product-card", document }' \
  | curl https://api.muzekit.com/v1/templates \
      -H "Authorization: Bearer $MUZEKIT_LIVE_SECRET_KEY" \
      -H "Content-Type: application/json" \
      -d @-
```

```javascript tab="Node"
const API = "https://api.muzekit.com/v1";
const auth = (key) => ({ Authorization: `Bearer ${key}` });

const res = await fetch(`${API}/templates/product-card/document`, {
  headers: auth(process.env.MUZEKIT_TEST_SECRET_KEY),
});
const { document } = await res.json();

await fetch(`${API}/templates`, {
  method: "POST",
  headers: {
    ...auth(process.env.MUZEKIT_LIVE_SECRET_KEY),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    name: "Product card",
    external_id: "product-card",
    document,
  }),
});
```

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

API = "https://api.muzekit.com/v1"
test = {"Authorization": f"Bearer {os.environ['MUZEKIT_TEST_SECRET_KEY']}"}
live = {"Authorization": f"Bearer {os.environ['MUZEKIT_LIVE_SECRET_KEY']}"}

document = requests.get(
    f"{API}/templates/product-card/document", headers=test
).json()["document"]

requests.post(
    f"{API}/templates",
    headers=live,
    json={"name": "Product card", "external_id": "product-card", "document": document},
)
```

</CodeTabs>

The key must be free in the target environment, or the create returns `409 external_id_taken`. To replace a template that's already there, [update its document](/docs/api-reference/templates-document-update#copy-one-templates-design-into-another) instead.

### Find a layer in the document

Layers are the `elements` of each page. A field has `parameterizable: true` and its `parameterId`, the key you see in [parameters](/docs/api-reference/templates-parameters).

<CodeTabs>

```bash tab="cURL"
curl -s https://api.muzekit.com/v1/templates/product-card/document \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  | jq '.document.pages[].elements[] | select(.parameterId == "headline")'
```

```javascript tab="Node"
const res = await fetch(
  "https://api.muzekit.com/v1/templates/product-card/document",
  { headers: { Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}` } },
);
const { document } = await res.json();
const headline = document.pages
  .flatMap((page) => page.elements ?? [])
  .find((el) => el.parameterId === "headline");
```

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

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

headline = next(
    el
    for page in document["pages"]
    for el in page.get("elements", [])
    if el.get("parameterId") == "headline"
)
```

</CodeTabs>

## Response

```json
{
  "object": "document",
  "template": "tpl_Vk1t4l9xvQv",
  "version": "ver_Lp0sQ7dXk2m",
  "revision": 3,
  "document": {
    "schema": { "core": 1 },
    "pages": [
      {
        "id": "page-1",
        "name": "Page 1",
        "canvas": { "width": 1080, "height": 1080 },
        "elements": [
          {
            "id": "el-1",
            "type": "text",
            "content": "Summer sale",
            "parameterizable": true,
            "parameterId": "headline",
            "position": { "x": 80, "y": 120 },
            "dimensions": { "width": 920, "height": 140 },
            "style": { "fontSize": 96, "color": "#111111" }
          }
        ]
      }
    ],
    "meta": {},
    "ext": {}
  }
}
```

Layers carry more fields than shown here. Keep the ones you don't change as they are when you save.
