sparkpost.templates
¶
-
class
sparkpost.templates.
Templates
(base_uri, api_key, transport_class=<class 'sparkpost.base.RequestsTransport'>)¶ Templates class used to create, update, delete, list and get templates. For detailed request and response formats, see the Templates API documentation.
-
create
(**kwargs)¶ Create a template based on the supplied parameters
Parameters: - id (str) – ID used to reference the template
- name (str) – Editable display name
- description (str) – Detailed description of the template
- published (bool) – Defaults to False. Whether the template is a published or draft version
- track_opens (bool) – Defaults to transmission level setting. Used to track opens of transmission
- track_clicks (bool) – Defaults to transmission level setting. Used to track clicks of transmission
- is_transactional (bool) – Defaults to transmission level setting. Distinguishes between transactional and non-transactional messages for unsubscribe and suppression purposes
- html (str) – HTML part of template
- text (str) – Text part of template
- subject (str) – Subject of template
- from_email (str) – Friendly from of template, domain must be a verified sending domain to your account or template create will fail
- reply_to (str) – Reply to of template
- custom_headers (dict) – Used to set any headers associated with template
Returns: a
dict
with the IDRaises: SparkPostAPIException
if template uses an unverified sending domain or there’s a syntax error in the content
-
delete
(template_id)¶ Delete a template by ID
Parameters: template_id (str) – ID of the template you want to delete Returns: TODO Raises: SparkPostAPIException
if template is not found or if template is in use
-
get
(template_id, draft=None)¶ Get a template by ID
Parameters: - template_id (str) – ID of the template you want to retrieve
- draft (bool) – Defaults to None. If True, returns the most recent draft template. If False, returns the most recent published template. If None, returns the most recent template version regardless of draft or published.
Returns: the requested template if found
Raises: SparkPostAPIException
if template is not found
-
list
()¶ Get a list of your templates
Returns: list of templates Raises: SparkPostAPIException
if API call fails
-
preview
(template_id, substitution_data, draft=None)¶ Get a preivew of your template by ID with the provided substitution_data
Parameters: - template_id (str) – ID of the template you want to retrieve
- substitution_data (dict) – data to be substituted in the template content
- draft (bool) – Defaults to None. If True, previews the most recent draft template. If False, previews the most recent published template. If None, previews the most recent template version regardless of draft or published.
Returns: the requested template if found with content expanded using substitution data provided
Raises: SparkPostAPIException
if API call fails
-
update
(template_id, **kwargs)¶ Update a template by ID based on the supplied parameters
Parameters: - template_id (str) – ID of the template you want to retrieve
- name (str) – Editable display name
- description (str) – Detailed description of the template
- published (bool) – Defaults to False. Whether the template is a published or draft version
- track_opens (bool) – Defaults to transmission level setting. Used to track opens of transmission
- track_clicks (bool) – Defaults to transmission level setting. Used to track clicks of transmission
- is_transactional (bool) – Defaults to transmission level setting. Distinguishes between transactional and non-transactional messages for unsubscribe and suppression purposes
- html (str) – HTML part of template
- text (str) – Text part of template
- subject (str) – Subject of template
- from_email (str) – Friendly from of template, domain must be a verified sending domain to your account or template create will fail
- reply_to (str) – Reply to of template
- custom_headers (dict) – Used to set any headers associated with template
Returns: TODO
Raises: SparkPostAPIException
if template is not found
-