Closed yamalight closed 1 year ago
Hi @yamalight
Please use the following code and it should work fine:
let defaultClient = SibApiV3Sdk.ApiClient.instance;
let apiKey = defaultClient.authentications['api-key'];
apiKey.apiKey = 'YOUR_API_KEY';
let apiInstance = new SibApiV3Sdk.TransactionalEmailsApi();
let sendSmtpEmail = new SibApiV3Sdk.SendSmtpEmail();
sendSmtpEmail.subject = "My {{params.subject}}";
sendSmtpEmail.sender = {"name":"John Doe","email":"shubham.upadhyay@sendinblue.com"};
sendSmtpEmail.to = [{"email":"shubham.upadhyay@sendinblue.com","name":"Jane Doe"}];
sendSmtpEmail.params= {
firstname: "John",
lastname: "Doe"
}
sendSmtpEmail.templateId = 54;
apiInstance.sendTransacEmail(sendSmtpEmail).then(function(data) {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}, function(error) {
console.error(error);
});
Kindly remember to replace the placeholder i.e. YOUR_API_KEY.
Also, the template 54 HTML content is as following:
<html><head></head><body><h1>
Hello! This is production test for the template 54.
firstname: {{params.firstname}}, lastname: {{params.lastname}}
</h1></body></html>
@shubhamUpadhyayInBlue I'm no longer involved with the client who used your SDK (and I think they've ended up using different provider) so cannot test the code, but if it works - feel free to close the issue.
I've tried sending a templated email and it seems like
TransactionalEmailsApi.sendTemplate
currently doesn't handle attributes passed to it.Template was pretty simple:
Following code results in empty values:
I also want to note that official docs for sendTemplate API method do not include
attributes
,params
or any other props - does server just not process this?The solution that worked for me was to use
TransactionalEmailsApi.sendTransacEmail
instead while passingtemplateId
, i.e.:Am I misunderstanding the use of
sendTemplate
or is it currently broken?