Create, list, update, and delete templates with the MailGlyph Node.js SDK.
import MailGlyph from 'mailglyph'; const client = new MailGlyph(process.env.MAILGLYPH_SECRET_KEY as string);
templates.list
const page = await client.templates.list({ limit: 20, type: 'TRANSACTIONAL', search: 'welcome' }); console.log(page.total, page.totalPages, page.data.length);
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);
templates.get
const fetched = await client.templates.get(template.id); console.log(fetched.subject, fetched.type);
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);
templates.delete
await client.templates.delete(template.id);