I am successfully sending emails using SendGrids Web API v3 but can't get the subsitutions to work when sending emails using templates. The emails come through successfully but no substitutions take place. Here is my (simplified) SendGrid template:
<html>
<head>
<title></title>
</head>
<body>
<div>You can reset your password by clicking on this link: {callbackUrl}</div>
<%body%>
</body>
</html>
And here is the JSON formatted body I'm sending:
{
"personalizations":[
{
"to":[
{
"email":"[email protected]"
}
]
}
],
"sub" : {
"{callbackUrl}" : "www.mysite.com/changepassword"
},
"from":{
"email":"[email protected]"
},
"template_id" :"5f852a2e-996b-4f04-be05-31766d1092d8",
"subject":"Reset your password",
"content":
[
{"type": "text/plain", "value": "Thank you"}]
}
The email is generated with the correct template, subject, and is sent to the correct email address however the email body contains the template without substitutions:
You can reset your password by clicking on this link: {callbackUrl}
Thank you
I'm at a loss as to what I'm doing wrong. I'm using currently using Postman to send the request while attempting to track down the issue.
You need to use key
substitutions
underpersonalizations
, notsub
as it's said in the docs. Also it has different structure thansub
.