sendgrid-nodejs icon indicating copy to clipboard operation
sendgrid-nodejs copied to clipboard

Bulk email with to {{name}} in body with substituions not working

Open apoorv-1310 opened this issue 8 years ago • 4 comments

Issue Summary

Hi, i need to send bulk email with a static HTML template and dynamic name in each mail

Steps to Reproduce

{
  "personalizations": [
    {
      "to": [
        {
          "email": "[email protected]"
        },
        {
          "email": "[email protected]"
        },
        {
          "email": "[email protected]"
        }
      ],
      "substitutions":{
      	"{{name}}":["dfsda","sdfb","cfsd"]
      },
      "subject": "Hello, World!"
    }
  ],
  "from": {
    "email": "[email protected]",
    "name": "test"
  },
  "subject": "Hello, World!",
  "content": [
    {
      "type": "text/html",
      "value": "<html><p>Hello {{name}}, world!</p></html>"
    }
  ]
}

here , each maiil should have first_name individually in each mail, but instead it is giving me errror


{
    "errors": [
        {
            "message": "Bad Request",
            "field": null,
            "help": null
        }
    ]
}

neither %name%,-name- and nor -name- is working

Technical details:

  • sendgrid-nodejs Version: master (latest commit: [commit number])
  • Node.js Version: 4.1.2

apoorv-1310 avatar Apr 15 '18 16:04 apoorv-1310

Hi @apoorv-1310,

Could you please extract the error message, like so? Thanks!

Also, would you mind providing the full source code that was used to generate that payload? I believe "{{name}}":["dfsda","sdfb","cfsd"] should probably be "name":["dfsda","sdfb","cfsd"].

Thanks!

With Best Regards,

Elmer

thinkingserious avatar Apr 16 '18 22:04 thinkingserious

i'm facing kind of same issue .. sending from node js this is my msg payload msg = { "from": { "email": "[email protected]" }, "personalizations": [{ "to": [{ "email": "[email protected]" }], "dynamic_template_data": { "name": "jhon", "plan": "xyz", "amount": "80000", }, }], "subject": "Notification", "template_id": "<my-template-id>", }; SGMail.send(msg);

this is my template

Hello {{name}}, some random text plan: {{plan}} amount you paid: {{amount}}

substitution data is missing in mail .. any idea?

satishsathya11 avatar Jul 27 '18 10:07 satishsathya11

Hi @satishsathya11,

Please move the dynamic_template_data inside of the personalizations object like so.

Thanks!

thinkingserious avatar Jul 31 '18 01:07 thinkingserious

@apoorv-1310

I think what you are looking for is below. Since you are using a substitution per email you need to break each to into its own container. Hopefully, the below example will help.

{
  "personalizations": [
    {
      "to": [
        {
          "email": "[email protected]"
        }
      ],
      "substitutions":{
        "{{name}}":{"dfsda"}
      },
      "subject": "Hello, World!"
    },
    {
      "to": [
        {
          "email": "[email protected]"
        }
      ],
      "substitutions":{
        "{{name}}":{"sdfb"}
      },
      "subject": "Hello, World!"
    },
    {
      "to": [
        {
          "email": "[email protected]"
        }
      ],
      "substitutions":{
        "{{name}}":{"cfsd"}
      },
      "subject": "Hello, World!"
    }
  ],
  "from": {
    "email": "[email protected]",
    "name": "test"
  },
  "subject": "Hello, World!",
  "content": [
    {
      "type": "text/html",
      "value": "<html><p>Hello {{name}}, world!</p></html>"
    }
  ]
}

kylearoberts avatar Oct 29 '18 15:10 kylearoberts