I am try to send an email through Parse.com's SendGrid cloud module with the header param in order to include some unique arguments about the email being sent.
var SendGrid = require("sendgrid");
SendGrid.initialize(username, password);
SendGrid.sendEmail({
to: request.params.to,
from: request.params.from,
subject: request.params.subject,
html: request.params.html,
headers: JSON.stringify({ "unique_args": { "newsletter": request.params.newsletter }})
}, {
success: function(httpResponse) {
response.success(httpResponse);
},
error: function(httpResponse) {
response.error(httpResponse);
}
});
This gets the error message: JSON in headers is valid but incompatible
When I don't Stringify the header, I receive this error: Uncaught Error: Can't form encode an Object
More information about SendGrid Mail API: https://sendgrid.com/docs/API_Reference/Web_API/mail.html
More information about Parse.com SendGrid Cloud Module: https://www.parse.com/docs/cloud_modules_guide#sendgrid
Thanks!!