Skip to content
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

Substitution is not working #441

Closed
sydneyhenrard opened this issue Sep 7, 2017 · 17 comments
Closed

Substitution is not working #441

sydneyhenrard opened this issue Sep 7, 2017 · 17 comments
Labels
status: help wanted requesting help from the community type: question question directed at the library

Comments

@sydneyhenrard
Copy link

Issue Summary

I migrated from sendgrid 2.0.0 to @sendgrid/mail 6.1.2, the substitutions are not working anymore

Steps to Reproduce

SendgridService.prototype.sendTestEmail = function () {
  var text = 'Hi %DISPLAY_NAME%\n\n'
  const msg = {
    to: 'xxx@gmail.com',
    subject: 'Test Email',
    from: {email: 'no-reply@example.com', name: 'Test'},
    text: text,
    substitutions: {
      "%DISPLAY_NAME%": 'Test'
    }
  }
  return sendgrid.send(msg)
}

Technical details:

  • sendgrid-nodejs Version: master (latest commit: [commit number])
  • Node.js Version: 8.4.0
@thinkingserious
Copy link
Contributor

Hello @sydneyhenrard,

Here is a complete example.

It appears that you need to set the substitutionWrappers. In your case that would be %. Then in the substitutions object, you would leave the % characters out.

With Best Regards,

Elmer

@thinkingserious thinkingserious added status: help wanted requesting help from the community type: question question directed at the library labels Sep 7, 2017
@sydneyhenrard
Copy link
Author

Is there a convention on variable?

SendgridService.prototype.sendTestEmail = function () {
  var text = 'Hi %DISPLAY_NAME% - %displayname%\n\n'
  const msg = {
    to: 'xxx@gmail.com',
    subject: 'Test Email',
    from: {email: 'no-reply@example.com', name: 'Test'},
    text: text,
    substitutionWrappers: ['%', '%'],
    substitutions: {
      DISPLAY_NAME: 'Test',
      displayname: 'Test'
    }
  }
  return sendgrid.send(msg)
}

The received email:

Hi %DISPLAY_NAME% – Test

@thinkingserious
Copy link
Contributor

thinkingserious commented Sep 8, 2017

Hello @sydneyhenrard,

I was able to reproduce this issue. I have added this to our backlog for a fix. It looks like given n substitution, substitution 0 is not getting set properly.

With Best Regards,

Elmer

@adamreisnz
Copy link
Contributor

@thinkingserious is this on your end or an issue with the Node SDK?

@thinkingserious
Copy link
Contributor

It's an issue with the SDK. I'm not quite sure exactly what the issue is though. I plan to examine the payload to help troubleshoot.

@sydneyhenrard
Copy link
Author

If I use camelCase variable, I have no problem with the substitutions even for substitution 0

@thinkingserious
Copy link
Contributor

Thanks @sydneyhenrard,

That should help get to the root cause quicker :)

@adamreisnz
Copy link
Contributor

I think I may know what the problem is, let me investigate.

@adamreisnz adamreisnz mentioned this issue Sep 11, 2017
@adamreisnz
Copy link
Contributor

#442 should fix this 👍

@thinkingserious
Copy link
Contributor

Merged as v6.1.3, thanks @adamreisnz!

@thinkingserious
Copy link
Contributor

@sydneyhenrard,

For helping us solve this issue, we would like to send you some swag as a token of our gratitude.

Thanks for supporting SendGrid!

With Best Regards,

Elmer

@greglbyv
Copy link

had the same problem in 01/2018. changed our substitution variables from %companyname% to %company_name% because single word variables were not working. fixed immediately.

@thinkingserious
Copy link
Contributor

Hi @greglbyv,

What version of the SDK are you using? Thanks!

With Best Regards,

Elmer

@enigram
Copy link

enigram commented Jun 1, 2018

Are substitutions supposed to work when using design built template? I can get them working only when I build the template by hand, the ones built with the design tool never work.

@thinkingserious
Copy link
Contributor

@airstofather,

To help you out I will need further detail. 1) Which template are you referring to? 2) Could you provide sample code? Both the template HTML and the Node.js code. Thank you!

Also, it might be best to open a separate issue. Thanks!

With Best Regards,

Elmer

@enigram
Copy link

enigram commented Jun 5, 2018

@thinkingserious

Please ignore my previous comment. After your reply I went back to look at it with fresh eyes and it was an extra space in the interpolated variable that was causing the issue which I didn't catch the first time.

All is working as advertised. Thank you.

@jay8t6
Copy link

jay8t6 commented Mar 25, 2019

@thinkingserious I have tried everything, camelcase, underscore. The variable still would not populate, when I do the testing via the sendgrid UI and pass in the variable, it works fine. It just wouldnt work through firebase cloud functions. Here's my code

I am using "@sendgrid/mail": "^6.3.1"

const msgbody = {
          to: userData.email,
          from: 'auto-reply@somedomain.com',
          subject: 'Registration Complete',
          templateId: 'd-dffc1e7c8a4a4ed5a4384eded1701f65',
          substitutionWrappers: ['{{', '}}'],
          substitutions: {
            first_name: userData.firstName
          }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: question question directed at the library
Projects
None yet
Development

No branches or pull requests

6 participants