Sendgrid API - section & substitution tags for transactional emails

I’m triggering a transactional email via the SendGrid API but cannot get the section and substitution tags to populate in the SendGrid template (i.e. test that dynamic data generated in Bubble is populated in the SendGrid email template when being sent out). I’ve tried everything (including enclosing the section tags in the personalizations header). Here is my current setup in Postman:

The call works correctly and does send the email with the correct “from”, “subject”, and “to” fields. The section and substitution tags do not work at all. Any ideas?

The docs suggest that sections (not “section”) is at the same level as personalizations, rather than inside it.
Also, substitutions is supposed to be inside personalizations.

So it’d be:
"personalizations": [ {"to": [ ... ], "substitutions": {"key1": "value1", "key2": "value2"} } ], "sections": { "key1": "value", "key2": "value2" }

I.e. just swap your sections and substitutions.


Edit: reference for personalizations has some example JSON:

Sendgrid docs su**s, really. I feel your pain

Hey @supernaturally,

Feel free to take advantage of CoBubble’s SendGrid plugin with support for templates and substitution tags via the latest Web API v3. Customizing SendGrid can be a pain but can yield beautiful results. With clients such as Uber, Airbnb and Spotify, you should consider ‘less than ideal’ documentation as a great way to challenge your comprehension just like the engineers at those great companies did. :slight_smile:

1 Like

You hit the nail on the head @mishav . This fixed the problem, and my calls now work perfectly. Thanks!

For anyone interested, here is my API call to Sendgrid for inserting dynamic data into a template using Bubble’s API Connector. The issue I was having before had to do with the sections and substitutions tags - if you just want various %tags% substituted into your SendGrid template, you should just use substitution tags.

Here is my template, just pop it into the API connector. I always prefer to make my own API calls so I can update and control fine details. It works and I have it live, just be sure to put the variables (%variable1%, %variable2%, %variable3%, etc.) exactly as typed into either your html code or directly type it into Sengrid’s Editor.

1. Use these for your headers (put your API key after “Bearer”):

2. Use this for the body:

3. Go into the API Connector copy/paste the info from Postman (above)
(if you need to help with this, you should probably head over to the tutorials)

4. Update your template inside of Sendgrid:

Hope this helps, cheers!


very helpful thanks

1 Like

@supernaturally - have you tried passing a multiline text (say from a multi-line text input) as one of the variables?

I keep getting the following error:
{“errors”:[{“message”:“Bad Request”,“field”:null,“help”:null}]}

I found the answer if you are interested: Strange behaviour from SendGrid

I haven’t tried this so not sure sorry. Maybe @supernaturally can help?