sendgrid-nodejs: Dynamic Template Data is not showing!
template html code:
<div style="text-align: center;"><span style="font-size:28px;"><strong><p>Code: {{voucherCode}}</p></strong></span></div>
Nodejs Code:
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
//sgMail.setSubstitutionWrappers('{{', '}}'); // Configure the substitution tag wrappers globally
const msg = {
to: 'exampel@exmaple.com',
from: 'sender@example.org',
templateId: 'd-787c96877a394be5b95c91750622fed1',
dynamicTemplateData : {
voucherCode: "Some One"
},
};
sgMail.send(msg)
When I received the email, the voucherCode is empty!
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 6
- Comments: 15 (5 by maintainers)
It looks like the
dynamic_template_datamust be inside apersonalizationsarray in order for it to work.This works for me:
Above poster is correct. There is a bug either in the library code or typescript definitions.
This would suggest that you can pass
dynamicTemplateDataas a value inPersonalizationData, but it has to actually be snake case,dynamic_template_data.The solution that worked for me is placing the dynamic_template_data inside the personalization object in the exact way seen below:
Yup, I’m seeing the same issue. The To and Bcc get the email, but the dynamic template is not populated in the Bcc when using the global Bcc account setting. Unfortunately, that’s not something that we can resolve in this helper lib so best to create a support ticket to request that this bug be fixed in the backend.
I spent 2 hours trying to debug this issue only to realize that the issue occurs on a BCC’ed email.