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

Dynamic Template Data is not showing! #729

Closed
kayson123 opened this issue Aug 14, 2018 · 15 comments
Closed

Dynamic Template Data is not showing! #729

kayson123 opened this issue Aug 14, 2018 · 15 comments
Labels
type: support ticket that should be redirected to support

Comments

@kayson123
Copy link

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!

@juliankmazo
Copy link

I'm having the same issues. I've spent already like 4 hours. What's going on?
I'm seeing some issues with other languages too

@juliankmazo
Copy link

@kayson123 I did a last change and it was updating to the last release #703 (comment)

Now is working for me. Try doing that.

@thinkingserious thinkingserious added type: question question directed at the library difficulty: unknown or n/a fix is unknown in difficulty status: waiting for feedback waiting for feedback from the submitter labels Aug 16, 2018
@thinkingserious
Copy link
Contributor

Hello @kayson123,

Have you upgraded the SDK to v6.3.1?

Also, you may try {{ voucherCode }} vs {{voucherCode}}.

Thanks!

With Best Regards,

Elmer

@juliankmazo,

Thanks for jumping in to help!

@nicjohnson
Copy link

It looks like the dynamic_template_data must be inside a personalizations array in order for it to work.

This works for me:

from: 'noreply@email.com',
subject: 'Thanks for your recent review',
templateId: 'template_id',
personalizations: [
            {
              to: {
                name: 'Some One',
                email: 'email@email.com'
              },
              dynamic_template_data: {
                review: {
                  url: 'https://www.google.com'
                }
              }
            }
          ]

@raine
Copy link

raine commented Sep 28, 2018

Above poster is correct. There is a bug either in the library code or typescript definitions.

export interface PersonalizationData {
  to: EmailData | EmailData[],
  cc?: EmailData | EmailData[],
  bcc?: EmailData | EmailData[],
  subject?: string;
  headers?: { [key: string]: string };
  substitutions?: { [key: string]: string };
  dynamicTemplateData?: { [key: string]: string; };
  customArgs?: { [key: string]: string };
  sendAt?: number;
}

This would suggest that you can pass dynamicTemplateData as a value in PersonalizationData, but it has to actually be snake case, dynamic_template_data.

@thinkingserious
Copy link
Contributor

Hi @raine,

I believe this PR addresses that issue. I hope that helps!

With Best Regards,

Elmer

@alexbjorlig
Copy link

With a fresh install of sendgrid 6.4.0, this issue is still present. The dynamic template data, is only working if passed with dynamic_template_data , but types suggests dynamicTempalteData.

@manan
Copy link

manan commented Oct 31, 2019

I'm facing the same issue. Are the typescript definitions for the library incorrect? Can someone please respond.

@coolnalu
Copy link

I spent 2 hours trying to debug this issue only to realize that the issue occurs on a BCC'ed email.

@CShigaki
Copy link

Is there any workaround to this issue? I'm facing the same problem.

@childish-sambino
Copy link
Contributor

@CShigaki Could you provide sample code and template that's not working? And what library version are you using?

@CShigaki
Copy link

CShigaki commented Feb 12, 2020

@childish-sambino I'm actually using a PHP library and the problem only occurs as @coolnalu said. When setting a BCC through the sendgrid interface (https://app.sendgrid.com/) instead of setting it with code, the email sent to the BCC does not receive (or apply, I don't know yet) the dynamic template data. I have no idea why this happens but I solved it by setting the BCC via code.

@childish-sambino
Copy link
Contributor

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.

@childish-sambino childish-sambino added type: support ticket that should be redirected to support and removed difficulty: unknown or n/a fix is unknown in difficulty status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library labels Feb 12, 2020
@thinkingserious
Copy link
Contributor

Hello @kayson123,

Thanks for submitting a GitHub issue! We are very sorry that you are running into this problem. In order to better serve you, as this does not present itself as a library specific issue, we would like to ask that you reach out to our support team at https://support.sendgrid.com.

Thank you!

SendGrid DX Team

@waelmas
Copy link

waelmas commented Nov 10, 2020

The solution that worked for me is placing the dynamic_template_data inside the personalization object in the exact way seen below:

    "personalizations": [
        {
              "dynamic_template_data": {
            "fullname": "full Name",
            "useremail": ":info@test.coml",
            "userphone": "56456",
            "usermsg": "tex fdsfgasdf t"
    },
            "to": [
                {
                    "email": "test1@test.com"
                }
            ],
            "cc": [
                {
                    "email": "test@test.com"
                }
            ]
        }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: support ticket that should be redirected to support
Projects
None yet
Development

No branches or pull requests