On 7/24/2018, our team publicly launched dynamic content for transactional templates. It is now available for all customers sending over v3 of our Mail Send API. Iterate over lists, handle conditionals and more, thanks to native support for a subset of Handlebars syntax!
More information can be found in our blog post announcement.
You can currently use this feature by manually creating the request body as shown here.
Now, we need to create helper code and examples for this SDK.
So I ended up starting my startup's transactional email project without knowing dynamic templating was new. While the management decision to make dynamic templating default when the SDK didn't support the new feature was questionable, with a bit of help from your support team, I wrote some code so I could use the SDK. Here's a Gist.
https://gist.github.com/qgreg/4ea19b0241b8b74b88011e36b2641c3a
The pieces & parts are there for a real update. I hope others can take what I wrote and run with it. Good luck!
Thank you for your support @qgreg!
Please follow this link so that we can send you some SendGrid swag as a small token of our appreciation.
With Best Regards,
Elmer
that's nice @qgreg.
But for anyone relying on the SDK to stay in sync with the API, I find that extending classes and monkey patching the internals is overkill.
A SendGrid API request is just JSON. Since mail.get() returns a dictionary object, you can apply new keys directly to it without the SDK abstractions.
For example - adding dynamic templates to an existing Mail() instance is as simple as this:
# build the request
request_body = mail.get()
# attach whatever data you want directly...
request_body['personalizations'][0]['dynamic_template_data'] = {
'whatever': 'data you want'
}
# mail it out
sg.client.mail.send.post(request_body=request_body)
The SDK isn't doing anything magical. It's literally just building an internal dict, which is dumped to JSON via the call to .send.post().
Do you have an ETA for either #593 or #597 to be released?
Hello @Giaco9,
Those are next up in the backlog :) I'm currently building from #593.
Fixed in release v5.6.0
Hi ! I am not being able to find the documentation to add dynamic_template_data to the mail using this package. I only found how to configure the request body to accept dynamic data, link
I want to use this package to create the request_body with the dynamic_template_data. Could you guys provide a snippet or some documentation please ?
Thanks for your time
@adriancast - does my snippet above help?
Hi @leebenson ,
Your snippet helped me a lot to understand how this python package works. But I wanted to use this client in order to build the request body.
I just checked this commit and I found the example of how to use this new feature.
Thanks for your time ! 馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀馃帀
@thinkingserious The new documentation link gives 404
@pavs94 I've found out that actual docs could be found here https://github.com/sendgrid/sendgrid-python/blob/master/use_cases/transactional_templates.md
I tried using the same code as in the below link
https://github.com/sendgrid/sendgrid-python/blob/master/use_cases/transactional_templates.md
But I am still getting 400 bad request error. I am using sendgrid==6.0.4. Any idea what could be the issue?
Got the issue. I have been using legacy templates. Using the transactional template solved the issue.
Most helpful comment
that's nice @qgreg.
But for anyone relying on the SDK to stay in sync with the API, I find that extending classes and monkey patching the internals is overkill.
A SendGrid API request is just JSON. Since
mail.get()returns a dictionary object, you can apply new keys directly to it without the SDK abstractions.For example - adding dynamic templates to an existing
Mail()instance is as simple as this:The SDK isn't doing anything magical. It's literally just building an internal dict, which is dumped to JSON via the call to
.send.post().