My transactional emails are automated, I would like to be able to run a manual end to end test on a new transactional template version before activating it. Could you please add an optional version_id to /mail/send which overrides the active version?
You hint at this sort of functionality here:
https://sendgrid.com/docs/API_Reference/Web_API_v3/Transactional_Templates/index.html
"Templates may have multiple versions with different content, these may be changed and activated through the API. These allow split testing, multiple languages of the same template, etc."
I can't comprehend how you'd have automated split testing or multiple languages using versions without specifying a version_id.
Thanks
+1 any updates here? It seem silly to have the idea of version but not be allowed to specify which version to use.
I've been looking for this exact functionality for language versioning in my case, it does seem strange that you cannot specify a version for send.
In any case, even if this was possible, it still wouldnt be a great option to handle multiple languages and so perhaps a more dedicated solution might be appropriate.
Pull requests to add this feature are welcome and will be reviewed based on priority, but Twilio SendGrid is not actively building new functionality for the library.
@thinkingserious, this is a server side feature request.
Hi @timmehmainframe,
I think I misunderstood. For your use case, can you do the following?
POST https://api.sendgrid.com/v3/templates/:template_id/versions/:version_id/activate HTTP/1.1
Hi @thinkingserious,
Thanks for your response.
I have automated emails which could go out while the non technical admins are testing their content updates, so activating the newest version to test could cause an end user to get an email version which hasn't been approved or has content/html errors etc.
I'm on google app engine, I don't want to call /activate before each mail/send and I don't want to limit my task queue to 1 concurrent task.
I have a work around involving 5 api calls to sendgrid: (Ideally I'd just like to be able to specific version_id as well as template_id in /mail/send)
I've cherry picked part of my code incase it's useful:
version_response = sg.client.templates._(template_id).versions._(version_id).get() # 1.
version_data = json.loads(version_response.body)
html_content = version_data['html_content']
subject = version_data['subject']
plain_content = version_data['plain_content']
duplicate_response = sg.client.templates._(template_id).post(request_body={ # 2.
"name": "temp-{template_id}-{dt}".format(
template_id=template_id,
dt=datetime.utcnow().strftime('%Y-%m-%d-%H-%M-%S'))
})
duplicate_data = json.loads(duplicate_response.body)
duplicate_template_id = duplicate_data['id']
duplicate_version_id = next(version['id'] for version in duplicate_data['versions'] if
version['html_content'] == html_content and
version['subject'] == subject and
version['plain_content'] == plain_content)
sg.client.templates._(duplicate_template_id).versions._(duplicate_version_id).activate.post() # 3.
request_body = message.get()
sg.client.mail.send.post(request_body=request_body) # 4.
sg.client.templates._(duplicate_template_id).delete() # 5.
Hello @timmehmainframe,
Thank you for taking the time to elaborate on your use case!
I will pass your feedback along to the product team.
With best regards,
Elmer
For internal tracking: MP-6100
Hey all, good to see that this has been suggested as an improvement? Any progress on when we can expect this to be implemented and publicly available? Thx :smile:
Closing as this is not a change that can be made in this library. An internal ticket has been filed, but product teams and support do not currently check GitHub when determining priority/impact.
@dgrubelic Best to file a support ticket and reference the above ID.
@childish-sambino if you are saying that this is not a change that can be made in this library, How is sendgrid able to send a test email using a specific template version when you are testing your email out? There is an id version_id_override that is sent in the post request.
POST -> https://api.sendgrid.com/v3/marketing/test/send_email?test-source=dynamic-templates
sample body -> {
emails: ["sample to email"]
from_address: "sample from email"
template_id: "sample template id"
version_id_override: "sample version id"
}
@megatrongh I'm not familiar with that API. Could you link to the docs so I can investigate?
But regardless, this issue is requesting the ability to do so from the mail-send API; not from a marketing campaign.
@childish-sambino I couldn't find it in the docs. I was looking at the request payload of how that was being made possible in the sendgrid dashboard when you want to test out a version of your dynamic template. Earlier you said it's not a change that can be done in the library. I didn't understand that. So I was asking how that was achieved through the marketing api, and why that cannot be done for the mail-send API also.
@childish-sambino if you are saying that this is not a change that can be made in this library, How is sendgrid able to send a test email using a specific template version when you are testing your email out? There is an id
version_id_overridethat is sent in the post request.POST -> https://api.sendgrid.com/v3/marketing/test/send_email?test-source=dynamic-templates sample body -> { emails: ["sample to email"] from_address: "sample from email" template_id: "sample template id" version_id_override: "sample version id" }
Is it possible to send template data in this request? This actually works, but I don't know how to send some data in there.
Maybe it's some leftover endpoint from previous versions of the API.
This is an API limitation. If the mail-send API does not support the template version, then there's nothing this library can/should do.
Regarding the template test API, it's not a documented endpoint so best not to take a production dependency on it. For how it's implemented on the backend to send a specific version of a template, this may be how the issue would be resolved on the mail-send backend, but is not something we can leverage in this library.
Is there an issue open for this? I really need this functionality
Hi @PascalUlor @megatrongh ,
Try to use this api . https://sendgrid.api-docs.io/v3.0/send-test-email/marketing-campaigns-send-test
mail test api:
https://api.sendgrid.com/v3/marketing/test/send_email
you should be able to use this api in your dev , test environments .
You can get all the available templates with version using the below api .
https://api.sendgrid.com/v3/templates?generations=dynamic
Once you have all templates and versions , choose the version_id of your choice based on a version name , you can add to the template in sendgrid.
https://api.sendgrid.com/v3/marketing/test/send_email
In the mail test api you should be able to set the below fields.
{
"template_id": "string (required)",
"version_id_override": "string (optional)",
"sender_id": "integer (optional)",
"custom_unsubscribe_url": "string (optional)",
"suppression_group_id": "integer (optional)",
"emails": [
"string"
],
"from_address": "string (optional)"
}
Most helpful comment
For internal tracking: MP-6100