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

# Templates

> Create, list, update, and delete templates with the MailGlyph Node.js SDK.

Use a **secret key** client for template methods.

```ts theme={null}
import MailGlyph from 'mailglyph';

const client = new MailGlyph(process.env.MAILGLYPH_SECRET_KEY as string);
```

## List templates (`templates.list`)

```ts theme={null}
const page = await client.templates.list({
  limit: 20,
  type: 'TRANSACTIONAL',
  search: 'welcome'
});

console.log(page.total, page.totalPages, page.data.length);
```

## Create a template (`templates.create`)

```ts theme={null}
const template = await client.templates.create({
  name: 'Welcome',
  subject: 'Welcome to MailGlyph',
  body: '<h1>Welcome</h1><p>Thanks for joining us.</p>',
  type: 'TRANSACTIONAL'
});

console.log(template.id, template.name);
```

## Get one template (`templates.get`)

```ts theme={null}
const fetched = await client.templates.get(template.id);

console.log(fetched.subject, fetched.type);
```

## Update a template (`templates.update`)

```ts theme={null}
const updated = await client.templates.update(template.id, {
  subject: 'Welcome to MailGlyph!',
  body: '<h1>Welcome!</h1><p>We are glad to have you.</p>'
});

console.log(updated.subject);
```

## Delete a template (`templates.delete`)

```ts theme={null}
await client.templates.delete(template.id);
```

See full details in the [Templates API reference](https://docs.mailglyph.com/api-reference/templates/listTemplates.md).


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