2
votes

I try to send a single Email via SendGrid API v3 with curl call.

I created a template and reference on it. In this template i placed some vars to be replace. Mails will be send successfully, but without it's string replacement.

There are the datastructure I sent. What do I wrong?

{ "template_id": "d-1074861686174fbfac02e25381e02e32", "personalizations": [ { "to": [{"email": "[email protected]"}], "sub": { "%USERNAME%": ["Hans"], "%DATE%": ["25.12.1988"], "%DAYS%": ["58"], }, }, ], "from": { "email": "[email protected]", "name": "Kundenservice" }, "reply_to": { "email": "[email protected]", "name": "Kundenservice" } }

1

1 Answers

3
votes

The variables that you want to replace in your template should be in curly braces

{{ email }}

The thing is that now the substitution key changed to dynamic_template_data

 {
   "from":{
      "email":"[email protected]"
   },
   "personalizations":[
      {
         "to":[
            {
               "email":"[email protected]"
            }
         ],
         "dynamic_template_data":{
            "name":"Sample Name",
            "city":"Place",
            "state":"CO"
          }
      }
   ],
   "template_id":"[template_id]"
}

Try this example and let me know if it works for you :)

There is also official documentation where it is explained very clear the entire sending process How to send an email with Dynamic Transactional Templates