Reputation: 1
I am trying to make a call to SendGrid via the Python SDK:
self._sendgrid.client.templates._(template_id).versions._(version_id).patch(request_body=data)
where the data is:
{"name": "this is a name1234.12341234132", "subject": "{{{subject}}}"}
I am getting the following exception:
{'error': 'Cannot update the active version with warnings.', 'warnings': [{'message': 'Failed to validate handlebars'}]}
My goal is to get the subject
value updated to use {{{subject}}}
as the value, so that we can dynamically set the Subject of the emails based on whatever is calling our function to send the template. I can do this, by manually setting the template versions within SendGrid directly, but trying to use the SDK or API, I am unable to do this. We have a lot of templates and it would take a while to update them all manually. Looking for help.
Solution to the problem I am experiencing when using the Python SDK for SendGrid.
Upvotes: 0
Views: 1771
Reputation: 41
This is an older question, but I had the same problem and was able to create a custom subject line using Python and SendGrid's dynamic templates by following the steps found at the following SendGrid support page: https://support.sendgrid.com/hc/en-us/articles/1260802535110-Create-a-Dynamic-Email-Subject-Line-with-Mustache-Templates. The general steps are summarized below.
Open your Dynamic Template and click the "Settings" wheel on the top left side of the page. You should see an area to enter your subject, and it is in this area where {{{subject}}} should be placed.
Update your code to pass your subject value to the appropriate variable in your dynamic_template_data. I used SendGrid's example dynamic message code, which has been slightly edited below.
def SendDynamic()
message = Mail(
from_email='[email protected]',
to_emails='[email protected]',
)
message.dynamic_template_data = {
"name":"this is a name1234.12341234132",
"subject":"this is your desired subject",
}
message.template_id = TEMPLATE_ID
sg = SendGridAPIClient(api_key='SG.xxxxxxxxxxxxxx')
response = sg.send(message)
Upvotes: 2