-
Notifications
You must be signed in to change notification settings - Fork 782
Closed
Labels
type: questionquestion directed at the libraryquestion directed at the library
Description
Hi,
I keep on getting the following error when trying to send a transactional email using a template I've setup within sendGrid.
Status code: 400
Error message: message: 'Bad Request', field: null, help: null
I've followed the following example: https://github.com/sendgrid/sendgrid-nodejs#without-mail-helper-class and have developed the following, its probably something simple i've missed or missunderstood.
const subject = 'Email subject';
const templateId = 'myTemplateId';
const sg = require('sendgrid')(myapikey);
const request = sg.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: {
"personalizations": [
{
"to": userEmails, // aray of user emails
"substitutions": {
"-userName-": userDetails.name,
"-productPrice-": productDetails.price,
"-productUrl-": productDetails.url,
"-productName-": productDetails.name,
},
"subject": subject
}
],
"from": {
"email": "myemail",
"name": "myname"
},
"content": [
{
"type": "text/html"
}
],
"template_id": templateId
}
});
sg.API(request, function (error, response) {
if (error) {
console.log('Error response received');
}
console.log(response.body.errors);
});
Technical details:
- sendgrid-nodejs Version: 4.7.1
- Node.js Version: 6.6
Thanks in advance.
Tom
Metadata
Metadata
Assignees
Labels
type: questionquestion directed at the libraryquestion directed at the library