-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Substitutions not working #676
Comments
Hello, @thinkingserious , I was able to reproduce the same issue as @panayi mentioned.
Code
Note: I've even tried using Technical details:
Any Help/Fix Appreciated as I've invested much time in this issue |
Hello @tjstlekr, In your HTML code, please change Thanks! With Best Regards, Elmer |
Hello @thinkingserious, |
Yes @tjstlekr, I mean the template code as described in this example. I can not answer your second question without concrete examples. (e.g. request body and template code). With Best Regards, Elmer |
Sadly! I do not have access to the template code. I'll stick with another version. |
Have you tried: substitutions: {
'first_name': 'Tejas',
'employee_id': 'emp123',
}, |
Yes, @thinkingserious tried that. I have also tried the following ways
|
I think your solution is to get whoever can change the HTML template code to wrap the variables with a substitution character(s). With Best Regards, Elmer |
@thinkingserious is correct. The template variables MUST be wrapped in double brackets {{name}}. Otherwise SendGrid wont know where to drop the substitutions you've sent. |
Hello @tetreault, By default we use double brackets. Thanks! With Best Regards, Elmer |
I've encountered the same issue as @panayi . I followed the transactional-templates sample. I've set substitution wrappers and in the template, wrapped substitutions in double brackets. However, the email I received had removed all substitutions without replacing with those I provided. I tried with both Code editor and Design editor for the template. Technical details:
Thanks! |
Hi @nrator, If the substitutions were replaced with blank strings, I'd double check that the variables you are iterating on are not empty. If you do verify they are not empty, could you please share the code snippit along with the relevant HTML so I can try and reproduce? Thanks! With Best Regards, Elmer |
I am not using variables but string so they are not empty. Below are the code snippet, HTML and the result I got: Code
HTML template
Email I got
Technical details Best regards, |
Hi I am having the same issue with transactional templates. The variables won't pickup. Using test data to preview the template in SG dashboard, everything looks correct.
And here is the html template :
Cheers |
I just switched over to the legacy template with same html code and it works. Can it be due to new changes in V3 API? |
Hi, after reading @himanshupnt 's comment, I tested with a legacy template and it worked. Thanks @himanshupnt . Later I found Sendgrid documentation Mail Send with Dynamic Transactional Templates, I've kind of got the new template (not legacy one) working. I used the same HTML template and my code was updated to:
Notice that I replaced "substitutions" with "dynamic_template_data", and placed "to" inside "personalizations" as required by the docs. And I also treated subject as one of the "dynamic_template_data" and it works. (put {{subject}} in the template subject field) Thanks. |
@nrator That did it for me as well. Thanks for posting it! |
I'm having the same problem and I opened an issue as well (After trying out solutions mentioned at the beginning). However I was able to add |
Hi @pankaja92 , I couldn't get <%subject%> working as well. Now my way of dealing subject is treating it as one of the "dynamic_template_data", which means I wrap it in {{ }} instead of <% %> and handle it inside "dynamic_template_data". I've found this sendgrid docs which may help. The subject param doesn't seem working though. |
@nrator Thanks . It worked. So, there' no need of <%body%> as well right (as it also won't work as the example given) . Btw, not the issue specific - but, do you have any experience or example to send a list of details via this library ? I'm looking for something that might help me to build my app :) |
@pankaja92 I am not sure what do you mean by sending a list of details. You may read this sendgrid blog post about new features of the dynamic templates, basically you can now iterate over lists of items or use basic conditionals to generate dynamic contents. For actual codes, you may refer to this repo. Hope it helps! |
Hi all, spent a few hours on this issue as well. Instead of using const sgMail = require('@sendgrid/mail')
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
sgMail.setSubstitutionWrappers('{{', '}}')
const msg = {
to: '[email protected]',
from: '[email protected]',
templateId: 'd-27e7d954368c46519eddc806e5cf8156',
dynamicTemplateData: {
name: 'Some One',
city: 'Denver',
},
}
sgMail.send(msg) Reference: #691 According to that PR, when the They've created an issue here to improve the add dynamic templates usage to the docs, but until then I hope this helps. 🎉 |
Please follow this issue: #703 |
change 'substitutions' to 'dynamic_template_data' |
@jseyfert shouldn't it be |
@aroach you are correct. I have updated my comment. |
At first it didn't work on my side either. using @sendgrid/[email protected] const result = await this.sgMail.send({
personalizations: [{
to: this._to
}],
dynamicTemplateData: {
test: 'test' <== working (code in template: {{ test }})
},
templateId: this._templateId,
}); I should note that the code below is not working: const result = await this.sgMail.send({
personalizations: [{
to: this._to,
dynamicTemplateData: {
test: 'test' <== NOT working (code in template: {{ test }})
}
}],
templateId: this._templateId,
}); |
Yep, you need to use v6.3.1 for dynamic_template_data support.
…On Tue, Dec 11, 2018 at 4:15 AM Roy Milder ***@***.***> wrote:
At first it didn't work on my side either.
I've noticed that my version was a bit out of date (I was using
@***@***.***)
I've updated the package, change my code and now it is working:
using @***@***.***
const result = await this.sgMail.send({
personalizations: [{
to: this._to
}],
dynamicTemplateData: {
test: 'test' <== working (code in template: {{ test }})
},
templateId: this._templateId,
});
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#676 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACL-sjFRFP8txUETNWFVLs0chW5yyL1Nks5u35OzgaJpZM4TOB5l>
.
|
Hi, do not forget |
Works for me. I have the latest version of the SendGrid library, and am using it through Firebase (Functions). The main issue now is the lack of TypeScript support - and the documentation. |
@roymilder , thank you so much. Your answer made my day - the substitutions for dynamic templates are very unclear. |
Hello @OleksiiM, Does this example help? Thanks for helping out! With regards to lack of TypeScript support and documentation, are you referring to the Firebase side? Thanks for helping out! With Best Regards, Elmer |
@thinkingserious, yes it does. Thank you. |
Where did you look first? I'm trying to figure out how to make sure folks who need to use dynamic templates go to the link I sent you first. |
@thinkingserious It says: So I jumped to "Including the template ID in the templates parameter of the Web API v3 Mail Send endpoint". Why it was unclear: Thank you for asking and making the docs better. I hope that other folks will avoid this type of troubles. |
@thinkingserious if I may add: The instructions on sending e-mail (https://sendgrid.api-docs.io/v3.0/mail-send) do not mention So that is unclear as well. Hope it helps! |
Thanks @OleksiiM & @roymilder! We appreciate your contributions back to the Twilio SendGrid community :) |
Hustling since 2 days I saw this and got this to work. |
Hello @Travotics, What documentation did you start with before you found the above? I'm trying to improve this experience. Thanks! With Best Regards, Elmer |
@thinkingserious https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/kitchen-sink.md Does not have In addition to updating the docs, it would also be a good idea to update the type interface |
Thank you so much for this! I've spent considerable time debugging for this. :/ |
Issue Summary
Followed the example for using substitutions in transactional emails, without making any changes. The substitution tags are removed, but the text is not inserted. Here is a screenshot of the email I receive:
Steps to Reproduce
test.js
to insert your API key, your email address, andtemplateId
you created above.node test.js
.Technical details:
The text was updated successfully, but these errors were encountered: