Search code examples
sendgridsendgrid-api-v3sendgrid-templates

Unable to get a value from the key in Sendgrid template


I am trying to get a value and use it in sendgrid email template. The JSON looks like this.

"productskumapping" : { "created/updated" : 2, "failed" : 0 }

{{productskumapping.created/updated}} does not give any value in the email template. the macro is not replaced. But the macro must replace with 2. How to make this work? the slash character("/") is causing the issue. Please sugggest any solution for this.


Solution

  • Twilio SendGrid developer evangelist here.

    SendGrid uses handlebars style expressions to interpolate data. I just learned that slashes were a deprecated way that handlebars the library used to navigate objects. I don't know if SendGrid uses that exact handlebars library internally, but I thought it was important.

    I believe the way to get around a slash in a key, like you have, is to surround the key with square brackets instead. This is known as literal segments and would look like this for you:

    {{productskumapping.[created/updated]}}