Skip to main content
Use a secret key client for template methods.
import MailGlyph from 'mailglyph';

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

List templates (templates.list)

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)

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)

const fetched = await client.templates.get(template.id);

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

Update a template (templates.update)

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)

await client.templates.delete(template.id);
See full details in the Templates API reference.