N
Novu•2y ago
ujwal1373

API endpoint to create an email template and associate it with the notification template

I was looking at the API documentation and couldn't find an API to create an email template. There is an API to create notification template and we can specify steps in the payload. The steps array has a placeholder for template object but not sure what is the format of it. I see that we can create layout and associate a step to the layout in the UI but not sure how we can do it using API. I have an email template in HTML that I wanted to use to trigger an email notification. Can someone please let me know the list of API calls required to create the template using the HTML content.
3 Replies
Gali Baum
Gali Baum•2y ago
{
name: 'test email template',
description: 'This is a test description',
tags: ['test-tag'],
notificationGroupId: session.notificationGroups[0]._id,
steps: [
{
template: {
name: 'Message Name',
subject: 'Test email subject',
preheader: 'Test email preheader',
content: [{ type: 'text', content: 'This is a sample text block' }],
type: 'email',
layoutId: <LAYOUT_ID>,
},
filters: [
{
isNegated: false,
type: 'GROUP',
value: 'AND',
children: [
{
on: FilterPartTypeEnum.SUBSCRIBER,
field: 'firstName',
value: 'test value',
operator: 'EQUAL',
},
],
},
],
},
],
}
{
name: 'test email template',
description: 'This is a test description',
tags: ['test-tag'],
notificationGroupId: session.notificationGroups[0]._id,
steps: [
{
template: {
name: 'Message Name',
subject: 'Test email subject',
preheader: 'Test email preheader',
content: [{ type: 'text', content: 'This is a sample text block' }],
type: 'email',
layoutId: <LAYOUT_ID>,
},
filters: [
{
isNegated: false,
type: 'GROUP',
value: 'AND',
children: [
{
on: FilterPartTypeEnum.SUBSCRIBER,
field: 'firstName',
value: 'test value',
operator: 'EQUAL',
},
],
},
],
},
],
}
Something like this structure For the layout , you should use the layout creation api call https://docs.novu.co/api/layout-creation/ and then you could use the layout id you get in the response either in the create notification->steps->template inside layoutId Or use the update notification template to update the layoutId for a step You could look at some examples in our tests like: https://github.com/novuhq/novu/blob/8eeb340982b1e4abb363f7b4643bb479c7088739/apps/api/src/app/notification-template/e2e/create-notification-templates.e2e.ts https://github.com/novuhq/novu/blob/7e689da12e248b9fa4cb73611e0fbbd597692bce/apps/api/src/app/notification-template/e2e/update-notification-template.e2e.ts @Ujwal Let me know how it goes 🙂
Pawan Jain
Pawan Jain•2y ago
Hi @Ujwal do you need more help in this?
ujwal1373
ujwal1373OP•2y ago
@galiainouz Thanks for your help. That worked! @Pawan Jain Hi Pawan. I'm good, don't need anymore help on this.
Want results from more Discord servers?
Add your server