# Delete a template

> Delete a template. It can be restored by support for 30 days.

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

<CodeTabs>

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

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

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

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

</CodeTabs>

`{id}` is the template's `tpl_…` id or its key. The template leaves every list at once, and a `template.deleted` webhook goes out. Files it uses stay in the library, and still count as in use while the template can be restored.

## Examples

### Delete a template by its key

Use the key to delete the same template in Test and in Live. Each environment has its own copy, so send the request with each key.

<CodeTabs>

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

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

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

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

</CodeTabs>

### Delete all of an end user's designs

When a user leaves your product, list their designs with `user` and delete each one. Keep listing until the list comes back empty.

<CodeTabs>

```bash tab="cURL"
for ID in $(curl -s "https://api.muzekit.com/v1/templates?user=usr_8fK2mQ1xZpR&limit=100" \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" | jq -r '.data[].id'); do
  curl -s -X DELETE "https://api.muzekit.com/v1/templates/$ID" \
    -H "Authorization: Bearer $MUZEKIT_SECRET_KEY"
done
```

```javascript tab="Node"
const headers = { Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}` };
const base = "https://api.muzekit.com/v1/templates";

while (true) {
  const page = await (
    await fetch(`${base}?user=usr_8fK2mQ1xZpR&limit=100`, { headers })
  ).json();
  if (!page.data.length) break;
  for (const t of page.data) {
    await fetch(`${base}/${t.id}`, { method: "DELETE", headers });
  }
}
```

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

headers = {"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"}
base = "https://api.muzekit.com/v1/templates"

while True:
    page = requests.get(
        base, params={"user": "usr_8fK2mQ1xZpR", "limit": 100}, headers=headers
    ).json()
    if not page["data"]:
        break
    for t in page["data"]:
        requests.delete(f"{base}/{t['id']}", headers=headers)
```

</CodeTabs>

An id or key that doesn't exist, or a template already deleted, answers `404 template_not_found`.

## Response

```json
{ "object": "template", "id": "tpl_Vk1t4l9xvQv", "deleted": true }
```
