Templates
A template is a reusable name + subject + content triple you can reference from a NotificationRequest by templateId instead of inlining subject/message on every send. Template operations live under client.templates().
Create a template
- Java
- Node.js
import com.notificationhub.sdk.model.TemplateRequest;
var request = TemplateRequest.builder()
.name("welcome-email")
.subject("Welcome to {{appName}}!")
.content("<h1>Hi {{firstName}}</h1><p>Thanks for joining {{appName}}.</p>")
.build();
var template = client.templates().create(request);
import { TemplateRequest } from '@sumitshresht/notificationhub-sdk';
const request = TemplateRequest.builder()
.name('welcome-email')
.subject('Welcome to {{appName}}!')
.content('<h1>Hi {{firstName}}</h1><p>Thanks for joining {{appName}}.</p>')
.build();
const template = await client.templates().create(request);
name, subject, and content are all required — build() throws if any is missing or blank.
Preview a template
Render a saved template with a specific set of variables, without sending anything.
- Java
- Node.js
var rendered = client.templates().preview(templateId, Map.of(
"firstName", "Ada",
"appName", "Acme"
));
const rendered = await client.templates().preview(templateId, {
firstName: 'Ada',
appName: 'Acme',
});
Preview raw HTML without saving
Useful for a live template editor — render arbitrary HTML through the same engine before it's saved as a template.
- Java
- Node.js
var rendered = client.templates().previewRaw(
"<p>Hi {{firstName}}</p>",
Map.of("firstName", "Ada")
);
const rendered = await client.templates().previewRaw(
'<p>Hi {{firstName}}</p>',
{ firstName: 'Ada' }
);
Update, list, and delete
- Java
- Node.js
client.templates().update(templateId, request);
client.templates().list(0, 20); // page, size
client.templates().delete(templateId);
await client.templates().update(templateId, request);
await client.templates().list(0, 20); // page, size
await client.templates().delete(templateId);
Sending with a template
Reference a template by ID from a NotificationRequest instead of setting subject/message directly:
- Java
- Node.js
var request = NotificationRequest.builder()
.addChannel(ChannelType.EMAIL)
.toEmail("user@example.com")
.templateId(templateId)
.addVariable("firstName", "Ada")
.addVariable("appName", "Acme")
.build();
client.notifications().send(request);
const request = NotificationRequest.builder()
.addChannel(ChannelType.EMAIL)
.toEmail('user@example.com')
.templateId(templateId)
.addVariable('firstName', 'Ada')
.addVariable('appName', 'Acme')
.build();
await client.notifications().send(request);