Skip to content

Instantly share code, notes, and snippets.

@ikedumancas
Created July 17, 2018 08:11
Show Gist options
  • Select an option

  • Save ikedumancas/11b640d6af9d2c7a32342be72e686d9c to your computer and use it in GitHub Desktop.

Select an option

Save ikedumancas/11b640d6af9d2c7a32342be72e686d9c to your computer and use it in GitHub Desktop.
Python: Copy Sendgrid Template from another account
# Install sendgrid
# pip install sendgrid
import sendgrid
import json
sendgrid_source_api_key = 'KEY'
sendgrid_destination_api_key = 'KEY'
sg_source = sendgrid.SendGridAPIClient(apikey=sendgrid_source_api_key)
sg_destination = sendgrid.SendGridAPIClient(apikey=sendgrid_destination_api_key)
source_response = sg_source.client.templates._('TEMPLATE_ID').get()
template = source_response.to_dict
version = template['versions'][-1]
exclude_version_keys = ('id', 'user_id', 'template_id', 'updated_at')
for k in exclude_version_keys:
version.pop(k, None)
# Create an empty Template on destination account
template_data = {
"name": template['name']
}
new_template_response = sg_destination.client.templates.post(request_body=template_data)
response_string = new_template_response.body.decode('utf-8')
new_template_id = response_string['id']
# Create Version for the new template
new_version_response = sg_destination.client.templates._(new_template_id).versions.post(request_body=version)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment