Sendgrid-nodejs: Confused between `substitutions` and `dynamicTemplateData`

Created on 16 Jan 2019  ·  16Comments  ·  Source: sendgrid/sendgrid-nodejs

Issue Summary

I'm confused between substitutions and dynamicTemplateData.

I only get the substitutions or dynamicTemplateData to work if I send both! If I take out either of them it doesn't replace the handlebars values in the template.

sgMail
        .send({
          from: { email: '[email protected]', name: 'Test' },
          personalizations: [
            {
              to: { email: member.email },
              substitutions: {
                memberName: member.name
              },
              dynamicTemplateData: {
                memberName: member.name
              }
            }
          ],
          templateId: '111'
        })
        .then(() => console.log('Mail sent successfully'))
        .catch(error => console.error(error.toString()))

Technical details:

  • sendgrid-nodejs Version: 6.3.1
  • Node.js Version: 10.15.0
unknown or a waiting for feedback question

Most helpful comment

Can someone please update the docs at

https://sendgrid.com/docs/for-developers/sending-email/personalizations

to mention dynamic_template_data where substitutions are mentioned? I think this could save a lot of people a lot of time.

Thanks!

All 16 comments

Hello @herkulano,

You would use dynamicTemplateData along with our transactional templates. substitutions are used with our legacy templates.

I hope that helps!

With Best Regards,

Elmer

Thanks for the response, understood it now.

I'm using your transactional templates, but if i use only the dynamicTemplateData it doesn't work.

Can someone please update the docs at

https://sendgrid.com/docs/for-developers/sending-email/personalizations

to mention dynamic_template_data where substitutions are mentioned? I think this could save a lot of people a lot of time.

Thanks!

Hello @herkulano,

Is your issue now resolved?

@danielzen,

Thanks for pointing out that documentation link! (cc @ksigler7 @Whatthefoxsays)

With Best Regards,

Elmer

Not really, as I mentioned for some reason it only works if I add both values if I take either one it doesn't work.

I've since moved away from sendgrid so I won't be able to follow up on this.

Thank you for your support.

Thanks for the response @herkulano,

If you choose to come back, I'm happy to further assist.

Still facing this issue in version 6.3.1. Workaround is to add a empty object as the substitutions value.

Hello @iudelsmann,

Have you tried using this example?

With Best Regards,

Elmer

Experiencing same behavior in 6.3.1 as @iudelsmann.

I'm sorry guys but this really is frustrating. I got it to work now using dynamicTemplateData but why not update the documentation. Otherwise, people like me just waste our time thinking we have done something wrong. Not to mention some endpoints just don't work with the new API (like adding contacts). I chose SendGrid because it's supposed to be developer friendly but it seems like there are so many issues with things you have changed over the years. I also got completely conflicting opinions on ASM vs subscription tracking from multiple support people. I am almost wishing I had gone with MailChimp or something else at this point given the inconsistencies and just plain wrong documentation.

Here is the wrong documentation that needs an update to save some other person some time in the future. Both these use 'substitutions' which doesn't work:
https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/customization.md
https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/kitchen-sink.md

Any updates for documentation? It's still to complicated to find out usage of dynamicTemplateData without docs.

I've updated the docs listed by replacing the legacy template parameters with dynamic ones. For examples on using legacy templates, see here.

Same error: Substitution is not working.

{ from: '[email protected]', subject: 'test subject', text: 'Text', html: html, personalizations: [ { 'to': [ { 'email': '[email protected]', 'name': 'John' } ], 'subject': 'Example 01', 'substitutions': { '-name-': 'John' } }, { 'to': [ { 'email': '[email protected]', 'name': 'Jane' } ], 'subject': 'Example 02', 'substitutions': { '-name-': 'Jane' } } ] }

Email is being send but the html substitution variable is not replaces by the value provided. This is my one html not a template which usually stored on SendGrid portal.

@chdharm Please open a new issue with details about what you're attempting to do. Closed issues are not closely followed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

agostonbonomi picture agostonbonomi  ·  3Comments

thinkingserious picture thinkingserious  ·  4Comments

kiranshashiny picture kiranshashiny  ·  4Comments

danielflippance picture danielflippance  ·  4Comments

Chrischuck picture Chrischuck  ·  3Comments