Actually I am trying to send the email with ZeptoMail . I had created one template .
i.e.
<html>
<body>{{name}}</body>
</html>
And I am using the zepto email sending api .
const axios = require('axios');
let data = JSON.stringify({
"from": {
"address": "abc@abc.com",
"name": "Paula"
},
"to": [
{
"email_address": {
"address": "abc@abc.com",
"name": "Abc"
}
}
],
"subject": "Hi",
"template_key": "my_template_key"
});
let config = {
method: 'post',
url: 'https://api.zeptomail.com/v1.1/email/template',
headers: {
'Authorization': 'my_token',
'Content-Type': 'application/json',
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
But need to also send the "name" which is act like a variable in my template. how can I send it.
You can make use of "merge_info"
key in the request body.
Add all your variables under this key.
Reference: Documentation of API
Example (in Single Email Template): In this case, all variables are common.
let data = JSON.stringify({
"from": {
"address": "abc@abc.com",
"name": "Paula"
},
"to": [
{
"email_address": {
"address": "abc@abc.com",
"name": "Abc"
}
}
],
"subject": "Hi",
"template_key": "my_template_key",
"merge_info": {
"name": "Guest",
...other_variables_here
}
});
Example (in Multiple Email Template): In this case, some variables differs for each email.
let data = JSON.stringify({
"from": {
"address": "abc@abc.com",
"name": "Paula"
},
"to": [
{
"email_address": {
"address": "abc@abc.com",
"name": "Abc"
},
"merge_info": {
"name": "Abc",
...other_variables_here
}
},
{
"email_address": {
"address": "def@abc.com",
"name": "Def"
},
"merge_info": {
"name": "Def",
...other_variables_here
}
}
],
"subject": "Hi",
"template_key": "my_template_key",
});