Skip to content

Add Dynamic Template Support #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thinkingserious opened this issue Jul 26, 2018 · 14 comments · Fixed by #593
Closed

Add Dynamic Template Support #591

thinkingserious opened this issue Jul 26, 2018 · 14 comments · Fixed by #593
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: twilio enhancement feature request on Twilio's roadmap

Comments

@thinkingserious
Copy link
Contributor

Issue Summary

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.

Acceptance Criteria

Documentation

@thinkingserious thinkingserious added status: help wanted requesting help from the community difficulty: medium fix is medium in difficulty up-for-grabs type: twilio enhancement feature request on Twilio's roadmap labels Jul 26, 2018
@qgreg
Copy link

qgreg commented Aug 1, 2018

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!

@thinkingserious
Copy link
Contributor Author

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

@leebenson
Copy link

leebenson commented Aug 9, 2018

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().

@Giaco9
Copy link

Giaco9 commented Aug 15, 2018

Do you have an ETA for either #593 or #597 to be released?

@thinkingserious
Copy link
Contributor Author

Hello @Giaco9,

Those are next up in the backlog :) I'm currently building from #593.

@thinkingserious
Copy link
Contributor Author

Fixed in release v5.6.0

@adriancast
Copy link

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

@leebenson
Copy link

@adriancast - does my snippet above help?

@adriancast
Copy link

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
Copy link
Contributor Author

HI @adriancast,

You may also find updated documentation here.

Thanks!

With Best Regards,

Elmer

@pavs94
Copy link

pavs94 commented Dec 17, 2018

@thinkingserious The new documentation link gives 404

@vlad-tokarev
Copy link

@parokshsaxena
Copy link

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?

@parokshsaxena
Copy link

Got the issue. I have been using legacy templates. Using the transactional template solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: twilio enhancement feature request on Twilio's roadmap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants