Skip to content

Commit

Permalink
Return personalizations as an array of request compatible JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
hpaul authored May 30, 2017
1 parent 4af67b1 commit 7dc8567
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/helpers/mail/mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,11 @@ function Mail(from_email, subject, to_email, content) {
}
this.personalizations.push(personalization);
};

// This array must be JSON compatible with the raw sendgrid request
this.getPersonalizations = function() {
return this.personalizations;
return this.personalizations.map(function(personalization) {
return personalization.toJSON();
});
};

this.setSubject = function(subject) {
Expand Down

2 comments on commit 7dc8567

@Theo-
Copy link

@Theo- Theo- commented on 7dc8567 Jun 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change for many examples on the web.

var mailJSON = mail.toJSON();
var substitution = new helper.Substitution(key, value)
mailJSON.personalizations[0].addSubstitution(substitution);

will not work anymore. Replace with:

var mailJSON = mail.toJSON();
mailJSON.personalizations[0].substitutions = {
    key: value
}

just posting for future reference.

@thinkingserious
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up @Theo-!

This PR did not change addSubstitution, I don't think: https://github.com/sendgrid/sendgrid-nodejs/blob/master/lib/helpers/mail/mail.js#L621

Could you please clarify. Thanks!

Please sign in to comment.