diff --git a/README.rst b/README.rst index cacda11..5bfb175 100644 --- a/README.rst +++ b/README.rst @@ -7,6 +7,7 @@ .. _Sign up: https://app.sparkpost.com/sign-up?src=Dev-Website&sfdcid=70160000000pqBb .. _Developer Hub: https://developers.sparkpost.com +=========================== SparkPost Python API client =========================== @@ -30,7 +31,7 @@ The super-mega-official Python package for using the SparkPost API. Installation ------------- +============ Install from PyPI using `pip`_: @@ -40,13 +41,11 @@ Install from PyPI using `pip`_: .. _pip: http://www.pip-installer.org/en/latest/ -.. _pip: http://www.pip-installer.org/en/latest/ - -Get a key ---------- +Initialization +============== -Go to `API & SMTP`_ in the SparkPost app and create an API key. We recommend using the ``SPARKPOST_API_KEY`` environment variable: +Go to `API Keys`_ in the SparkPost app and create an API key. We recommend using the ``SPARKPOST_API_KEY`` environment variable: .. code-block:: python @@ -60,11 +59,11 @@ Alternatively, you can pass the API key to the SparkPost class: from sparkpost import SparkPost sp = SparkPost('YOUR API KEY') -.. _API & SMTP: https://app.sparkpost.com/#/configuration/credentials +.. _API Keys: https://app.sparkpost.com/account/credentials Send a message --------------- +============== Here at SparkPost, our messages are known as transmissions. Let's use the underlying `transmissions API`_ to send a friendly test message: @@ -74,37 +73,126 @@ Here at SparkPost, our messages are known as transmissions. Let's use the underl sp = SparkPost() - response = sp.transmissions.send( - use_sandbox=True, - recipients=['someone@somedomain.com'], - html='
Hello world
', - from_email='test@sparkpostbox.com', - subject='Hello from python-sparkpost' - ) + response = sp.transmissions.post({ + options: { + 'sandbox': True, + 'open_tracking': True, + 'click_tracking': True, + }, + recipients: ['someone@somedomain.com'], + content: { + 'from': 'test@sparkpostbox.com', + 'subject': 'Hello from python-sparkpost', + 'text': 'Hello world!', + 'html': 'Hello world!
', + }, + }) print(response) # outputs {u'total_accepted_recipients': 1, u'id': u'47960765679942446', u'total_rejected_recipients': 0} -.. _transmissions API: https://www.sparkpost.com/api#/reference/transmissions +.. _transmissions API: https://developers.sparkpost.com/api/transmissions.html -Django Integration ------------------- -The SparkPost python library comes with an email backend for Django. Put the following configuration in `settings.py` file. +Custom wrappers +=============== + +The ``sp.transmissions`` object is a wrapper around the library's `base resource`_. We create wrappers to add some syntactic sugar on top of our API. For example, adding ``cc`` and ``bcc`` to a transmission. + +.. _base resource: https://github.com/SparkPost/python-sparkpost/blob/master/sparkpost/base.py + +Using the base resource +======================= + +The base resource can be used to access any of our endpoints through a common interface. Examples for each type of HTTP method follow. + +Get a list of all webhooks (GET): .. code-block:: python - SPARKPOST_API_KEY = 'API_KEY' - EMAIL_BACKEND = 'sparkpost.django.email_backend.SparkPostEmailBackend' + from sparkpost import SparkPost + + sp = SparkPost() + + response = sp.get(uri='webhooks') -Replace *API_KEY* with an actual API key that you've generated in `Get a Key`_ section. Check out the `full documentation`_ on the Django email backend. +Get a specific webhook (GET): -.. _full documentation: https://python-sparkpost.readthedocs.io/en/latest/django/backend.html +.. code-block:: python + + from sparkpost import SparkPost + + sp = SparkPost() + + # or get a specific webhook + response = sp.get( + uri='webhooks/12affc24-f183-11e3-9234-3c15c2c818c2' + ) + +Create a webhook (POST): + +.. code-block:: python + + from sparkpost import SparkPost + + sp = SparkPost() + + response = sp.post( + uri='webhooks', + payload={ + 'name': 'Example webhook', + 'target': 'http://client.example.com/example-webhook', + 'events': [ + 'delivery', + 'injection', + 'open', + 'click' + ] + } + ) + +Update a webhook (PUT): + +.. code-block:: python + + from sparkpost import SparkPost + + sp = SparkPost() + + response = sp.put( + uri='webhooks/12affc24-f183-11e3-9234-3c15c2c818c2', + payload={ + 'target': 'http://client.example.com/different-endpoint' + } + ) + +Delete a webhook (DELETE): + +.. code-block:: python + + from sparkpost import SparkPost + + sp = SparkPost() + + response = sp.delete( + uri='webhooks/12affc24-f183-11e3-9234-3c15c2c818c2' + ) + + +Integrations +============ + +Django Integration +------------------ + +We recommend the `django-anymail`_ package for using SparkPost with Django. + +.. _django-anymail: https://github.com/anymail/django-anymail Using with Google Cloud ----------------------- There are a few simple modifications necessary to enable the use of the underlying ``requests`` library that python-sparkpost uses. First, add the ``requests`` and ``requests-toolbelt`` to your project's ``requirements.txt``: -.. code-block:: +.. code-block:: text requests requests-toolbelt @@ -115,13 +203,13 @@ Then create or update your ``appengine_config.py`` file to include the following import requests import requests_toolbelt.adapters.appengine - + requests_toolbelt.adapters.appengine.monkeypatch() Then deploy your app and you should be able to send using python-sparkpost on Google Cloud. Documentation -------------- +============= * Documentation for `python-sparkpost`_ * `SparkPost API Reference`_ @@ -131,7 +219,7 @@ Documentation Contribute ----------- +========== #. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug. #. Fork `the repository`_ on GitHub and make your changes in a branch on your fork diff --git a/docs/api/recipient_lists.rst b/docs/api/recipient_lists.rst deleted file mode 100644 index d724576..0000000 --- a/docs/api/recipient_lists.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. module:: sparkpost.recipient_lists - -:mod:`sparkpost.recipient_lists` -================================ - -.. autoclass:: RecipientLists - :members: diff --git a/docs/api/suppression_list.rst b/docs/api/suppression_list.rst deleted file mode 100644 index ce86428..0000000 --- a/docs/api/suppression_list.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. module:: sparkpost.suppression_list - -:mod:`sparkpost.suppression_list` -================================= - -.. autoclass:: SuppressionList - :members: diff --git a/docs/api/templates.rst b/docs/api/templates.rst deleted file mode 100644 index cfa8ba8..0000000 --- a/docs/api/templates.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. module:: sparkpost.templates - -:mod:`sparkpost.templates` -============================= - -.. autoclass:: Templates - :members: diff --git a/docs/conf.py b/docs/conf.py index 57dc59f..45bae73 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -19,12 +19,12 @@ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +# sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom @@ -43,7 +43,7 @@ source_suffix = '.rst' # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' @@ -51,26 +51,26 @@ # General information about the project. now = datetime.datetime.now() project = u'python-sparkpost' -copyright = u'2014-{year}, Message Systems'.format(year=now.year) +copyright = u'2014-{year}, SparkPost'.format(year=now.year) # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '1.3' +version = '2.0' # The full version, including alpha/beta/rc tags. -release = '1.3.5' +release = '2.0.dev1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -78,27 +78,27 @@ # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # -- Options for HTML output ---------------------------------------------- @@ -116,26 +116,26 @@ # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # "Hello Rock stars!
', - ) - - -You can also use `EmailMessage` or `EmailMultiAlternatives` class directly. That will give you access to more specific fileds like `template`: - -.. code-block:: python - - email = EmailMessage( - to=[ - { - "address": "to@example.com", - "substitution_data": { - "key": "value" - } - } - ], - from_email='test@from.com' - ) - email.template = 'template-id' - email.send() - -Or cc, bcc, reply to, or attachments fields: - -.. code-block:: python - - from django.core.mail import EmailMultiAlternatives - - email = EmailMultiAlternatives( - subject='hello from sparkpost', - body='Woo hoo! Sent from Django!', - from_email='from@yourdomain.com', - to=['to@example.com'], - cc=['ccone@example.com'], - bcc=['bccone@example.com'], - reply_to=['replyone@example.com'] - ) - - email.attach_alternative('Woo hoo! Sent from Django!
', 'text/html') - email.attach('image.png', img_data, 'image/png') - email.send() - - -Supported version ------------------ -SparkPost will support all versions of Django that are within extended support period. Refer to `Django Supported Versions`_. - -.. _Django Supported Versions: https://www.djangoproject.com/download/#supported-versions - - -Additional documentation ------------------------- - -See our `Using SparkPost with Django`_ in support article. - -.. _Using SparkPost with Django: https://support.sparkpost.com/customer/en/portal/articles/2169630-using-sparkpost-with-django?b_id=7411 diff --git a/docs/index.rst b/docs/index.rst index b19fec8..8ee50be 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,3 +1,4 @@ +=========================== SparkPost Python API client =========================== @@ -5,7 +6,7 @@ The super-mega-official Python package for using the SparkPost API. Installation ------------- +============ Install from PyPI using `pip`_: @@ -16,10 +17,10 @@ Install from PyPI using `pip`_: .. _pip: http://www.pip-installer.org/en/latest/ -Authorization -------------- +Initialization +============== -Go to `API & SMTP`_ in the SparkPost app and create an API key. We recommend using the ``SPARKPOST_API_KEY`` environment variable: +Go to `API Keys`_ in the SparkPost app and create an API key. We recommend using the ``SPARKPOST_API_KEY`` environment variable: .. code-block:: python @@ -33,11 +34,158 @@ Alternatively, you can pass the API key to the SparkPost class: from sparkpost import SparkPost sp = SparkPost('YOUR API KEY') -.. _API & SMTP: https://app.sparkpost.com/configuration/credentials +.. _API Keys: https://app.sparkpost.com/account/credentials + +Send a message +============== + +Here at SparkPost, our messages are known as transmissions. Let's use the underlying `transmissions API`_ to send a friendly test message: + +.. code-block:: python + + from sparkpost import SparkPost + + sp = SparkPost() + + response = sp.transmissions.post({ + options: { + 'sandbox': True, + 'open_tracking': True, + 'click_tracking': True, + }, + recipients: ['someone@somedomain.com'], + content: { + 'from': 'test@sparkpostbox.com', + 'subject': 'Hello from python-sparkpost', + 'text': 'Hello world!', + 'html': 'Hello world!
', + }, + }) + + print(response) + # outputs {u'total_accepted_recipients': 1, u'id': u'47960765679942446', u'total_rejected_recipients': 0} + +.. _transmissions API: https://developers.sparkpost.com/api/transmissions.html + +Custom wrappers +=============== + +The ``sp.transmissions`` object is a wrapper around the library's `base resource`_. We create wrappers to add some syntactic sugar on top of our API. For example, adding ``cc`` and ``bcc`` to a transmission. + +.. _base resource: https://github.com/SparkPost/python-sparkpost/blob/master/sparkpost/base.py + +Using the base resource +======================= + +The base resource can be used to access any of our endpoints through a common interface. Examples for each type of HTTP method follow. + +Get a list of all webhooks (GET): + +.. code-block:: python + + from sparkpost import SparkPost + + sp = SparkPost() + + response = sp.get(uri='webhooks') + +Get a specific webhook (GET): + +.. code-block:: python + + from sparkpost import SparkPost + + sp = SparkPost() + + # or get a specific webhook + response = sp.get( + uri='webhooks/12affc24-f183-11e3-9234-3c15c2c818c2' + ) + +Create a webhook (POST): + +.. code-block:: python + + from sparkpost import SparkPost + + sp = SparkPost() + + response = sp.post( + uri='webhooks', + payload={ + 'name': 'Example webhook', + 'target': 'http://client.example.com/example-webhook', + 'events': [ + 'delivery', + 'injection', + 'open', + 'click' + ] + } + ) + +Update a webhook (PUT): + +.. code-block:: python + + from sparkpost import SparkPost + + sp = SparkPost() + + response = sp.put( + uri='webhooks/12affc24-f183-11e3-9234-3c15c2c818c2', + payload={ + 'target': 'http://client.example.com/different-endpoint' + } + ) + +Delete a webhook (DELETE): + +.. code-block:: python + + from sparkpost import SparkPost + + sp = SparkPost() + + response = sp.delete( + uri='webhooks/12affc24-f183-11e3-9234-3c15c2c818c2' + ) + + +Integrations +============ + +Django Integration +------------------ + +We recommend the `django-anymail`_ package for using SparkPost with Django. + +.. _django-anymail: https://github.com/anymail/django-anymail + +Using with Google Cloud +----------------------- +There are a few simple modifications necessary to enable the use of the underlying ``requests`` library that python-sparkpost uses. First, add the ``requests`` and ``requests-toolbelt`` to your project's ``requirements.txt``: + +.. code-block:: text + + requests + requests-toolbelt + +Then create or update your ``appengine_config.py`` file to include the following: + +.. code-block:: python + + import requests + import requests_toolbelt.adapters.appengine + + requests_toolbelt.adapters.appengine.monkeypatch() + +Then deploy your app and you should be able to send using python-sparkpost on Google Cloud. + Resources ---------- +========= The following resources are available in python-sparkpost: @@ -49,7 +197,7 @@ The following resources are available in python-sparkpost: API reference -------------- +============= Auto-generated API reference for python-sparkpost: @@ -58,17 +206,6 @@ Auto-generated API reference for python-sparkpost: api -Using in Django ---------------- - -Configure Django to use SparkPost email backend - -.. toctree:: - :maxdepth: 2 - - django/backend - - Additional documentation ------------------------ @@ -78,7 +215,7 @@ The underlying SparkPost API is documented at the official `SparkPost API Refere Contribute ----------- +========== #. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug. #. Fork `the repository`_ on GitHub and make your changes in a branch on your fork diff --git a/docs/resources/metrics.rst b/docs/resources/metrics.rst deleted file mode 100644 index eaef00c..0000000 --- a/docs/resources/metrics.rst +++ /dev/null @@ -1,34 +0,0 @@ -Metrics -======= - -Retrieve a list of campaigns ----------------------------- - -.. code-block:: python - - from sparkpost import SparkPost - - sp = SparkPost() - - sp.metrics.campaigns.list() - - -Retrieve a list of domains --------------------------- - -.. code-block:: python - - from sparkpost import SparkPost - - sp = SparkPost() - - sp.metrics.domains.list() - - -Additional documentation ------------------------- - -See the `SparkPost Metrics API Reference`_. - -.. _SparkPost Metrics API Reference: https://www.sparkpost.com/api#/reference/metrics - diff --git a/docs/resources/recipient_lists.rst b/docs/resources/recipient_lists.rst deleted file mode 100644 index 5ef507e..0000000 --- a/docs/resources/recipient_lists.rst +++ /dev/null @@ -1,83 +0,0 @@ -Recipient Lists -=============== - -Let's use the underlying `recipient_lists API`_ to create a recipient list: - -.. code-block:: python - - from sparkpost import SparkPost - - sp = SparkPost() - - response = sp.recipient_lists.create( - id='UNIQUE_TEST_ID', - name='Test Recipient list', - recipients=[ - { - 'address': { - 'email': 'test1@test.com' - } - }, - { - 'address': { - 'email': 'test2@test.com' - } - }, - { - 'address': { - 'email': 'test3@test.com' - } - } - ] - ) - - print(response) - # outputs {u'total_accepted_recipients': 3, u'id': u'UNIQUE_TEST_ID', u'total_rejected_recipients': 0, u'name':'Test Recipient list'} - -.. _recipient_lists API: https://www.sparkpost.com/api#/reference/recipient-lists - - -Retrieve a recipient list -------------------------- - -.. code-block:: python - - from sparkpost import SparkPost - - sp = SparkPost() - - sp.recipient_lists.get('my-list-id') - - -List all recipient lists ------------------------- - -.. code-block:: python - - from sparkpost import SparkPost - - sp = SparkPost() - - sp.recipient_lists.list() - - -API reference -------------- - -:doc:`/api/recipient_lists` - - -Further examples ----------------- - -See the `python-sparkpost recipient_lists examples`_. - -.. _python-sparkpost recipient_lists examples: https://github.com/SparkPost/python-sparkpost/tree/master/examples/recipient_lists - - -Additional documentation ------------------------- - -See the `SparkPost Recipient Lists API Reference`_. - -.. _SparkPost Recipient Lists API Reference: https://www.sparkpost.com/api#/reference/recipient_lists diff --git a/docs/resources/suppression_list.rst b/docs/resources/suppression_list.rst deleted file mode 100644 index 412eb3b..0000000 --- a/docs/resources/suppression_list.rst +++ /dev/null @@ -1,68 +0,0 @@ -Suppression List -================ - -Let's use the underlying `suppression_list API`_ to create a suppression entry: - -.. code-block:: python - - from sparkpost import SparkPost - - sp = SparkPost() - - response = sp.suppression_list.create({ - "email": "test@test.com" - "transactional": False, - "non_transactional": True, - "description": "User requested to not receive any non-transactional emails." - }) - - print(response) - # outputs {u'message': u'Recipient successfully created'} - -.. _suppression_list API: https://www.sparkpost.com/api#/reference/suppression-list - - -Get a suppression entry ------------------------ - -.. code-block:: python - - from sparkpost import SparkPost - - sp = SparkPost() - - sp.suppression_list.get('test@test.com') - - -List suppression entries ------------------------- - -.. code-block:: python - - from sparkpost import SparkPost - - sp = SparkPost() - - sp.suppression_list.list() - - -API reference -------------- - -:doc:`/api/suppression_list` - - -Further examples ----------------- - -See the `python-sparkpost suppression_list examples`_. - -.. _python-sparkpost suppression_list examples: https://github.com/SparkPost/python-sparkpost/tree/master/examples/suppression_list - - -Additional documentation ------------------------- - -See the `SparkPost Suppression List API Reference`_. - -.. _SparkPost Suppression List API Reference: https://www.sparkpost.com/api#/reference/suppression-list diff --git a/docs/resources/templates.rst b/docs/resources/templates.rst deleted file mode 100644 index 7202c78..0000000 --- a/docs/resources/templates.rst +++ /dev/null @@ -1,69 +0,0 @@ -Templates -============= - -Let's use the underlying `templates API`_ to create a template: - -.. code-block:: python - - from sparkpost import SparkPost - - sp = SparkPost() - - response = sp.templates.create( - id='TEST_ID', - name='Test Template', - from_email='test@test.com', - subject='Test email template!', - html='This is a test email template!' - ) - - print(response) - # outputs {u'id': u'TEST_ID'} - -.. _templates API: https://www.sparkpost.com/api#/reference/templates - - -Retrieve a template ------------------------ - -.. code-block:: python - - from sparkpost import SparkPost - - sp = SparkPost() - - sp.templates.get('my-template-id') - - -List all templates ----------------------- - -.. code-block:: python - - from sparkpost import SparkPost - - sp = SparkPost() - - sp.templates.list() - - -API reference -------------- - -:doc:`/api/templates` - - -Further examples ----------------- - -See the `python-sparkpost templates examples`_. - -.. _python-sparkpost templates examples: https://github.com/SparkPost/python-sparkpost/tree/master/examples/templates - - -Additional documentation ------------------------- - -See the `SparkPost Templates API Reference`_. - -.. _SparkPost Templates API Reference: https://www.sparkpost.com/api#/reference/templates diff --git a/docs/resources/transmissions.rst b/docs/resources/transmissions.rst index ca91063..9b9724d 100644 --- a/docs/resources/transmissions.rst +++ b/docs/resources/transmissions.rst @@ -9,19 +9,25 @@ Here at SparkPost, our messages are known as transmissions. Let's use the underl sp = SparkPost() - response = sp.transmissions.send( - recipients=['someone@somedomain.com'], - html='Hello world
', - from_email='test@sparkpostbox.com', - subject='Hello from python-sparkpost', - track_opens=True, - track_clicks=True - ) + response = sp.transmissions.post({ + options: { + 'sandbox': True, + 'open_tracking': True, + 'click_tracking': True, + }, + recipients: ['someone@somedomain.com'], + content: { + 'from': 'test@sparkpostbox.com', + 'subject': 'Hello from python-sparkpost', + 'text': 'Hello world!', + 'html': 'Hello world!
', + }, + }) print(response) # outputs {u'total_accepted_recipients': 1, u'id': u'47960765679942446', u'total_rejected_recipients': 0} -.. _transmissions API: https://www.sparkpost.com/api#/reference/transmissions +.. _transmissions API: https://developers.sparkpost.com/api/transmissions.html Send a transmission @@ -36,15 +42,20 @@ Using inline templates and/or recipients sp = SparkPost() - sp.transmissions.send( - recipients=['someone@somedomain.com'], - text="Hello world", - html='Hello world
', - from_email='test@sparkpostbox.com', - subject='Hello from python-sparkpost', - track_opens=True, - track_clicks=True - ) + response = sp.transmissions.post({ + options: { + 'sandbox': True, + 'open_tracking': True, + 'click_tracking': True, + }, + recipients: ['someone@somedomain.com'], + content: { + 'from': 'test@sparkpostbox.com', + 'subject': 'Hello from python-sparkpost', + 'text': 'Hello world!', + 'html': 'Hello world!
', + }, + }) Including cc, bcc @@ -56,17 +67,22 @@ Including cc, bcc sp = SparkPost() - sp.transmissions.send( - recipients=['someone@somedomain.com'], - cc=['carboncopy@somedomain.com'], - bcc=['blindcarboncopy@somedomain.com'], - text="Hello world", - html='Hello world
', - from_email='test@sparkpostbox.com', - subject='Hello from python-sparkpost', - track_opens=True, - track_clicks=True - ) + response = sp.transmissions.post({ + options: { + 'sandbox': True, + 'open_tracking': True, + 'click_tracking': True, + }, + recipients: ['someone@somedomain.com'], + cc: ['carboncopy@somedomain.com'], + bcc: ['blindcarboncopy@somedomain.com'], + content: { + 'from': 'test@sparkpostbox.com', + 'subject': 'Hello from python-sparkpost', + 'text': 'Hello world!', + 'html': 'Hello world!
', + }, + }) Sending an attachment @@ -78,22 +94,27 @@ Sending an attachment sp = SparkPost() - sp.transmissions.send( - recipients=['someone@somedomain.com'], - text="Hello world", - html='Hello world
', - from_email='test@sparkpostbox.com', - subject='Hello from python-sparkpost', - track_opens=True, - track_clicks=True, - attachments=[ - { - "name": "test.txt", - "type": "text/plain", - "filename": "/home/sparkpost/a-file.txt" - } + response = sp.transmissions.post({ + options: { + 'sandbox': True, + 'open_tracking': True, + 'click_tracking': True, + }, + recipients: ['someone@somedomain.com'], + content: { + 'from': 'test@sparkpostbox.com', + 'subject': 'Hello from python-sparkpost', + 'text': 'Hello world!', + 'html': 'Hello world!
', + 'attachments': [ + { + 'name': 'test.txt', + 'type': 'text/plain', + 'filename': '/home/sparkpost/a-file.txt' + } ] - ) + }, + }) Using substitution data @@ -109,18 +130,23 @@ Using substitution data sp = SparkPost() - sp.transmissions.send( - recipients=['someone@somedomain.com'], - text="Hello {{name}}", - html='Hello {{name}}
', - from_email='test@sparkpostbox.com', - subject='Hello from python-sparkpost', - track_opens=True, - track_clicks=True, - substitution_data={ - 'name': 'Sparky' - } - ) + response = sp.transmissions.post({ + options: { + 'sandbox': True, + 'open_tracking': True, + 'click_tracking': True, + }, + recipients: ['someone@somedomain.com'], + content: { + 'from': 'test@sparkpostbox.com', + 'subject': 'Hello from python-sparkpost', + 'text': 'Hello {{name}}!', + 'html': 'Hello {{name}}!
', + }, + substitution_data: { + 'name': 'Sparky' + }, + }) Using a stored template @@ -132,10 +158,10 @@ Using a stored template sp = SparkPost() - sp.transmissions.send( - recipients=['someone@somedomain.com'], - template='my-template-id' - ) + response = sp.transmissions.post({ + recipients: ['someone@somedomain.com'], + template_id: 'my-template-id', + }) Using a stored recipient list @@ -147,10 +173,10 @@ Using a stored recipient list sp = SparkPost() - sp.transmissions.send( - recipient_list='my-recipient-list', - template='my-template-id' - ) + response = sp.transmissions.post({ + recipients: 'my-recipient-list', + template_id: 'my-template-id', + }) Retrieve a transmission @@ -174,7 +200,7 @@ List all transmissions sp = SparkPost() - sp.transmissions.list() + sp.transmissions.get() API reference @@ -196,5 +222,5 @@ Additional documentation See the `SparkPost Transmissions API Reference`_. -.. _SparkPost Transmissions API Reference: https://www.sparkpost.com/api#/reference/transmissions +.. _SparkPost Transmissions API Reference: https://developers.sparkpost.com/api/transmissions.html