Using Go, and Sendgrid's API to send emails using Sendgrid email templates. There is a feature Sendgrid added that allows you to dynamically populate strings in the email template. This works. However, I'm trying to use their AddSubstitutions method (Sendgrid's definition of 'AddSubstitutions' below) to pass an array of strings, to be dynamically populated in a Sendgrid email template.
Link to the Sendgrid SMTPAPI Repo: https://github.com/sendgrid/smtpapi-go/blob/master/smtpapi.go
// AddSubstitutions adds a multiple substitutions to a specific key
func (h *SMTPAPIHeader) AddSubstitutions(key string, subs []string) {
for i := 0; i < len(subs); i++ {
h.AddSubstitution(key, subs[i])
}
}
When the API call is made - there are no errors, and an email is sent, however, only the first string in the array that's passed with the 'AddSubstitutions' method populates the email. I've printed the contents of the array to the console, and I can see multiple values exist in the array. In the template, I've tried adding additional '-keys-' to be populated, but when I do that, the first element in the array gets populated multiple times. How can I pass an array to Sendgrid's API, and have it populate the body of the email template with every string in the array? Code below:
nickNameArray := make([]string, 0)
for i, _ := range names {
nickNameArray = append(nickNameArray, names[i])
}
m.AddSubstitutions("-nickNames-", nickNameArray)
The message is sent to Sendgrid via another function - this is the relevant logic.