sendgrid / sendgrid-nodejs

The Official Twilio SendGrid Led, Community Driven Node.js API Library
https://sendgrid.com
MIT License
3k stars 781 forks source link

personalizations / substitutions not working with simple text or html content on v3 api #1265

Closed thomas-topway-it closed 3 years ago

thomas-topway-it commented 3 years ago

Issue Summary

Hello, we would like to perform personalizations / substitutions using v3 api but without using a template, as described here

https://sendgrid.com/docs/for-developers/sending-email/personalizations/#sending-a-single-email-to-a-single-recipient-with-substitutions

technically it should be straightforward, because you can just allow replacement of the substitutions keys when they are found in the text or html email content, but currently that does not seem to work.

When sending through the v3 api an object like

{
  text: ' hello {{first_name}} ... ',
  "personalizations": [
    {
      "to": [
        {
          "email": "recipient@example.com"
        }
      ],
      "substitutions": {
        "{{first_name}}": "Johann"
      },
      "subject": "YOUR SUBJECT LINE GOES HERE"
    }
  ]
}

substitutions don't work when you provide the email content directly without using a template

willfolsom commented 3 years ago

@thomas-topway-it This is an issue in the Go version as well (trying to override subjects results in "(no subject)"). It must be further up the chain in the SendGrid API.

JenniferMah commented 3 years ago

Hi @thomas-topway-it are you using the sendgrid-nodejs library to make the request?

thomas-topway-it commented 3 years ago

@JenniferMah

sure, we are using sendgrid-nodejs

childish-sambino commented 3 years ago

You'll need to drop the wrapper characters in the substitutions keys. The library adds the handlebars automatically.

"substitutions": {
  "first_name": "Johann"
},
thomas-topway-it commented 3 years ago

It works removing the brackets from the substitutions keys, thanks