`__ is a full example):
+
+.. code:: python
+
+ import os
+ from sendgrid import SendGridAPIClient
+
+ message = {
+ 'personalizations': [
+ {
+ 'to': [
+ {
+ 'email': 'test@example.com'
+ }
+ ],
+ 'subject': 'Sending with Twilio SendGrid is Fun'
+ }
+ ],
+ 'from': {
+ 'email': 'test@example.com'
+ },
+ 'content': [
+ {
+ 'type': 'text/plain',
+ 'value': 'and easy to do anywhere, even with Python'
+ }
+ ]
+ }
+ try:
+ sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
+ response = sg.send(message)
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+ except Exception as e:
+ print(str(e))
+
+General v3 Web API Usage (With `Fluent Interface`_)
+---------------------------------------------------
+
+.. code:: python
+
+ import os
+ from sendgrid import SendGridAPIClient
+
+ sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
+ response = sg.client.suppression.bounces.get()
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+
+General v3 Web API Usage (Without `Fluent Interface`_)
+------------------------------------------------------
+
+.. code:: python
+
+ import os
+ from sendgrid import SendGridAPIClient
+
+ sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
+ response = sg.client._('suppression/bounces').get()
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+
+Processing Inbound Email
+========================
+
+Please see `our helper`_ for utilizing our Inbound Parse webhook.
+
+Usage
+=====
+
+- `Twilio SendGrid Documentation`_
+- `Library Usage Documentation`_
+- `Example Code`_
+- `How-to: Migration from v2 to v3`_
+- `v3 Web API Mail Send Helper`_ - build a request object payload for a v3 /mail/send API call.
+- `Processing Inbound Email`_
+
+Use Cases
+=========
+
+`Examples of common API use cases`_, such as how to send an email with a transactional template or add an attachment or send an SMS message.
+
+Announcements
+=============
+
+All updates to this library are documented in our `CHANGELOG`_ and `releases`_.
+
+How to Contribute
+=================
+
+We encourage contribution to our libraries (you might even score some nifty swag), please see our `CONTRIBUTING`_ guide for details.
+
+Quick links:
+
+- `Feature Request`_
+- `Bug Reports`_
+- `Improvements to the Codebase`_
+- `Review Pull Requests`_
+
+Troubleshooting
+===============
+
+Please see our `troubleshooting guide`_ for common library issues.
+
+About
+=====
+
+**sendgrid-python** is maintained and funded by Twilio SendGrid, Inc.
+The names and logos for **sendgrid-python** are trademarks of Twilio SendGrid, Inc.
+
+License
+=======
+
+`The MIT License (MIT)`_
+
+.. _Twilio: https://github.com/sendgrid/sendgrid-python/blob/HEAD/use_cases/sms.md
+.. _release notes: https://github.com/sendgrid/sendgrid-python/releases/tag/v6.0.0
+.. _Web API v3: https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html
+.. _v3 /mail/send: https://sendgrid.com/blog/introducing-v3mailsend-sendgrids-new-mail-endpoint
+.. _issues: https://github.com/sendgrid/sendgrid-python/issues
+.. _pull requests: https://github.com/sendgrid/sendgrid-python/blob/HEAD/CONTRIBUTING.md
+.. _free level: https://sendgrid.com/free?source=sendgrid-python
+.. _Twilio account: https://www.twilio.com/try-twilio?source=sendgrid-python
+.. _SENDGRID_API_KEY: https://app.sendgrid.com/settings/api_keys
+.. _Python-HTTP-Client: https://github.com/sendgrid/python-http-client
+.. _Cryptography: https://github.com/pyca/cryptography
+.. _/mail/send Helper: https://github.com/sendgrid/sendgrid-python/tree/HEAD/sendgrid/helpers/mail
+.. _personalization object: https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html
+.. _Fluent Interface: https://sendgrid.com/blog/using-python-to-implement-a-fluent-interface-to-any-rest-api/
+.. _our helper: https://github.com/sendgrid/sendgrid-python/tree/HEAD/sendgrid/helpers/inbound
+.. _Twilio SendGrid Documentation: https://sendgrid.com/docs/API_Reference/index.html
+.. _Library Usage Documentation: https://github.com/sendgrid/sendgrid-python/tree/HEAD/USAGE.md
+.. _Example Code: https://github.com/sendgrid/sendgrid-python/tree/HEAD/examples
+.. _`How-to: Migration from v2 to v3`: https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html
+.. _v3 Web API Mail Send Helper: https://github.com/sendgrid/sendgrid-python/tree/HEAD/sendgrid/helpers/mail
+.. _Processing Inbound Email: https://github.com/sendgrid/sendgrid-python/tree/HEAD/sendgrid/helpers/inbound
+.. _Examples of common API use cases: https://github.com/sendgrid/sendgrid-python/blob/HEAD/use_cases/README.md
+.. _breaking changes: https://github.com/sendgrid/sendgrid-python/issues/217
+.. _CHANGELOG: https://github.com/sendgrid/sendgrid-python/blob/HEAD/CHANGELOG.md
+.. _releases: https://github.com/sendgrid/sendgrid-python/releases
+.. _CONTRIBUTING: https://github.com/sendgrid/sendgrid-python/blob/HEAD/CONTRIBUTING.md
+.. _Feature Request: https://github.com/sendgrid/sendgrid-python/blob/HEAD/CONTRIBUTING.md#feature-request
+.. _Bug Reports: https://github.com/sendgrid/sendgrid-python/blob/HEAD/CONTRIBUTING.md#submit-a-bug-report
+.. _Improvements to the Codebase: https://github.com/sendgrid/sendgrid-python/blob/HEAD/CONTRIBUTING.md#improvements-to-the-codebase
+.. _Review Pull Requests: https://github.com/sendgrid/sendgrid-python/blob/HEAD/CONTRIBUTING.md#code-reviews
+.. _troubleshooting guide: https://github.com/sendgrid/sendgrid-python/blob/HEAD/TROUBLESHOOTING.md
+.. _The MIT License (MIT): https://github.com/sendgrid/sendgrid-python/blob/HEAD/LICENSE
+
+.. |Tests Badge| image:: https://github.com/sendgrid/sendgrid-python/actions/workflows/test.yml/badge.svg
+ :target: https://github.com/sendgrid/sendgrid-python/actions/workflows/test.yml
+.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/sendgrid.svg
+ :target: https://pypi.org/project/sendgrid/
+.. |PyPI Version| image:: https://img.shields.io/pypi/v/sendgrid.svg
+ :target: https://pypi.org/project/sendgrid/
+.. |Docker Badge| image:: https://img.shields.io/docker/automated/sendgrid/sendgrid-python.svg
+ :target: https://hub.docker.com/r/sendgrid/sendgrid-python/
+.. |MIT licensed| image:: https://img.shields.io/badge/license-MIT-blue.svg
+ :target: ./LICENSE
+.. |Twitter Follow| image:: https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow
+ :target: https://twitter.com/sendgrid
+.. |GitHub contributors| image:: https://img.shields.io/github/contributors/sendgrid/sendgrid-python.svg
+ :target: https://github.com/sendgrid/sendgrid-python/graphs/contributors
+.. |Open Source Helpers| image:: https://www.codetriage.com/sendgrid/sendgrid-python/badges/users.svg
+ :target: https://www.codetriage.com/sendgrid/sendgrid-python
diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md
index c22913108..0a7f54c69 100644
--- a/TROUBLESHOOTING.md
+++ b/TROUBLESHOOTING.md
@@ -1,85 +1,89 @@
-If you have a non-library SendGrid issue, please contact our [support team](https://support.sendgrid.com).
+If you have an issue logging into your Twilio SendGrid account, please read this [document](https://sendgrid.com/docs/ui/account-and-settings/troubleshooting-login/). For any questions regarding login issues, please contact our [support team](https://support.sendgrid.com).
+
+If you have a non-library Twilio SendGrid issue, please contact our [support team](https://support.sendgrid.com).
If you can't find a solution below, please open an [issue](https://github.com/sendgrid/sendgrid-python/issues).
## Table of Contents
+* [Environment Variables and Your Twilio SendGrid API Key](#environment)
+* [Error Messages](#error)
* [Migrating from v2 to v3](#migrating)
* [Continue Using v2](#v2)
* [Testing v3 /mail/send Calls Directly](#testing)
-* [Error Messages](#error)
-* [Versions](#versions)
-* [Environment Variables and Your SendGrid API Key](#environment)
* [Using the Package Manager](#package-manager)
+* [Version Convention](#versions)
+* [Viewing the Request Body](#request-body)
+* [Error Handling](#error-handling)
+* [Verifying Event Webhooks](#signed-webhooks)
-
-## Migrating from v2 to v3
+
+## Environment Variables and Your Twilio SendGrid API Key
-Please review [our guide](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html) on how to migrate from v2 to v3.
+All of our examples assume you are using [environment variables](https://github.com/sendgrid/sendgrid-python#setup-environment-variables) to hold your Twilio SendGrid API key.
-
-## Continue Using v2
-
-[Here](https://github.com/sendgrid/sendgrid-python/tree/0942f9de2d5ba5fedb65a23940ebe1005a21a6c7) is the last working version with v2 support.
+If you choose to add your Twilio SendGrid API key directly (not recommended):
-Using pip:
+`api_key=os.environ.get('SENDGRID_API_KEY')`
-```bash
-pip uninstall sendgrid
-pip install sendgrid=1.6.22
-```
-
-Download:
-
-Click the "Clone or download" green button in [GitHub](https://github.com/sendgrid/sendgrid-python/tree/0942f9de2d5ba5fedb65a23940ebe1005a21a6c7) and choose download.
+becomes
-
-## Testing v3 /mail/send Calls Directly
+`api_key='SENDGRID_API_KEY'`
-[Here](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/curl_examples.html) are some cURL examples for common use cases.
+In the first case, SENDGRID_API_KEY is in reference to the name of the environment variable, while the second case references the actual Twilio SendGrid API Key.
## Error Messages
+HTTP exceptions are defined in the [`python_http_client` package](https://github.com/sendgrid/python-http-client/blob/HEAD/python_http_client/exceptions.py).
+
To read the error message returned by SendGrid's API in Python 2.X:
```python
-import urllib2
+from python_http_client.exceptions import HTTPError
try:
response = sg.client.mail.send.post(request_body=mail.get())
-except urllib2.HTTPError as e:
- print e.read()
+except HTTPError as e:
+ print e.to_dict
```
-To read the error message returned by SendGrid's API in Python 3.X:
+To read the error message returned by Twilio SendGrid's API in Python 3.X:
```python
-import urllib
+from python_http_client.exceptions import HTTPError
+
try:
response = sg.client.mail.send.post(request_body=mail.get())
-except urllib.error.HTTPError as e:
- print e.read()
+except HTTPError as e:
+ print(e.to_dict)
```
-
-## Versions
-We follow the MAJOR.MINOR.PATCH versioning scheme as described by [SemVer.org](http://semver.org). Therefore, we recommend that you always pin (or vendor) the particular version you are working with to your code and never auto-update to the latest version. Especially when there is a MAJOR point release, since that is guarenteed to be a breaking change. Changes are documented in the [CHANGELOG](https://github.com/sendgrid/sendgrid-python/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-python/releases) section.
+
+## Migrating from v2 to v3
-
-## Environment Variables and Your SendGrid API Key
+Please review [our guide](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/how_to_migrate_from_v2_to_v3_mail_send.html) on how to migrate from v2 to v3.
-All of our examples assume you are using [environment variables](https://github.com/sendgrid/sendgrid-python#setup-environment-variables) to hold your SendGrid API key.
+
+## Continue Using v2
-If you choose to add your SendGrid API key directly (not recommended):
+[Here](https://github.com/sendgrid/sendgrid-python/tree/0942f9de2d5ba5fedb65a23940ebe1005a21a6c7) is the last working version with v2 support.
-`apikey=os.environ.get('SENDGRID_API_KEY')`
+Using pip:
-becomes
+```bash
+pip uninstall sendgrid
+pip install sendgrid==1.6.22
+```
+
+Download:
-`apikey='SENDGRID_API_KEY'`
+Click the "Clone or download" green button in [GitHub](https://github.com/sendgrid/sendgrid-python/tree/0942f9de2d5ba5fedb65a23940ebe1005a21a6c7) and choose download.
+
+
+## Testing v3 /mail/send Calls Directly
-In the first case SENDGRID_API_KEY is in reference to the name of the environment variable, while the second case references the actual SendGrid API Key.
+[Here](https://sendgrid.com/docs/for-developers/sending-email/curl-examples) are some cURL examples for common use cases.
## Using the Package Manager
@@ -90,6 +94,38 @@ In most cases we recommend you download the latest version of the library, but i
`pip install sendgrid==X.X.X`
-If you are usring a [requirements file](https://pip.readthedocs.io/en/1.1/requirements.html), please use:
+If you are using a [requirements file](https://pip.readthedocs.io/en/1.1/requirements.html), please use:
`sendgrid==X.X.X`
+
+
+## Versioning Convention
+
+We follow the MAJOR.MINOR.PATCH versioning scheme as described by [SemVer.org](http://semver.org). Therefore, we recommend that you always pin (or vendor) the particular version you are working with to your code and never auto-update to the latest version. Especially when there is a MAJOR point release, since that is guaranteed to be a breaking change. Changes are documented in the [CHANGELOG](CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-python/releases) section.
+
+
+## Viewing the Request Body
+
+When debugging or testing, it may be useful to examine the raw request body to compare against the [documented format](https://sendgrid.com/docs/API_Reference/api_v3.html).
+
+You can do this right before you call `response = sg.client.mail.send.post(request_body=mail.get())` like so:
+
+```python
+ print(json.dumps(message.get(), sort_keys=True, indent=4))
+```
+
+
+# Error Handling
+
+Please review [our use_cases](use_cases/README.md) for examples of error handling.
+
+
+## Signed Webhook Verification
+
+Twilio SendGrid's Event Webhook will notify a URL via HTTP POST with information about events that occur as your mail is processed. [This](https://docs.sendgrid.com/for-developers/tracking-events/getting-started-event-webhook-security-features) article covers all you need to know to secure the Event Webhook, allowing you to verify that incoming requests originate from Twilio SendGrid. The sendgrid-python library can help you verify these Signed Event Webhooks.
+
+You can find the usage example [here](examples/helpers/eventwebhook/eventwebhook_example.py) and the tests [here](test/test_eventwebhook.py).
+If you are still having trouble getting the validation to work, follow the following instructions:
+- Be sure to use the *raw* payload for validation
+- Be sure to include a trailing carriage return and newline in your payload
+- In case of multi-event webhooks, make sure you include the trailing newline and carriage return after *each* event
diff --git a/USAGE.md b/USAGE.md
index 013a48e92..978b675ab 100644
--- a/USAGE.md
+++ b/USAGE.md
@@ -2,19 +2,21 @@ This documentation is based on our [OAI specification](https://github.com/sendgr
# INITIALIZATION
+Make sure your API key has the [required permissions](https://sendgrid.com/docs/ui/account-and-settings/api-keys/).
+
```python
-import sendgrid
+from sendgrid import SendGridAPIClient
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
```
# Table of Contents
-* [ACCESS SETTINGS](#access_settings)
+* [ACCESS SETTINGS](#access-settings)
* [ALERTS](#alerts)
-* [API KEYS](#api_keys)
+* [API KEYS](#api-keys)
* [ASM](#asm)
* [BROWSERS](#browsers)
* [CAMPAIGNS](#campaigns)
@@ -25,21 +27,20 @@ sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
* [GEO](#geo)
* [IPS](#ips)
* [MAIL](#mail)
-* [MAIL SETTINGS](#mail_settings)
-* [MAILBOX PROVIDERS](#mailbox_providers)
-* [PARTNER SETTINGS](#partner_settings)
+* [MAIL SETTINGS](#mail-settings)
+* [MAILBOX PROVIDERS](#mailbox-providers)
+* [PARTNER SETTINGS](#partner-settings)
* [SCOPES](#scopes)
* [SENDERS](#senders)
+* [SENDER AUTHENTICATION](#sender-authentication)
* [STATS](#stats)
* [SUBUSERS](#subusers)
* [SUPPRESSION](#suppression)
* [TEMPLATES](#templates)
-* [TRACKING SETTINGS](#tracking_settings)
+* [TRACKING SETTINGS](#tracking-settings)
* [USER](#user)
-* [WHITELABEL](#whitelabel)
-
-
+
# ACCESS SETTINGS
## Retrieve all recent access attempts
@@ -56,9 +57,9 @@ For more information, please see our [User Guide](http://sendgrid.com/docs/User_
```python
params = {'limit': 1}
response = sg.client.access_settings.activity.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Add one or more IPs to the whitelist
@@ -88,9 +89,9 @@ data = {
]
}
response = sg.client.access_settings.whitelist.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve a list of currently whitelisted IPs
@@ -105,9 +106,9 @@ For more information, please see our [User Guide](http://sendgrid.com/docs/User_
```python
response = sg.client.access_settings.whitelist.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Remove one or more IPs from the whitelist
@@ -131,13 +132,13 @@ data = {
]
}
response = sg.client.access_settings.whitelist.delete(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve a specific whitelisted IP
-**This endpoint allows you to retreive a specific IP address that has been whitelisted.**
+**This endpoint allows you to retrieve a specific IP address that has been whitelisted.**
You must include the ID for the specific IP address you want to retrieve in your call.
@@ -151,9 +152,9 @@ For more information, please see our [User Guide](http://sendgrid.com/docs/User_
```python
rule_id = "test_url_param"
response = sg.client.access_settings.whitelist._(rule_id).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Remove a specific IP from the whitelist
@@ -171,9 +172,9 @@ For more information, please see our [User Guide](http://sendgrid.com/docs/User_
```python
rule_id = "test_url_param"
response = sg.client.access_settings.whitelist._(rule_id).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# ALERTS
@@ -198,13 +199,13 @@ data = {
"type": "stats_notification"
}
response = sg.client.alerts.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all alerts
-**This endpoint allows you to retieve all of your alerts.**
+**This endpoint allows you to retrieve all of your alerts.**
Alerts allow you to specify an email address to receive notifications regarding your email usage or statistics.
* Usage alerts allow you to set the threshold at which an alert will be sent.
@@ -217,9 +218,9 @@ For more information about alerts, please see our [User Guide](https://sendgrid.
```python
response = sg.client.alerts.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update an alert
@@ -240,9 +241,9 @@ data = {
}
alert_id = "test_url_param"
response = sg.client.alerts._(alert_id).patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve a specific alert
@@ -260,9 +261,9 @@ For more information about alerts, please see our [User Guide](https://sendgrid.
```python
alert_id = "test_url_param"
response = sg.client.alerts._(alert_id).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete an alert
@@ -280,18 +281,18 @@ For more information about alerts, please see our [User Guide](https://sendgrid.
```python
alert_id = "test_url_param"
response = sg.client.alerts._(alert_id).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-
+
# API KEYS
## Create API keys
-**This enpoint allows you to create a new random API Key for the user.**
+**This endpoint allows you to create a new random API Key for the user.**
-A JSON request body containing a "name" property is required. If number of maximum keys is reached, HTTP 403 will be returned.
+A JSON request body containing a "name" property is required. If the number of maximum keys is reached, HTTP 403 will be returned.
There is a limit of 100 API Keys on your account.
@@ -313,15 +314,15 @@ data = {
]
}
response = sg.client.api_keys.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all API Keys belonging to the authenticated user
**This endpoint allows you to retrieve all API Keys that belong to the authenticated user.**
-The API Keys feature allows customers to be able to generate an API Key credential which can be used for authentication with the SendGrid v3 Web API or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
+The API Keys feature allows customers to generate an API Key credential which can be used for authentication with the SendGrid v3 Web API or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
### GET /api_keys
@@ -329,16 +330,16 @@ The API Keys feature allows customers to be able to generate an API Key credenti
```python
params = {'limit': 1}
response = sg.client.api_keys.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update the name & scopes of an API Key
**This endpoint allows you to update the name and scopes of a given API key.**
A JSON request body with a "name" property is required.
-Most provide the list of all the scopes an api key should have.
+Most provide the list of all the scopes an API key should have.
The API Keys feature allows customers to be able to generate an API Key credential which can be used for authentication with the SendGrid v3 Web API or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
@@ -356,9 +357,9 @@ data = {
}
api_key_id = "test_url_param"
response = sg.client.api_keys._(api_key_id).put(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update API keys
@@ -366,7 +367,7 @@ print response.headers
A JSON request body with a "name" property is required.
-The API Keys feature allows customers to be able to generate an API Key credential which can be used for authentication with the SendGrid v3 Web API or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
+The API Keys feature allows customers to be able to generate an API Key credential which can be used for authentication with the Twilio SendGrid v3 Web API or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
## URI Parameters
@@ -383,13 +384,13 @@ data = {
}
api_key_id = "test_url_param"
response = sg.client.api_keys._(api_key_id).patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve an existing API Key
-**This endpoint allows you to retrieve a single api key.**
+**This endpoint allows you to retrieve a single API key.**
If the API Key ID does not exist an HTTP 404 will be returned.
@@ -399,17 +400,17 @@ If the API Key ID does not exist an HTTP 404 will be returned.
```python
api_key_id = "test_url_param"
response = sg.client.api_keys._(api_key_id).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete API keys
-**This endpoint allows you to revoke an existing API Key**
+**This endpoint allows you to revoke an existing API Key.**
-Authentications using this API Key will fail after this request is made, with some small propogation delay.If the API Key ID does not exist an HTTP 404 will be returned.
+Authentications using this API Key will fail after this request is made, with some small propagation delay. If the API Key ID does not exist an HTTP 404 will be returned.
-The API Keys feature allows customers to be able to generate an API Key credential which can be used for authentication with the SendGrid v3 Web API or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
+The API Keys feature allows customers to be able to generate an API Key credential which can be used for authentication with the Twilio SendGrid v3 Web API or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
## URI Parameters
@@ -423,9 +424,9 @@ The API Keys feature allows customers to be able to generate an API Key credenti
```python
api_key_id = "test_url_param"
response = sg.client.api_keys._(api_key_id).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# ASM
@@ -434,9 +435,9 @@ print response.headers
**This endpoint allows you to create a new suppression group.**
-Suppression groups, or unsubscribe groups, are specific types or categories of email that you would like your recipients to be able to unsubscribe from. For example: Daily Newsletters, Invoices, System Alerts.
+Suppression groups, or unsubscribe groups, are specific types or categories of emails that you would like your recipients to be able to unsubscribe from. For example: Daily Newsletters, Invoices, System Alerts.
-The **name** and **description** of the unsubscribe group will be visible by recipients when they are managing their subscriptions.
+The **name** and **description** of the unsubscribe group will be visible to recipients when they are managing their subscriptions.
Each user can create up to 25 different suppression groups.
@@ -450,9 +451,9 @@ data = {
"name": "Product Suggestions"
}
response = sg.client.asm.groups.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve information about multiple suppression groups
@@ -462,7 +463,7 @@ This endpoint will return information for each group ID that you include in your
Suppressions are a list of email addresses that will not receive content sent under a given [group](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html).
-Suppression groups, or [unsubscribe groups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html), allow you to label a category of content that you regularly send. This gives your recipients the ability to opt out of a specific set of your email. For example, you might define a group for your transactional email, and one for your marketing email so that your users can continue recieving your transactional email witout having to receive your marketing content.
+Suppression groups, or [unsubscribe groups](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html), allow you to label a category of content that you regularly send. This gives your recipients the ability to opt out of a specific set of your email. For example, you might define a group for your transactional email, and one for your marketing email so that your users can continue receiving your transactional email without having to receive your marketing content.
### GET /asm/groups
@@ -470,17 +471,17 @@ Suppression groups, or [unsubscribe groups](https://sendgrid.com/docs/API_Refere
```python
params = {'id': 1}
response = sg.client.asm.groups.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update a suppression group.
**This endpoint allows you to update or change a suppression group.**
-Suppression groups, or unsubscribe groups, are specific types or categories of email that you would like your recipients to be able to unsubscribe from. For example: Daily Newsletters, Invoices, System Alerts.
+Suppression groups, or unsubscribe groups, are specific types or categories of emails that you would like your recipients to be able to unsubscribe from. For example: Daily Newsletters, Invoices, System Alerts.
-The **name** and **description** of the unsubscribe group will be visible by recipients when they are managing their subscriptions.
+The **name** and **description** of the unsubscribe group will be visible to recipients when they are managing their subscriptions.
Each user can create up to 25 different suppression groups.
@@ -495,17 +496,17 @@ data = {
}
group_id = "test_url_param"
response = sg.client.asm.groups._(group_id).patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Get information on a single suppression group.
**This endpoint allows you to retrieve a single suppression group.**
-Suppression groups, or unsubscribe groups, are specific types or categories of email that you would like your recipients to be able to unsubscribe from. For example: Daily Newsletters, Invoices, System Alerts.
+Suppression groups, or unsubscribe groups, are specific types or categories of emails that you would like your recipients to be able to unsubscribe from. For example: Daily Newsletters, Invoices, System Alerts.
-The **name** and **description** of the unsubscribe group will be visible by recipients when they are managing their subscriptions.
+The **name** and **description** of the unsubscribe group will be visible to recipients when they are managing their subscriptions.
Each user can create up to 25 different suppression groups.
@@ -515,9 +516,9 @@ Each user can create up to 25 different suppression groups.
```python
group_id = "test_url_param"
response = sg.client.asm.groups._(group_id).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete a suppression group.
@@ -525,9 +526,9 @@ print response.headers
You can only delete groups that have not been attached to sent mail in the last 60 days. If a recipient uses the "one-click unsubscribe" option on an email associated with a deleted group, that recipient will be added to the global suppression list.
-Suppression groups, or unsubscribe groups, are specific types or categories of email that you would like your recipients to be able to unsubscribe from. For example: Daily Newsletters, Invoices, System Alerts.
+Suppression groups, or unsubscribe groups, are specific types or categories of emails that you would like your recipients to be able to unsubscribe from. For example: Daily Newsletters, Invoices, System Alerts.
-The **name** and **description** of the unsubscribe group will be visible by recipients when they are managing their subscriptions.
+The **name** and **description** of the unsubscribe group will be visible to recipients when they are managing their subscriptions.
Each user can create up to 25 different suppression groups.
@@ -537,9 +538,9 @@ Each user can create up to 25 different suppression groups.
```python
group_id = "test_url_param"
response = sg.client.asm.groups._(group_id).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Add suppressions to a suppression group
@@ -561,9 +562,9 @@ data = {
}
group_id = "test_url_param"
response = sg.client.asm.groups._(group_id).suppressions.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all suppressions for a suppression group
@@ -577,9 +578,9 @@ Suppressions are recipient email addresses that are added to [unsubscribe groups
```python
group_id = "test_url_param"
response = sg.client.asm.groups._(group_id).suppressions.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Search for suppressions within a group
@@ -602,9 +603,9 @@ data = {
}
group_id = "test_url_param"
response = sg.client.asm.groups._(group_id).suppressions.search.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete a suppression from a suppression group
@@ -619,9 +620,9 @@ Suppressions are recipient email addresses that are added to [unsubscribe groups
group_id = "test_url_param"
email = "test_url_param"
response = sg.client.asm.groups._(group_id).suppressions._(email).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all suppressions
@@ -634,9 +635,9 @@ Suppressions are a list of email addresses that will not receive content sent un
```python
response = sg.client.asm.suppressions.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Add recipient addresses to the global suppression group.
@@ -655,15 +656,15 @@ data = {
]
}
response = sg.client.asm.suppressions._("global").post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve a Global Suppression
-**This endpoint allows you to retrieve a global suppression. You can also use this endpoint to confirm if an email address is already globally suppresed.**
+**This endpoint allows you to retrieve a global suppression. You can also use this endpoint to confirm if an email address is already globally suppressed.**
-If the email address you include in the URL path parameter `{email}` is alreayd globally suppressed, the response will include that email address. If the address you enter for `{email}` is not globally suppressed, an empty JSON object `{}` will be returned.
+If the email address you include in the URL path parameter `{email}` is already globally suppressed, the response will include that email address. If the address you enter for `{email}` is not globally suppressed, an empty JSON object `{}` will be returned.
A global suppression (or global unsubscribe) is an email address of a recipient who does not want to receive any of your messages. A globally suppressed recipient will be removed from any email you send. For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/global_unsubscribes.html).
@@ -673,9 +674,9 @@ A global suppression (or global unsubscribe) is an email address of a recipient
```python
email = "test_url_param"
response = sg.client.asm.suppressions._("global")._(email).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete a Global Suppression
@@ -689,9 +690,9 @@ A global suppression (or global unsubscribe) is an email address of a recipient
```python
email = "test_url_param"
response = sg.client.asm.suppressions._("global")._(email).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all suppression groups for an email address
@@ -705,9 +706,9 @@ Suppressions are a list of email addresses that will not receive content sent un
```python
email = "test_url_param"
response = sg.client.asm.suppressions._(email).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# BROWSERS
@@ -726,9 +727,9 @@ Advanced Stats provide a more in-depth view of your email statistics and the act
```python
params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'browsers': 'test_string', 'limit': 'test_string', 'offset': 'test_string', 'start_date': '2016-01-01'}
response = sg.client.browsers.stats.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# CAMPAIGNS
@@ -739,7 +740,7 @@ print response.headers
Our Marketing Campaigns API lets you create, manage, send, and schedule campaigns.
-Note: In order to send or schedule the campaign, you will be required to provide a subject, sender ID, content (we suggest both html and plain text), and at least one list or segment ID. This information is not required when you create a campaign.
+Note: In order to send or schedule the campaign, you will be required to provide a subject, sender ID, content (we suggest both HTML and plain text), and at least one list or segment ID. This information is not required when you create a campaign.
For more information:
@@ -770,9 +771,9 @@ data = {
"title": "March Newsletter"
}
response = sg.client.campaigns.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all Campaigns
@@ -790,11 +791,11 @@ For more information:
```python
-params = {'limit': 1, 'offset': 1}
+params = {'limit': 10, 'offset': 0}
response = sg.client.campaigns.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update a Campaign
@@ -819,9 +820,9 @@ data = {
}
campaign_id = "test_url_param"
response = sg.client.campaigns._(campaign_id).patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve a single campaign
@@ -839,9 +840,9 @@ For more information:
```python
campaign_id = "test_url_param"
response = sg.client.campaigns._(campaign_id).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete a Campaign
@@ -859,9 +860,9 @@ For more information:
```python
campaign_id = "test_url_param"
response = sg.client.campaigns._(campaign_id).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update a Scheduled Campaign
@@ -880,9 +881,9 @@ data = {
}
campaign_id = "test_url_param"
response = sg.client.campaigns._(campaign_id).schedules.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Schedule a Campaign
@@ -901,9 +902,9 @@ data = {
}
campaign_id = "test_url_param"
response = sg.client.campaigns._(campaign_id).schedules.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## View Scheduled Time of a Campaign
@@ -919,9 +920,9 @@ For more information:
```python
campaign_id = "test_url_param"
response = sg.client.campaigns._(campaign_id).schedules.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Unschedule a Scheduled Campaign
@@ -940,9 +941,9 @@ For more information:
```python
campaign_id = "test_url_param"
response = sg.client.campaigns._(campaign_id).schedules.delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Send a Campaign
@@ -960,9 +961,9 @@ For more information:
```python
campaign_id = "test_url_param"
response = sg.client.campaigns._(campaign_id).schedules.now.post()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Send a Test Campaign
@@ -983,9 +984,9 @@ data = {
}
campaign_id = "test_url_param"
response = sg.client.campaigns._(campaign_id).schedules.test.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# CATEGORIES
@@ -1002,9 +1003,9 @@ Categories can help organize your email analytics by enabling you to tag emails
```python
params = {'category': 'test_string', 'limit': 1, 'offset': 1}
response = sg.client.categories.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve Email Statistics for Categories
@@ -1020,9 +1021,9 @@ Categories allow you to group your emails together according to broad topics tha
```python
params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01', 'categories': 'test_string'}
response = sg.client.categories.stats.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve sums of email stats for each category [Needs: Stats object defined, has category ID?]
@@ -1038,9 +1039,9 @@ Categories allow you to group your emails together according to broad topics tha
```python
params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'start_date': '2016-01-01', 'sort_by_direction': 'asc'}
response = sg.client.categories.stats.sums.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# CLIENTS
@@ -1059,9 +1060,9 @@ Advanced Stats provide a more in-depth view of your email statistics and the act
```python
params = {'aggregated_by': 'day', 'start_date': '2016-01-01', 'end_date': '2016-04-01'}
response = sg.client.clients.stats.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve stats by a specific client type.
@@ -1084,9 +1085,9 @@ Advanced Stats provide a more in-depth view of your email statistics and the act
params = {'aggregated_by': 'day', 'start_date': '2016-01-01', 'end_date': '2016-04-01'}
client_type = "test_url_param"
response = sg.client.clients._(client_type).stats.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# CONTACTDB
@@ -1095,7 +1096,7 @@ print response.headers
**This endpoint allows you to create a custom field.**
-The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
### POST /contactdb/custom_fields
@@ -1106,30 +1107,30 @@ data = {
"type": "text"
}
response = sg.client.contactdb.custom_fields.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all custom fields
**This endpoint allows you to retrieve all custom fields.**
-The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
### GET /contactdb/custom_fields
```python
response = sg.client.contactdb.custom_fields.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve a Custom Field
**This endpoint allows you to retrieve a custom field by ID.**
-The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
### GET /contactdb/custom_fields/{custom_field_id}
@@ -1137,15 +1138,15 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](
```python
custom_field_id = "test_url_param"
response = sg.client.contactdb.custom_fields._(custom_field_id).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete a Custom Field
**This endpoint allows you to delete a custom field by ID.**
-The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
### DELETE /contactdb/custom_fields/{custom_field_id}
@@ -1153,9 +1154,9 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](
```python
custom_field_id = "test_url_param"
response = sg.client.contactdb.custom_fields._(custom_field_id).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Create a List
@@ -1171,9 +1172,9 @@ data = {
"name": "your list name"
}
response = sg.client.contactdb.lists.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all lists
@@ -1186,9 +1187,9 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co
```python
response = sg.client.contactdb.lists.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete Multiple lists
@@ -1207,9 +1208,9 @@ data = [
4
]
response = sg.client.contactdb.lists.delete(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update a List
@@ -1228,9 +1229,9 @@ data = {
params = {'list_id': 1}
list_id = "test_url_param"
response = sg.client.contactdb.lists._(list_id).patch(request_body=data, query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve a single list
@@ -1245,9 +1246,9 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co
params = {'list_id': 1}
list_id = "test_url_param"
response = sg.client.contactdb.lists._(list_id).get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete a List
@@ -1262,9 +1263,9 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co
params = {'delete_contacts': 'true'}
list_id = "test_url_param"
response = sg.client.contactdb.lists._(list_id).delete(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Add Multiple Recipients to a List
@@ -1284,9 +1285,9 @@ data = [
]
list_id = "test_url_param"
response = sg.client.contactdb.lists._(list_id).recipients.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all recipients on a List
@@ -1301,9 +1302,9 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co
params = {'page': 1, 'page_size': 1, 'list_id': 1}
list_id = "test_url_param"
response = sg.client.contactdb.lists._(list_id).recipients.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Add a Single Recipient to a List
@@ -1318,9 +1319,9 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co
list_id = "test_url_param"
recipient_id = "test_url_param"
response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).post()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete a Single Recipient from a Single List
@@ -1336,9 +1337,9 @@ params = {'recipient_id': 1, 'list_id': 1}
list_id = "test_url_param"
recipient_id = "test_url_param"
response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).delete(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update Recipient
@@ -1348,7 +1349,7 @@ The body of an API call to this endpoint must include an array of one or more re
It is of note that you can add custom field data as parameters on recipient objects. We have provided an example using some of the default custom fields SendGrid provides.
-The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
### PATCH /contactdb/recipients
@@ -1362,9 +1363,9 @@ data = [
}
]
response = sg.client.contactdb.recipients.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Add recipients
@@ -1393,9 +1394,9 @@ data = [
}
]
response = sg.client.contactdb.recipients.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve recipients
@@ -1412,17 +1413,17 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co
```python
params = {'page': 1, 'page_size': 1}
response = sg.client.contactdb.recipients.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete Recipient
-**This endpoint allows you to deletes one or more recipients.**
+**This endpoint allows you to delete one or more recipients.**
The body of an API call to this endpoint must include an array of recipient IDs of the recipients you want to delete.
-The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
### DELETE /contactdb/recipients
@@ -1433,9 +1434,9 @@ data = [
"recipient_id2"
]
response = sg.client.contactdb.recipients.delete(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve the count of billable recipients
@@ -1450,24 +1451,24 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co
```python
response = sg.client.contactdb.recipients.billable_count.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve a Count of Recipients
**This endpoint allows you to retrieve the total number of Marketing Campaigns recipients.**
-The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
### GET /contactdb/recipients/count
```python
response = sg.client.contactdb.recipients.count.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve recipients matching search criteria
@@ -1476,13 +1477,13 @@ print response.headers
field_name:
* is a variable that is substituted for your actual custom field name from your recipient.
-* Text fields must be url-encoded. Date fields are searchable only by unix timestamp (e.g. 2/2/2015 becomes 1422835200)
+* Text fields must be url-encoded. Date fields are searchable only by UNIX timestamp (e.g. 2/2/2015 becomes 1422835200)
* If field_name is a 'reserved' date field, such as created_at or updated_at, the system will internally convert
your epoch time to a date range encompassing the entire day. For example, an epoch time of 1422835600 converts to
Mon, 02 Feb 2015 00:06:40 GMT, but internally the system will search from Mon, 02 Feb 2015 00:00:00 GMT through
Mon, 02 Feb 2015 23:59:59 GMT.
-The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
### GET /contactdb/recipients/search
@@ -1490,9 +1491,9 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](
```python
params = {'{field_name}': 'test_string'}
response = sg.client.contactdb.recipients.search.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve a single recipient
@@ -1506,9 +1507,9 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co
```python
recipient_id = "test_url_param"
response = sg.client.contactdb.recipients._(recipient_id).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete a Recipient
@@ -1522,9 +1523,9 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co
```python
recipient_id = "test_url_param"
response = sg.client.contactdb.recipients._(recipient_id).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve the lists that a recipient is on
@@ -1540,24 +1541,24 @@ The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.co
```python
recipient_id = "test_url_param"
response = sg.client.contactdb.recipients._(recipient_id).lists.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve reserved fields
**This endpoint allows you to list all fields that are reserved and can't be used for custom field names.**
-The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
+The contactdb is a database of your contacts for [Twilio SendGrid Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html).
### GET /contactdb/reserved_fields
```python
response = sg.client.contactdb.reserved_fields.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Create a Segment
@@ -1579,7 +1580,7 @@ Valid operators for create and update depend on the type of the field you are se
Segment conditions using "eq" or "ne" for email clicks and opens should provide a "field" of either *clicks.campaign_identifier* or *opens.campaign_identifier*. The condition value should be a string containing the id of a completed campaign.
-Segments may contain multiple condtions, joined by an "and" or "or" in the "and_or" field. The first condition in the conditions list must have an empty "and_or", and subsequent conditions must all specify an "and_or".
+Segments may contain multiple conditions, joined by an "and" or "or" in the "and_or" field. The first condition in the conditions list must have an empty "and_or", and subsequent conditions must all specify an "and_or".
The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients.
@@ -1614,9 +1615,9 @@ data = {
"name": "Last Name Miller"
}
response = sg.client.contactdb.segments.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all segments
@@ -1631,9 +1632,9 @@ For more information about segments in Marketing Campaigns, please see our [User
```python
response = sg.client.contactdb.segments.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update a segment
@@ -1662,9 +1663,9 @@ data = {
params = {'segment_id': 'test_string'}
segment_id = "test_url_param"
response = sg.client.contactdb.segments._(segment_id).patch(request_body=data, query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve a segment
@@ -1681,13 +1682,13 @@ For more information about segments in Marketing Campaigns, please see our [User
params = {'segment_id': 1}
segment_id = "test_url_param"
response = sg.client.contactdb.segments._(segment_id).get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete a segment
-**This endpoint allows you to delete a segment from your recipients database.**
+**This endpoint allows you to delete a segment from your recipient's database.**
You also have the option to delete all the contacts from your Marketing Campaigns recipient database who were in this segment.
@@ -1702,9 +1703,9 @@ For more information about segments in Marketing Campaigns, please see our [User
params = {'delete_contacts': 'true'}
segment_id = "test_url_param"
response = sg.client.contactdb.segments._(segment_id).delete(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve recipients on a segment
@@ -1721,9 +1722,9 @@ For more information about segments in Marketing Campaigns, please see our [User
params = {'page': 1, 'page_size': 1}
segment_id = "test_url_param"
response = sg.client.contactdb.segments._(segment_id).recipients.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# DEVICES
@@ -1737,10 +1738,10 @@ print response.headers
## Available Device Types
| **Device** | **Description** | **Example** |
|---|---|---|
-| Desktop | Email software on desktop computer. | I.E., Outlook, Sparrow, or Apple Mail. |
-| Webmail | A web-based email client. | I.E., Yahoo, Google, AOL, or Outlook.com. |
-| Phone | A smart phone. | iPhone, Android, Blackberry, etc.
-| Tablet | A tablet computer. | iPad, android based tablet, etc. |
+| Desktop | Email software on a desktop computer. | I.E., Outlook, Sparrow, or Apple Mail. |
+| Webmail | A web-based email client. | I.E., Yahoo, Google, AOL, or Outlook.com. |
+| Phone | A smartphone. | iPhone, Android, Blackberry, etc.
+| Tablet | A tablet computer. | iPad, Android-based tablet, etc. |
| Other | An unrecognized device. |
Advanced Stats provide a more in-depth view of your email statistics and the actions taken by your recipients. You can segment these statistics by geographic location, device type, client type, browser, and mailbox provider. For more information about statistics, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/index.html).
@@ -1751,9 +1752,9 @@ Advanced Stats provide a more in-depth view of your email statistics and the act
```python
params = {'aggregated_by': 'day', 'limit': 1, 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 1}
response = sg.client.devices.stats.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# GEO
@@ -1772,9 +1773,9 @@ Advanced Stats provide a more in-depth view of your email statistics and the act
```python
params = {'end_date': '2016-04-01', 'country': 'US', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01'}
response = sg.client.geo.stats.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# IPS
@@ -1783,7 +1784,7 @@ print response.headers
**This endpoint allows you to retrieve a list of all assigned and unassigned IPs.**
-Response includes warm up status, pools, assigned subusers, and whitelabel info. The start_date field corresponds to when warmup started for that IP.
+The response includes warm-up status, pools, assigned subusers, and authentication info. The start_date field corresponds to when warmup started for that IP.
A single IP address or a range of IP addresses may be dedicated to an account in order to send email for multiple domains. The reputation of this IP is based on the aggregate performance of all the senders who use it.
@@ -1793,9 +1794,9 @@ A single IP address or a range of IP addresses may be dedicated to an account in
```python
params = {'subuser': 'test_string', 'ip': 'test_string', 'limit': 1, 'exclude_whitelabels': 'true', 'offset': 1}
response = sg.client.ips.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all assigned IPs
@@ -1808,9 +1809,9 @@ A single IP address or a range of IP addresses may be dedicated to an account in
```python
response = sg.client.ips.assigned.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Create an IP pool.
@@ -1818,9 +1819,9 @@ print response.headers
**Each user can create up to 10 different IP pools.**
-IP Pools allow you to group your dedicated SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic.
+IP Pools allow you to group your dedicated Twilio SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic.
-IP pools can only be used with whitelabeled IP addresses.
+IP pools can only be used with authenticated IP addresses.
If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools.
@@ -1832,17 +1833,17 @@ data = {
"name": "marketing"
}
response = sg.client.ips.pools.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all IP pools.
-**This endpoint allows you to retreive all of your IP pools.**
+**This endpoint allows you to retrieve all of your IP pools.**
IP Pools allow you to group your dedicated SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic.
-IP pools can only be used with whitelabeled IP addresses.
+IP pools can only be used with authenticated IP addresses.
If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools.
@@ -1851,17 +1852,17 @@ If an IP pool is NOT specified for an email, it will use any IP available, inclu
```python
response = sg.client.ips.pools.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update an IP pools name.
**This endpoint allows you to update the name of an IP pool.**
-IP Pools allow you to group your dedicated SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic.
+IP Pools allow you to group your dedicated Twilio SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic.
-IP pools can only be used with whitelabeled IP addresses.
+IP pools can only be used with authenticated IP addresses.
If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools.
@@ -1874,17 +1875,17 @@ data = {
}
pool_name = "test_url_param"
response = sg.client.ips.pools._(pool_name).put(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all IPs in a specified pool.
**This endpoint allows you to list all of the IP addresses that are in a specific IP pool.**
-IP Pools allow you to group your dedicated SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic.
+IP Pools allow you to group your dedicated Twilio SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic.
-IP pools can only be used with whitelabeled IP addresses.
+IP pools can only be used with authenticated IP addresses.
If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools.
@@ -1894,17 +1895,17 @@ If an IP pool is NOT specified for an email, it will use any IP available, inclu
```python
pool_name = "test_url_param"
response = sg.client.ips.pools._(pool_name).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete an IP pool.
**This endpoint allows you to delete an IP pool.**
-IP Pools allow you to group your dedicated SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic.
+IP Pools allow you to group your dedicated Twilio SendGrid IP addresses together. For example, you could create separate pools for your transactional and marketing email. When sending marketing emails, specify that you want to use the marketing IP pool. This allows you to maintain separate reputations for your different email traffic.
-IP pools can only be used with whitelabeled IP addresses.
+IP pools can only be used with authenticated IP addresses.
If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools.
@@ -1914,9 +1915,9 @@ If an IP pool is NOT specified for an email, it will use any IP available, inclu
```python
pool_name = "test_url_param"
response = sg.client.ips.pools._(pool_name).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Add an IP address to a pool
@@ -1935,9 +1936,9 @@ data = {
}
pool_name = "test_url_param"
response = sg.client.ips.pools._(pool_name).ips.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Remove an IP address from a pool.
@@ -1954,15 +1955,15 @@ A single IP address or a range of IP addresses may be dedicated to an account in
pool_name = "test_url_param"
ip = "test_url_param"
response = sg.client.ips.pools._(pool_name).ips._(ip).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Add an IP to warmup
**This endpoint allows you to enter an IP address into warmup mode.**
-SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how SendGrid limits your email traffic for IPs in warmup.
+Twilio SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how Twilio SendGrid limits your email traffic for IPs in warmup.
For more general information about warming up IPs, please see our [Classroom](https://sendgrid.com/docs/Classroom/Deliver/Delivery_Introduction/warming_up_ips.html).
@@ -1974,15 +1975,15 @@ data = {
"ip": "0.0.0.0"
}
response = sg.client.ips.warmup.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all IPs currently in warmup
**This endpoint allows you to retrieve all of your IP addresses that are currently warming up.**
-SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how SendGrid limits your email traffic for IPs in warmup.
+Twilio SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how Twilio SendGrid limits your email traffic for IPs in warmup.
For more general information about warming up IPs, please see our [Classroom](https://sendgrid.com/docs/Classroom/Deliver/Delivery_Introduction/warming_up_ips.html).
@@ -1991,15 +1992,15 @@ For more general information about warming up IPs, please see our [Classroom](ht
```python
response = sg.client.ips.warmup.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve warmup status for a specific IP address
**This endpoint allows you to retrieve the warmup status for a specific IP address.**
-SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how SendGrid limits your email traffic for IPs in warmup.
+Twilio SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how Twilio SendGrid limits your email traffic for IPs in warmup.
For more general information about warming up IPs, please see our [Classroom](https://sendgrid.com/docs/Classroom/Deliver/Delivery_Introduction/warming_up_ips.html).
@@ -2009,15 +2010,15 @@ For more general information about warming up IPs, please see our [Classroom](ht
```python
ip_address = "test_url_param"
response = sg.client.ips.warmup._(ip_address).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Remove an IP from warmup
**This endpoint allows you to remove an IP address from warmup mode.**
-SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how SendGrid limits your email traffic for IPs in warmup.
+Twilio SendGrid can automatically warm up dedicated IP addresses by limiting the amount of mail that can be sent through them per hour, with the limit determined by how long the IP address has been in warmup. See the [warmup schedule](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_warmup_schedule.html) for more details on how Twilio SendGrid limits your email traffic for IPs in warmup.
For more general information about warming up IPs, please see our [Classroom](https://sendgrid.com/docs/Classroom/Deliver/Delivery_Introduction/warming_up_ips.html).
@@ -2027,9 +2028,9 @@ For more general information about warming up IPs, please see our [Classroom](ht
```python
ip_address = "test_url_param"
response = sg.client.ips.warmup._(ip_address).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all IP pools an IP address belongs to
@@ -2045,9 +2046,9 @@ A single IP address or a range of IP addresses may be dedicated to an account in
```python
ip_address = "test_url_param"
response = sg.client.ips._(ip_address).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# MAIL
@@ -2067,9 +2068,9 @@ More Information:
```python
response = sg.client.mail.batch.post()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Validate batch ID
@@ -2087,13 +2088,13 @@ More Information:
```python
batch_id = "test_url_param"
response = sg.client.mail.batch._(batch_id).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## v3 Mail Send
-This endpoint allows you to send email over SendGrids v3 Web API, the most recent version of our API. If you are looking for documentation about the v2 Mail Send endpoint, please see our [v2 API Reference](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
+This endpoint allows you to send email over Twilio SendGrid's v3 Web API, the most recent version of our API. If you are looking for documentation about the v2 Mail Send endpoint, please see our [v2 API Reference](https://sendgrid.com/docs/API_Reference/Web_API/mail.html).
* Top level parameters are referred to as "global".
* Individual fields within the personalizations array will override any other global, or message level, parameters that are defined outside of personalizations.
@@ -2104,7 +2105,7 @@ For more detailed information about how to use the v3 Mail Send endpoint, please
### POST /mail/send
-This endpoint has a helper, check it out [here](https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/README.md).
+This endpoint has a helper, check it out [here](sendgrid/helpers/mail/README.md).
```python
data = {
@@ -2158,8 +2159,8 @@ data = {
},
"footer": {
"enable": True,
- "html": "ThanksThe SendGrid Team
",
- "text": "Thanks,/n The SendGrid Team"
+ "html": "ThanksThe Twilio SendGrid Team
",
+ "text": "Thanks,/n The Twilio SendGrid Team"
},
"sandbox_mode": {
"enable": False
@@ -2241,23 +2242,23 @@ data = {
"enable": True,
"html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
"substitution_tag": "<%click here%>",
- "text": "If you would like to unsubscribe and stop receiveing these emails <% click here %>."
+ "text": "If you would like to unsubscribe and stop receiving these emails <% click here %>."
}
}
}
response = sg.client.mail.send.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-
+
# MAIL SETTINGS
## Retrieve all mail settings
**This endpoint allows you to retrieve a list of all mail settings.**
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### GET /mail_settings
@@ -2265,9 +2266,9 @@ Mail settings allow you to tell SendGrid specific things to do to every email th
```python
params = {'limit': 1, 'offset': 1}
response = sg.client.mail_settings.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update address whitelist mail settings
@@ -2275,7 +2276,7 @@ print response.headers
The address whitelist setting whitelists a specified email address or domain for which mail should never be suppressed. For example, you own the domain example.com, and one or more of your recipients use email@example.com addresses, by placing example.com in the address whitelist setting, all bounces, blocks, and unsubscribes logged for that domain will be ignored and sent as if under normal sending conditions.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### PATCH /mail_settings/address_whitelist
@@ -2289,9 +2290,9 @@ data = {
]
}
response = sg.client.mail_settings.address_whitelist.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve address whitelist mail settings
@@ -2299,24 +2300,24 @@ print response.headers
The address whitelist setting whitelists a specified email address or domain for which mail should never be suppressed. For example, you own the domain example.com, and one or more of your recipients use email@example.com addresses, by placing example.com in the address whitelist setting, all bounces, blocks, and unsubscribes logged for that domain will be ignored and sent as if under normal sending conditions.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### GET /mail_settings/address_whitelist
```python
response = sg.client.mail_settings.address_whitelist.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update BCC mail settings
**This endpoint allows you to update your current BCC mail settings.**
-When the BCC mail setting is enabled, SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field, if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules.
+When the BCC mail setting is enabled, Twilio SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field, if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### PATCH /mail_settings/bcc
@@ -2327,34 +2328,34 @@ data = {
"enabled": False
}
response = sg.client.mail_settings.bcc.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve all BCC mail settings
**This endpoint allows you to retrieve your current BCC mail settings.**
-When the BCC mail setting is enabled, SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field, if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules.
+When the BCC mail setting is enabled, Twilio SendGrid will automatically send a blind carbon copy (BCC) to an address for every email sent without adding that address to the header. Please note that only one email address may be entered in this field, if you wish to distribute BCCs to multiple addresses you will need to create a distribution group or use forwarding rules.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### GET /mail_settings/bcc
```python
response = sg.client.mail_settings.bcc.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update bounce purge mail settings
**This endpoint allows you to update your current bounce purge settings.**
-This setting allows you to set a schedule for SendGrid to automatically delete contacts from your soft and hard bounce suppression lists.
+This setting allows you to set a schedule for Twilio SendGrid to automatically delete contacts from your soft and hard bounce suppression lists.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### PATCH /mail_settings/bounce_purge
@@ -2366,26 +2367,26 @@ data = {
"soft_bounces": 5
}
response = sg.client.mail_settings.bounce_purge.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve bounce purge mail settings
**This endpoint allows you to retrieve your current bounce purge settings.**
-This setting allows you to set a schedule for SendGrid to automatically delete contacts from your soft and hard bounce suppression lists.
+This setting allows you to set a schedule for Twilio SendGrid to automatically delete contacts from your soft and hard bounce suppression lists.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### GET /mail_settings/bounce_purge
```python
response = sg.client.mail_settings.bounce_purge.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update footer mail settings
@@ -2393,7 +2394,7 @@ print response.headers
The footer setting will insert a custom footer at the bottom of the text and HTML bodies. Use the embedded HTML editor and plain text entry fields to create the content of the footers to be inserted into your emails.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### PATCH /mail_settings/footer
@@ -2405,9 +2406,9 @@ data = {
"plain_content": "..."
}
response = sg.client.mail_settings.footer.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve footer mail settings
@@ -2415,16 +2416,16 @@ print response.headers
The footer setting will insert a custom footer at the bottom of the text and HTML bodies. Use the embedded HTML editor and plain text entry fields to create the content of the footers to be inserted into your emails.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### GET /mail_settings/footer
```python
response = sg.client.mail_settings.footer.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update forward bounce mail settings
@@ -2432,7 +2433,7 @@ print response.headers
Activating this setting allows you to specify an email address to which bounce reports are forwarded.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### PATCH /mail_settings/forward_bounce
@@ -2443,9 +2444,9 @@ data = {
"enabled": True
}
response = sg.client.mail_settings.forward_bounce.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve forward bounce mail settings
@@ -2453,16 +2454,16 @@ print response.headers
Activating this setting allows you to specify an email address to which bounce reports are forwarded.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### GET /mail_settings/forward_bounce
```python
response = sg.client.mail_settings.forward_bounce.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update forward spam mail settings
@@ -2470,7 +2471,7 @@ print response.headers
Enabling the forward spam setting allows you to specify an email address to which spam reports will be forwarded.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### PATCH /mail_settings/forward_spam
@@ -2481,9 +2482,9 @@ data = {
"enabled": False
}
response = sg.client.mail_settings.forward_spam.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve forward spam mail settings
@@ -2491,16 +2492,16 @@ print response.headers
Enabling the forward spam setting allows you to specify an email address to which spam reports will be forwarded.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### GET /mail_settings/forward_spam
```python
response = sg.client.mail_settings.forward_spam.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update plain content mail settings
@@ -2508,7 +2509,7 @@ print response.headers
The plain content setting will automatically convert any plain text emails that you send to HTML before sending.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### PATCH /mail_settings/plain_content
@@ -2518,9 +2519,9 @@ data = {
"enabled": False
}
response = sg.client.mail_settings.plain_content.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve plain content mail settings
@@ -2528,16 +2529,16 @@ print response.headers
The plain content setting will automatically convert any plain text emails that you send to HTML before sending.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### GET /mail_settings/plain_content
```python
response = sg.client.mail_settings.plain_content.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update spam check mail settings
@@ -2545,7 +2546,7 @@ print response.headers
The spam checker filter notifies you when emails are detected that exceed a predefined spam threshold.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### PATCH /mail_settings/spam_check
@@ -2557,9 +2558,9 @@ data = {
"url": "url"
}
response = sg.client.mail_settings.spam_check.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve spam check mail settings
@@ -2567,16 +2568,16 @@ print response.headers
The spam checker filter notifies you when emails are detected that exceed a predefined spam threshold.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### GET /mail_settings/spam_check
```python
response = sg.client.mail_settings.spam_check.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update template mail settings
@@ -2586,7 +2587,7 @@ This setting refers to our original email templates. We currently support more f
The legacy email template setting wraps an HTML template around your email content. This can be useful for sending out marketing email and/or other HTML formatted messages.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### PATCH /mail_settings/template
@@ -2597,9 +2598,9 @@ data = {
"html_content": "<% body %>"
}
response = sg.client.mail_settings.template.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Retrieve legacy template mail settings
@@ -2609,18 +2610,18 @@ This setting refers to our original email templates. We currently support more f
The legacy email template setting wraps an HTML template around your email content. This can be useful for sending out marketing email and/or other HTML formatted messages.
-Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
+Mail settings allow you to tell Twilio SendGrid specific things to do to every email that you send to your recipients over Twilio SendGrid's [Web API](https://sendgrid.com/docs/API_Reference/Web_API/mail.html) or [SMTP Relay](https://sendgrid.com/docs/API_Reference/SMTP_API/index.html).
### GET /mail_settings/template
```python
response = sg.client.mail_settings.template.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-
+
# MAILBOX PROVIDERS
## Retrieve email statistics by mailbox provider.
@@ -2637,18 +2638,18 @@ Advanced Stats provide a more in-depth view of your email statistics and the act
```python
params = {'end_date': '2016-04-01', 'mailbox_providers': 'test_string', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01'}
response = sg.client.mailbox_providers.stats.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-
+
# PARTNER SETTINGS
## Returns a list of all partner settings.
**This endpoint allows you to retrieve a list of all partner settings that you can enable.**
-Our partner settings allow you to integrate your SendGrid account with our partners to increase your SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html).
+Our partner settings allow you to integrate your Twilio SendGrid account with our partners to increase your Twilio SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html).
### GET /partner_settings
@@ -2656,17 +2657,17 @@ Our partner settings allow you to integrate your SendGrid account with our partn
```python
params = {'limit': 1, 'offset': 1}
response = sg.client.partner_settings.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Updates New Relic partner settings.
**This endpoint allows you to update or change your New Relic partner settings.**
-Our partner settings allow you to integrate your SendGrid account with our partners to increase your SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html).
+Our partner settings allow you to integrate your Twilio SendGrid account with our partners to increase your Twilio SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html).
-By integrating with New Relic, you can send your SendGrid email statistics to your New Relic Dashboard. If you enable this setting, your stats will be sent to New Relic every 5 minutes. You will need your New Relic License Key to enable this setting. For more information, please see our [Classroom](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/new_relic.html).
+By integrating with New Relic, you can send your Twilio SendGrid email statistics to your New Relic Dashboard. If you enable this setting, your stats will be sent to New Relic every 5 minutes. You will need your New Relic License Key to enable this setting. For more information, please see our [Classroom](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/new_relic.html).
### PATCH /partner_settings/new_relic
@@ -2678,26 +2679,26 @@ data = {
"license_key": ""
}
response = sg.client.partner_settings.new_relic.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Returns all New Relic partner settings.
**This endpoint allows you to retrieve your current New Relic partner settings.**
-Our partner settings allow you to integrate your SendGrid account with our partners to increase your SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html).
+Our partner settings allow you to integrate your Twilio SendGrid account with our partners to increase your Twilio SendGrid experience and functionality. For more information about our partners, and how you can begin integrating with them, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/partners.html).
-By integrating with New Relic, you can send your SendGrid email statistics to your New Relic Dashboard. If you enable this setting, your stats will be sent to New Relic every 5 minutes. You will need your New Relic License Key to enable this setting. For more information, please see our [Classroom](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/new_relic.html).
+By integrating with New Relic, you can send your Twilio SendGrid email statistics to your New Relic Dashboard. If you enable this setting, your stats will be sent to New Relic every 5 minutes. You will need your New Relic License Key to enable this setting. For more information, please see our [Classroom](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/new_relic.html).
### GET /partner_settings/new_relic
```python
response = sg.client.partner_settings.new_relic.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# SCOPES
@@ -2706,16 +2707,16 @@ print response.headers
**This endpoint returns a list of all scopes that this user has access to.**
-API Keys can be used to authenticate the use of [SendGrids v3 Web API](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html), or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html). API Keys may be assigned certain permissions, or scopes, that limit which API endpoints they are able to access. For a more detailed explanation of how you can use API Key permissios, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/api_keys.html#-API-Key-Permissions) or [Classroom](https://sendgrid.com/docs/Classroom/Basics/API/api_key_permissions.html).
+API Keys can be used to authenticate the use of [Twilio SendGrid's v3 Web API](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html), or the [Mail API Endpoint](https://sendgrid.com/docs/API_Reference/Web_API/mail.html). API Keys may be assigned certain permissions, or scopes, that limit which API endpoints they are able to access. For a more detailed explanation of how you can use API Key permissions, please visit our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/api_keys.html#-API-Key-Permissions) or [Classroom](https://sendgrid.com/docs/Classroom/Basics/API/api_key_permissions.html).
### GET /scopes
```python
response = sg.client.scopes.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
# SENDERS
@@ -2726,7 +2727,7 @@ print response.headers
*You may create up to 100 unique sender identities.*
-Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
+Sender Identities are required to be verified before use. If your domain has been authenticated it will auto verify on creation. Otherwise, an email will be sent to the `from.email`.
### POST /senders
@@ -2750,30 +2751,30 @@ data = {
"zip": "80202"
}
response = sg.client.senders.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Get all Sender Identities
**This endpoint allows you to retrieve a list of all sender identities that have been created for your account.**
-Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
+Sender Identities are required to be verified before use. If your domain has been authenticated it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
### GET /senders
```python
response = sg.client.senders.get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Update a Sender Identity
**This endpoint allows you to update a sender identity.**
-Updates to `from.email` require re-verification. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
+Updates to `from.email` require re-verification. If your domain has been authenticated it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
Partial updates are allowed, but fields that are marked as "required" in the POST (create) endpoint must not be nil if that field is included in the PATCH request.
@@ -2800,15 +2801,15 @@ data = {
}
sender_id = "test_url_param"
response = sg.client.senders._(sender_id).patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## View a Sender Identity
**This endpoint allows you to retrieve a specific sender identity.**
-Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
+Sender Identities are required to be verified before use. If your domain has been authenticated it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
### GET /senders/{sender_id}
@@ -2816,15 +2817,15 @@ Sender Identities are required to be verified before use. If your domain has bee
```python
sender_id = "test_url_param"
response = sg.client.senders._(sender_id).get()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Delete a Sender Identity
-**This endoint allows you to delete one of your sender identities.**
+**This endpoint allows you to delete one of your sender identities.**
-Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
+Sender Identities are required to be verified before use. If your domain has been authenticated it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
### DELETE /senders/{sender_id}
@@ -2832,15 +2833,15 @@ Sender Identities are required to be verified before use. If your domain has bee
```python
sender_id = "test_url_param"
response = sg.client.senders._(sender_id).delete()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
## Resend Sender Identity Verification
-**This enpdoint allows you to resend a sender identity verification email.**
+**This endpoint allows you to resend a sender identity verification email.**
-Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
+Sender Identities are required to be verified before use. If your domain has been authenticated it will auto verify on creation. Otherwise an email will be sent to the `from.email`.
### POST /senders/{sender_id}/resend_verification
@@ -2848,2190 +2849,2193 @@ Sender Identities are required to be verified before use. If your domain has bee
```python
sender_id = "test_url_param"
response = sg.client.senders._(sender_id).resend_verification.post()
-print response.status_code
-print response.body
-print response.headers
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-
-# STATS
-
-## Retrieve global email statistics
-
-**This endpoint allows you to retrieve all of your global email statistics between a given date range.**
-
-Parent accounts will see aggregated stats for their account and all subuser accounts. Subuser accounts will only see their own stats.
-
-### GET /stats
+
+# SENDER AUTHENTICATION
-```python
-params = {'aggregated_by': 'day', 'limit': 1, 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 1}
-response = sg.client.stats.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
-```
-
-# SUBUSERS
+## Create an authenticated domain.
-## Create Subuser
+**This endpoint allows you to create a domain authentication for one of your domains.**
-This endpoint allows you to retrieve a list of all of your subusers. You can choose to retrieve specific subusers as well as limit the results that come back from the API.
+If you are creating a domain authentication that you would like a subuser to use, you have two options:
+1. Use the "username" parameter. This allows you to create a domain authentication on behalf of your subuser. This means the subuser is able to see and modify the created authentication.
+2. Use the Association workflow (see Associate Domain section). This allows you to assign a domain authentication created by the parent to a subuser. This means the subuser will default to the assigned domain authentication, but will not be able to see or modify that authentication. However, if the subuser creates their own domain authentication it will overwrite the assigned domain authentication.
-For more information about Subusers:
+A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
-* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
-* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html)
+For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
-### POST /subusers
+### POST /whitelabel/domains
```python
data = {
- "email": "John@example.com",
+ "automatic_security": False,
+ "custom_spf": True,
+ "default": True,
+ "domain": "example.com",
"ips": [
- "1.1.1.1",
- "2.2.2.2"
+ "192.168.1.1",
+ "192.168.1.2"
],
- "password": "johns_password",
- "username": "John@example.com"
+ "subdomain": "news",
+ "username": "john@example.com"
}
-response = sg.client.subusers.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.whitelabel.domains.post(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## List all Subusers
-
-This endpoint allows you to retrieve a list of all of your subusers. You can choose to retrieve specific subusers as well as limit the results that come back from the API.
-
-For more information about Subusers:
-
-* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
-* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html)
-
-### GET /subusers
+## List all domain authentications.
+**This endpoint allows you to retrieve a list of all domain authentications you have created.**
-```python
-params = {'username': 'test_string', 'limit': 1, 'offset': 1}
-response = sg.client.subusers.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
-```
-## Retrieve Subuser Reputations
+A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
-Subuser sender reputations give a good idea how well a sender is doing with regards to how recipients and recipient servers react to the mail that is being received. When a bounce, spam report, or other negative action happens on a sent email, it will effect your sender rating.
+For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
-This endpoint allows you to request the reputations for your subusers.
-### GET /subusers/reputations
+### GET /whitelabel/domains
```python
-params = {'usernames': 'test_string'}
-response = sg.client.subusers.reputations.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+params = {'username': 'test_string', 'domain': 'test_string', 'exclude_subusers': 'true', 'limit': 1, 'offset': 1}
+response = sg.client.whitelabel.domains.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve email statistics for your subusers.
+## Get the default domain authentication.
-**This endpoint allows you to retrieve the email statistics for the given subusers.**
+**This endpoint allows you to retrieve the default default authentication for a domain.**
-You may retrieve statistics for up to 10 different subusers by including an additional _subusers_ parameter for each additional subuser.
+A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
-While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings.
+For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
-For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html).
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| domain | string |The domain to find a default domain authentication for. |
-### GET /subusers/stats
+### GET /whitelabel/domains/default
```python
-params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01', 'subusers': 'test_string'}
-response = sg.client.subusers.stats.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.whitelabel.domains.default.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve monthly stats for all subusers
+## List the domain authentication associated with the given user.
-**This endpoint allows you to retrieve the monthly email statistics for all subusers over the given date range.**
+**This endpoint allows you to retrieve all of the domain authentications that have been assigned to a specific subuser.**
-While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats for your subusers. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings.
+A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
-When using the `sort_by_metric` to sort your stats by a specific metric, you can not sort by the following metrics:
-`bounce_drops`, `deferred`, `invalid_emails`, `processed`, `spam_report_drops`, `spam_reports`, or `unsubscribe_drops`.
+Domain authentications can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's authenticated domains. To associate a domain authentication with a subuser, the parent account must first create the default authentication and validate it. The parent may then associate the default authentication via the subuser management tools.
-For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html).
+For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
-### GET /subusers/stats/monthly
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| username | string | Username of the subuser to find associated domain authentications for. |
+
+### GET /whitelabel/domains/subuser
```python
-params = {'subuser': 'test_string', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'date': 'test_string', 'sort_by_direction': 'asc'}
-response = sg.client.subusers.stats.monthly.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.whitelabel.domains.subuser.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve the totals for each email statistic metric for all subusers.
+## Disassociate a domain authentication from a given user.
-**This endpoint allows you to retrieve the total sums of each email statistic metric for all subusers over the given date range.**
+**This endpoint allows you to disassociate a specific default authentication from a subuser.**
+A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
-While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings.
+Domain authentications can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's authenticated domains. To associate a domain authentication with a subuser, the parent account must first create the default authentication and validate it. The parent may then associate the default authentication via the subuser management tools.
-For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html).
+For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
-### GET /subusers/stats/sums
+## URI Parameters
+| URI Parameter | Type | Required? | Description |
+|---|---|---|---|
+| username | string | required | Username for the subuser to find associated domain authentications for. |
+
+### DELETE /whitelabel/domains/subuser
```python
-params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'start_date': '2016-01-01', 'sort_by_direction': 'asc'}
-response = sg.client.subusers.stats.sums.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.whitelabel.domains.subuser.delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Enable/disable a subuser
+## Update a domain authentication.
-This endpoint allows you to enable or disable a subuser.
+**This endpoint allows you to update the settings for a domain authentication.**
-For more information about Subusers:
+A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
-* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
-* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html)
+For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
-### PATCH /subusers/{subuser_name}
+### PATCH /whitelabel/domains/{domain_id}
```python
data = {
- "disabled": False
+ "custom_spf": True,
+ "default": False
}
-subuser_name = "test_url_param"
-response = sg.client.subusers._(subuser_name).patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+domain_id = "test_url_param"
+response = sg.client.whitelabel.domains._(domain_id).patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete a subuser
+## Retrieve a domain authentication.
-This endpoint allows you to delete a subuser. This is a permanent action, once deleted a subuser cannot be retrieved.
+**This endpoint allows you to retrieve a specific domain authentication.**
-For more information about Subusers:
+A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
-* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
-* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html)
+For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
-### DELETE /subusers/{subuser_name}
+
+### GET /whitelabel/domains/{domain_id}
```python
-subuser_name = "test_url_param"
-response = sg.client.subusers._(subuser_name).delete()
-print response.status_code
-print response.body
-print response.headers
+domain_id = "test_url_param"
+response = sg.client.whitelabel.domains._(domain_id).get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update IPs assigned to a subuser
+## Delete a domain authentication.
-Each subuser should be assigned to an IP address, from which all of this subuser's mail will be sent. Often, this is the same IP as the parent account, but each subuser can have their own, or multiple, IP addresses as well.
+**This endpoint allows you to delete a domain authentication.**
-More information:
+A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
-* [How to request more IPs](https://sendgrid.com/docs/Classroom/Basics/Account/adding_an_additional_dedicated_ip_to_your_account.html)
-* [IPs can be whitelabeled](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/ips.html)
+For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
-### PUT /subusers/{subuser_name}/ips
+### DELETE /whitelabel/domains/{domain_id}
```python
-data = [
- "127.0.0.1"
-]
-subuser_name = "test_url_param"
-response = sg.client.subusers._(subuser_name).ips.put(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+domain_id = "test_url_param"
+response = sg.client.whitelabel.domains._(domain_id).delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update Monitor Settings for a subuser
+## Associate a domain authentication with a given user.
-Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails.
+**This endpoint allows you to associate a specific domain authentication with a subuser.**
-### PUT /subusers/{subuser_name}/monitor
+A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
+Domain authentications can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's authenticated domains. To associate a domain authentication with a subuser, the parent account must first create the default authentication and validate it. The parent may then associate the default authentication via the subuser management tools.
-```python
-data = {
- "email": "example@example.com",
- "frequency": 500
-}
-subuser_name = "test_url_param"
-response = sg.client.subusers._(subuser_name).monitor.put(request_body=data)
-print response.status_code
-print response.body
-print response.headers
-```
-## Create monitor settings
+For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
-Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails.
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| domain_id | integer | ID of the domain authentication to associate with the subuser. |
-### POST /subusers/{subuser_name}/monitor
+### POST /whitelabel/domains/{domain_id}/subuser
```python
data = {
- "email": "example@example.com",
- "frequency": 50000
+ "username": "jane@example.com"
}
-subuser_name = "test_url_param"
-response = sg.client.subusers._(subuser_name).monitor.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+domain_id = "test_url_param"
+response = sg.client.whitelabel.domains._(domain_id).subuser.post(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve monitor settings for a subuser
+## Add an IP to a domain authentication.
-Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails.
-
-### GET /subusers/{subuser_name}/monitor
+**This endpoint allows you to add an IP address to a domain authentication.**
+A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
-```python
-subuser_name = "test_url_param"
-response = sg.client.subusers._(subuser_name).monitor.get()
-print response.status_code
-print response.body
-print response.headers
-```
-## Delete monitor settings
+For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
-Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails.
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| id | integer | ID of the domain to which you are adding an IP |
-### DELETE /subusers/{subuser_name}/monitor
+### POST /whitelabel/domains/{id}/ips
```python
-subuser_name = "test_url_param"
-response = sg.client.subusers._(subuser_name).monitor.delete()
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "ip": "192.168.0.1"
+}
+id = "test_url_param"
+response = sg.client.whitelabel.domains._(id).ips.post(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve the monthly email statistics for a single subuser
+## Remove an IP from a domain authentication.
-**This endpoint allows you to retrive the monthly email statistics for a specific subuser.**
+**This endpoint allows you to remove a domain's IP address from that domain's authentication.**
-While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats for your subusers. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings.
+A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
-When using the `sort_by_metric` to sort your stats by a specific metric, you can not sort by the following metrics:
-`bounce_drops`, `deferred`, `invalid_emails`, `processed`, `spam_report_drops`, `spam_reports`, or `unsubscribe_drops`.
+For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
-For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html).
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| id | integer | ID of the domain authentication to delete the IP from. |
+| ip | string | IP to remove from the domain authentication. |
-### GET /subusers/{subuser_name}/stats/monthly
+### DELETE /whitelabel/domains/{id}/ips/{ip}
```python
-params = {'date': 'test_string', 'sort_by_direction': 'asc', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1}
-subuser_name = "test_url_param"
-response = sg.client.subusers._(subuser_name).stats.monthly.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+id = "test_url_param"
+ip = "test_url_param"
+response = sg.client.whitelabel.domains._(id).ips._(ip).delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-
-# SUPPRESSION
+## Validate a domain authentication.
-## Retrieve all blocks
+**This endpoint allows you to validate a domain authentication. If it fails, it will return an error message describing why the default authentication could not be validated.**
-**This endpoint allows you to retrieve a list of all email addresses that are currently on your blocks list.**
+A domain authentication allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Authenticating a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that Twilio SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, Twilio SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
-[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server.
+For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
-For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html).
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| id | integer |ID of the domain authentication to validate. |
-### GET /suppression/blocks
+### POST /whitelabel/domains/{id}/validate
```python
-params = {'start_time': 1, 'limit': 1, 'end_time': 1, 'offset': 1}
-response = sg.client.suppression.blocks.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+id = "test_url_param"
+response = sg.client.whitelabel.domains._(id).validate.post()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete blocks
-**This endpoint allows you to delete all email addresses on your blocks list.**
+## Create reverse DNS record
-There are two options for deleting blocked emails:
+**This endpoint allows you to create a reverse DNS record.**
-1. You can delete all blocked emails by setting `delete_all` to true in the request body.
-2. You can delete some blocked emails by specifying the email addresses in an array in the request body.
+When creating a reverse DNS record, you should use the same subdomain that you used when you created a domain authentication.
-[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server.
+Reverse DNS consists of a subdomain and domain that will be used to generate a record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
-For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-reverse-dns/).
-### DELETE /suppression/blocks
+### POST /whitelabel/ips
```python
data = {
- "delete_all": False,
- "emails": [
- "example1@example.com",
- "example2@example.com"
- ]
+ "domain": "example.com",
+ "ip": "192.168.1.1",
+ "subdomain": "email"
}
-response = sg.client.suppression.blocks.delete(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.whitelabel.ips.post(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve a specific block
-**This endpoint allows you to retrieve a specific email address from your blocks list.**
+## Retrieve all reverse DNS records
-[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server.
+**This endpoint allows you to retrieve all of the reverse DNS records that have been created by this account.**
-For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html).
+You may include a search key by using the "ip" parameter. This enables you to perform a prefix search for a given IP segment (e.g. "192.").
-### GET /suppression/blocks/{email}
+Reverse DNS consists of a subdomain and domain that will be used to generate a record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
+For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-reverse-dns/).
-```python
-email = "test_url_param"
-response = sg.client.suppression.blocks._(email).get()
-print response.status_code
-print response.body
-print response.headers
+### GET /whitelabel/ips
+
+
+```python
+params = {'ip': 'test_string', 'limit': 1, 'offset': 1}
+response = sg.client.whitelabel.ips.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete a specific block
+## Retrieve a reverse DNS record
-**This endpoint allows you to delete a specific email address from your blocks list.**
+**This endpoint allows you to retrieve a reverse DNS record.**
-[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server.
+A reverse DNS record consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
-For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
-### DELETE /suppression/blocks/{email}
+### GET /whitelabel/ips/{id}
```python
-email = "test_url_param"
-response = sg.client.suppression.blocks._(email).delete()
-print response.status_code
-print response.body
-print response.headers
+id = "test_url_param"
+response = sg.client.whitelabel.ips._(id).get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve all bounces
-
-**This endpoint allows you to retrieve all of your bounces.**
+## Delete a reverse DNS record
-Bounces are messages that are returned to the server that sent it.
+**This endpoint allows you to delete a reverse DNS record.**
-For more information see:
+A reverse DNS record consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
-* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information
-* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html)
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
-### GET /suppression/bounces
+### DELETE /whitelabel/ips/{id}
```python
-params = {'start_time': 1, 'end_time': 1}
-response = sg.client.suppression.bounces.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+id = "test_url_param"
+response = sg.client.whitelabel.ips._(id).delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete bounces
-
-**This endpoint allows you to delete all of your bounces. You can also use this endpoint to remove a specific email address from your bounce list.**
-
-Bounces are messages that are returned to the server that sent it.
+## Validate a reverse DNS record
-For more information see:
+**This endpoint allows you to validate a reverse DNS record.**
-* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information
-* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html)
-* [Classroom > List Scrubbing Guide](https://sendgrid.com/docs/Classroom/Deliver/list_scrubbing.html)
+A reverse DNS record consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once Twilio SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
-Note: the `delete_all` and `emails` parameters should be used independently of each other as they have different purposes.
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
-### DELETE /suppression/bounces
+### POST /whitelabel/ips/{id}/validate
```python
-data = {
- "delete_all": True,
- "emails": [
- "example@example.com",
- "example2@example.com"
- ]
-}
-response = sg.client.suppression.bounces.delete(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+id = "test_url_param"
+response = sg.client.whitelabel.ips._(id).validate.post()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve a Bounce
+## Create a Link Branding
-**This endpoint allows you to retrieve a specific bounce for a given email address.**
-
-Bounces are messages that are returned to the server that sent it.
+**This endpoint allows you to create a new link branding.**
-For more information see:
+Email link brandings allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
-* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information
-* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html)
-* [Classroom > List Scrubbing Guide](https://sendgrid.com/docs/Classroom/Deliver/list_scrubbing.html)
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
-### GET /suppression/bounces/{email}
+### POST /whitelabel/links
```python
-email = "test_url_param"
-response = sg.client.suppression.bounces._(email).get()
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "default": True,
+ "domain": "example.com",
+ "subdomain": "mail"
+}
+params = {'limit': 1, 'offset': 1}
+response = sg.client.whitelabel.links.post(request_body=data, query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete a bounce
+## Retrieve all link brandings
-**This endpoint allows you to remove an email address from your bounce list.**
-
-Bounces are messages that are returned to the server that sent it. This endpoint allows you to delete a single email addresses from your bounce list.
+**This endpoint allows you to retrieve all link brandings.**
-For more information see:
+Email link brandings allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
-* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information
-* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html)
-* [Classroom > List Scrubbing Guide](https://sendgrid.com/docs/Classroom/Deliver/list_scrubbing.html)
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
-### DELETE /suppression/bounces/{email}
+### GET /whitelabel/links
```python
-params = {'email_address': 'example@example.com'}
-email = "test_url_param"
-response = sg.client.suppression.bounces._(email).delete(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+params = {'limit': 1}
+response = sg.client.whitelabel.links.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve all invalid emails
+## Retrieve a Default Link Branding
-**This endpoint allows you to retrieve a list of all invalid email addresses.**
+**This endpoint allows you to retrieve the default link branding.**
-An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server.
+Default link branding is the actual link branding to be used when sending messages. If there are multiple link brandings, the default is determined by the following order:
+
+ - Validated link brandings marked as "default"
+ - Legacy link brands (migrated from the whitelabel wizard)
+ - Default Twilio SendGrid link branding (i.e. 100.ct.sendgrid.net)
+
-Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
+Email link brandings allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
-For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/invalid_emails.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
-### GET /suppression/invalid_emails
+### GET /whitelabel/links/default
```python
-params = {'start_time': 1, 'limit': 1, 'end_time': 1, 'offset': 1}
-response = sg.client.suppression.invalid_emails.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+params = {'domain': 'test_string'}
+response = sg.client.whitelabel.links.default.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete invalid emails
-
-**This endpoint allows you to remove email addresses from your invalid email address list.**
-
-There are two options for deleting invalid email addresses:
+## Retrieve Associated Link Branding
-1) You can delete all invalid email addresses by setting `delete_all` to true in the request body.
-2) You can delete some invalid email addresses by specifying certain addresses in an array in the request body.
+**This endpoint allows you to retrieve the associated link branding for a subuser.**
-An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server.
+Link whitelables can be associated with subusers from the parent account. This functionality allows
+subusers to send mail using their parent's link brandings. To associate a link branding, the parent account
+must first create a domain authentication and validate it. The parent may then associate that branded link with a subuser via the API or the Subuser Management page in the user interface.
-Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
+Email link brandings allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
-For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/invalid_emails.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
-### DELETE /suppression/invalid_emails
+### GET /whitelabel/links/subuser
```python
-data = {
- "delete_all": False,
- "emails": [
- "example1@example.com",
- "example2@example.com"
- ]
-}
-response = sg.client.suppression.invalid_emails.delete(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+params = {'username': 'test_string'}
+response = sg.client.whitelabel.links.subuser.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve a specific invalid email
+## Disassociate a Link Branding
-**This endpoint allows you to retrieve a specific invalid email addresses.**
+**This endpoint allows you to disassociate a link branding from a subuser.**
-An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server.
+Link whitelables can be associated with subusers from the parent account. This functionality allows
+subusers to send mail using their parent's link brandings. To associate a link branding, the parent account
+must first create a domain authentication and validate it. The parent may then associate that branded link with a subuser via the API or the Subuser Management page in the user interface.
-Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
+Email link brandings allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
-For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/invalid_emails.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
-### GET /suppression/invalid_emails/{email}
+### DELETE /whitelabel/links/subuser
```python
-email = "test_url_param"
-response = sg.client.suppression.invalid_emails._(email).get()
-print response.status_code
-print response.body
-print response.headers
+params = {'username': 'test_string'}
+response = sg.client.whitelabel.links.subuser.delete(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete a specific invalid email
-
-**This endpoint allows you to remove a specific email address from the invalid email address list.**
+## Update a Link Branding
-An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server.
+**This endpoint allows you to update a specific link branding. You can use this endpoint to change a link branding's default status.**
-Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
+Email link brandings allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
-For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/invalid_emails.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
-### DELETE /suppression/invalid_emails/{email}
+### PATCH /whitelabel/links/{id}
```python
-email = "test_url_param"
-response = sg.client.suppression.invalid_emails._(email).delete()
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "default": True
+}
+id = "test_url_param"
+response = sg.client.whitelabel.links._(id).patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve a specific spam report
+## Retrieve a Link Branding
-**This endpoint allows you to retrieve a specific spam report.**
+**This endpoint allows you to retrieve a specific link branding.**
-[Spam reports](https://sendgrid.com/docs/Glossary/spam_reports.html) happen when a recipient indicates that they think your email is [spam](https://sendgrid.com/docs/Glossary/spam.html) and then their email provider reports this to SendGrid.
+Email link brandings allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
-For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
-### GET /suppression/spam_report/{email}
+### GET /whitelabel/links/{id}
```python
-email = "test_url_param"
-response = sg.client.suppression.spam_report._(email).get()
-print response.status_code
-print response.body
-print response.headers
+id = "test_url_param"
+response = sg.client.whitelabel.links._(id).get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete a specific spam report
+## Delete a Link Branding
-**This endpoint allows you to delete a specific spam report.**
+**This endpoint allows you to delete a link branding.**
-[Spam reports](https://sendgrid.com/docs/Glossary/spam_reports.html) happen when a recipient indicates that they think your email is [spam](https://sendgrid.com/docs/Glossary/spam.html) and then their email provider reports this to SendGrid.
+Email link brandings allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
-For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
-### DELETE /suppression/spam_report/{email}
+### DELETE /whitelabel/links/{id}
```python
-email = "test_url_param"
-response = sg.client.suppression.spam_report._(email).delete()
-print response.status_code
-print response.body
-print response.headers
+id = "test_url_param"
+response = sg.client.whitelabel.links._(id).delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve all spam reports
+## Validate a Link Branding
-**This endpoint allows you to retrieve all spam reports.**
+**This endpoint allows you to validate a link branding.**
-[Spam reports](https://sendgrid.com/docs/Glossary/spam_reports.html) happen when a recipient indicates that they think your email is [spam](https://sendgrid.com/docs/Glossary/spam.html) and then their email provider reports this to SendGrid.
+Email link brandings allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
-For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
-### GET /suppression/spam_reports
+### POST /whitelabel/links/{id}/validate
```python
-params = {'start_time': 1, 'limit': 1, 'end_time': 1, 'offset': 1}
-response = sg.client.suppression.spam_reports.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+id = "test_url_param"
+response = sg.client.whitelabel.links._(id).validate.post()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete spam reports
+## Associate a Link Branding
-**This endpoint allows you to delete your spam reports.**
-
-There are two options for deleting spam reports:
+**This endpoint allows you to associate a link branding with a subuser account.**
-1) You can delete all spam reports by setting "delete_all" to true in the request body.
-2) You can delete some spam reports by specifying the email addresses in an array in the request body.
+Link whitelables can be associated with subusers from the parent account. This functionality allows
+subusers to send mail using their parent's link brandings. To associate a link branding, the parent account
+must first create a domain authentication and validate it. The parent may then associate that branded link with a subuser via the API or the Subuser Management page in the user interface.
-[Spam reports](https://sendgrid.com/docs/Glossary/spam_reports.html) happen when a recipient indicates that they think your email is [spam](https://sendgrid.com/docs/Glossary/spam.html) and then their email provider reports this to SendGrid.
+Email link brandings allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
-For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
-### DELETE /suppression/spam_reports
+### POST /whitelabel/links/{link_id}/subuser
```python
data = {
- "delete_all": False,
- "emails": [
- "example1@example.com",
- "example2@example.com"
- ]
+ "username": "jane@example.com"
}
-response = sg.client.suppression.spam_reports.delete(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+link_id = "test_url_param"
+response = sg.client.whitelabel.links._(link_id).subuser.post(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve all global suppressions
-**This endpoint allows you to retrieve a list of all email address that are globally suppressed.**
+
+# STATS
-A global suppression (or global unsubscribe) is an email address of a recipient who does not want to receive any of your messages. A globally suppressed recipient will be removed from any email you send. For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/global_unsubscribes.html).
+## Retrieve global email statistics
-### GET /suppression/unsubscribes
+**This endpoint allows you to retrieve all of your global email statistics between a given date range.**
+
+Parent accounts will see aggregated stats for their account and all subuser accounts. Subuser accounts will only see their own stats.
+
+### GET /stats
```python
-params = {'start_time': 1, 'limit': 1, 'end_time': 1, 'offset': 1}
-response = sg.client.suppression.unsubscribes.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+params = {'aggregated_by': 'day', 'limit': 1, 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 1}
+response = sg.client.stats.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-
-# TEMPLATES
+
+# SUBUSERS
-## Create a transactional template.
+## Create Subuser
-**This endpoint allows you to create a transactional template.**
+This endpoint allows you to retrieve a list of all of your subusers. You can choose to retrieve specific subusers as well as limit the results that come back from the API.
-Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
+For more information about Subusers:
-Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
+* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html)
-### POST /templates
+### POST /subusers
```python
data = {
- "name": "example_name"
+ "email": "John@example.com",
+ "ips": [
+ "1.1.1.1",
+ "2.2.2.2"
+ ],
+ "password": "johns_password",
+ "username": "John@example.com"
}
-response = sg.client.templates.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.subusers.post(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve all transactional templates.
-
-**This endpoint allows you to retrieve all transactional templates.**
+## List all Subusers
-Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
+This endpoint allows you to retrieve a list of all of your subusers. You can choose to retrieve specific subusers as well as limit the results that come back from the API.
-Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+For more information about Subusers:
-### GET /templates
+* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
+* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html)
+
+### GET /subusers
```python
-response = sg.client.templates.get()
-print response.status_code
-print response.body
-print response.headers
+params = {'username': 'test_string', 'limit': 1, 'offset': 1}
+response = sg.client.subusers.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Edit a transactional template.
-
-**This endpoint allows you to edit a transactional template.**
-
-Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
+## Retrieve Subuser Reputations
-Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+Subuser sender reputations give a good idea how well a sender is doing with regards to how recipients and recipient servers react to the mail that is being received. When a bounce, spam report, or other negative action happens on a sent email, it will effect your sender rating.
+This endpoint allows you to request the reputations for your subusers.
-### PATCH /templates/{template_id}
+### GET /subusers/reputations
```python
-data = {
- "name": "new_example_name"
-}
-template_id = "test_url_param"
-response = sg.client.templates._(template_id).patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+params = {'usernames': 'test_string'}
+response = sg.client.subusers.reputations.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve a single transactional template.
+## Retrieve email statistics for your subusers.
-**This endpoint allows you to retrieve a single transactional template.**
+**This endpoint allows you to retrieve the email statistics for the given subusers.**
-Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
+You may retrieve statistics for up to 10 different subusers by including an additional _subusers_ parameter for each additional subuser.
-Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings.
+For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html).
-### GET /templates/{template_id}
+### GET /subusers/stats
```python
-template_id = "test_url_param"
-response = sg.client.templates._(template_id).get()
-print response.status_code
-print response.body
-print response.headers
+params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01', 'subusers': 'test_string'}
+response = sg.client.subusers.stats.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete a template.
+## Retrieve monthly stats for all subusers
-**This endpoint allows you to delete a transactional template.**
+**This endpoint allows you to retrieve the monthly email statistics for all subusers over the given date range.**
-Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
+While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats for your subusers. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings.
-Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+When using the `sort_by_metric` to sort your stats by a specific metric, you can not sort by the following metrics:
+`bounce_drops`, `deferred`, `invalid_emails`, `processed`, `spam_report_drops`, `spam_reports`, or `unsubscribe_drops`.
+For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html).
-### DELETE /templates/{template_id}
+### GET /subusers/stats/monthly
```python
-template_id = "test_url_param"
-response = sg.client.templates._(template_id).delete()
-print response.status_code
-print response.body
-print response.headers
+params = {'subuser': 'test_string', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'date': 'test_string', 'sort_by_direction': 'asc'}
+response = sg.client.subusers.stats.monthly.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Create a new transactional template version.
+## Retrieve the totals for each email statistic metric for all subusers.
-**This endpoint allows you to create a new version of a template.**
+**This endpoint allows you to retrieve the total sums of each email statistic metric for all subusers over the given date range.**
-Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates.
-For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings.
+For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html).
-### POST /templates/{template_id}/versions
+### GET /subusers/stats/sums
```python
-data = {
- "active": 1,
- "html_content": "<%body%>",
- "name": "example_version_name",
- "plain_content": "<%body%>",
- "subject": "<%subject%>",
- "template_id": "ddb96bbc-9b92-425e-8979-99464621b543"
-}
-template_id = "test_url_param"
-response = sg.client.templates._(template_id).versions.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'start_date': '2016-01-01', 'sort_by_direction': 'asc'}
+response = sg.client.subusers.stats.sums.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Edit a transactional template version.
-
-**This endpoint allows you to edit a version of one of your transactional templates.**
+## Enable/disable a subuser
-Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates.
+This endpoint allows you to enable or disable a subuser.
-For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+For more information about Subusers:
-## URI Parameters
-| URI Parameter | Type | Description |
-|---|---|---|
-| template_id | string | The ID of the original template |
-| version_id | string | The ID of the template version |
+* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
+* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html)
-### PATCH /templates/{template_id}/versions/{version_id}
+### PATCH /subusers/{subuser_name}
```python
data = {
- "active": 1,
- "html_content": "<%body%>",
- "name": "updated_example_name",
- "plain_content": "<%body%>",
- "subject": "<%subject%>"
+ "disabled": False
}
-template_id = "test_url_param"
-version_id = "test_url_param"
-response = sg.client.templates._(template_id).versions._(version_id).patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+subuser_name = "test_url_param"
+response = sg.client.subusers._(subuser_name).patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve a specific transactional template version.
-
-**This endpoint allows you to retrieve a specific version of a template.**
+## Delete a subuser
-Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates.
+This endpoint allows you to delete a subuser. This is a permanent action, once you delete a subuser it cannot be retrieved.
-For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+For more information about Subusers:
-## URI Parameters
-| URI Parameter | Type | Description |
-|---|---|---|
-| template_id | string | The ID of the original template |
-| version_id | string | The ID of the template version |
+* [User Guide > Subusers](https://sendgrid.com/docs/User_Guide/Settings/Subusers/index.html)
+* [Classroom > How do I add more subusers to my account?](https://sendgrid.com/docs/Classroom/Basics/Account/how_do_i_add_more_subusers_to_my_account.html)
-### GET /templates/{template_id}/versions/{version_id}
+### DELETE /subusers/{subuser_name}
```python
-template_id = "test_url_param"
-version_id = "test_url_param"
-response = sg.client.templates._(template_id).versions._(version_id).get()
-print response.status_code
-print response.body
-print response.headers
+subuser_name = "test_url_param"
+response = sg.client.subusers._(subuser_name).delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete a transactional template version.
-
-**This endpoint allows you to delete one of your transactional template versions.**
+## Update IPs assigned to a subuser
-Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates.
+Each subuser should be assigned to an IP address, from which all of this subuser's mail will be sent. Often, this is the same IP as the parent account, but each subuser can have their own, or multiple, IP addresses as well.
-For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+More information:
-## URI Parameters
-| URI Parameter | Type | Description |
-|---|---|---|
-| template_id | string | The ID of the original template |
-| version_id | string | The ID of the template version |
+* [How to request more IPs](https://sendgrid.com/docs/Classroom/Basics/Account/adding_an_additional_dedicated_ip_to_your_account.html)
+* [How to set up reverse DNS](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-reverse-dns/)
-### DELETE /templates/{template_id}/versions/{version_id}
+### PUT /subusers/{subuser_name}/ips
```python
-template_id = "test_url_param"
-version_id = "test_url_param"
-response = sg.client.templates._(template_id).versions._(version_id).delete()
-print response.status_code
-print response.body
-print response.headers
+data = [
+ "127.0.0.1"
+]
+subuser_name = "test_url_param"
+response = sg.client.subusers._(subuser_name).ips.put(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Activate a transactional template version.
+## Update Monitor Settings for a subuser
-**This endpoint allows you to activate a version of one of your templates.**
+Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails.
-Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates.
+### PUT /subusers/{subuser_name}/monitor
-For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+```python
+data = {
+ "email": "example@example.com",
+ "frequency": 500
+}
+subuser_name = "test_url_param"
+response = sg.client.subusers._(subuser_name).monitor.put(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
+```
+## Create monitor settings
-## URI Parameters
-| URI Parameter | Type | Description |
-|---|---|---|
-| template_id | string | The ID of the original template |
-| version_id | string | The ID of the template version |
+Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails.
-### POST /templates/{template_id}/versions/{version_id}/activate
+### POST /subusers/{subuser_name}/monitor
```python
-template_id = "test_url_param"
-version_id = "test_url_param"
-response = sg.client.templates._(template_id).versions._(version_id).activate.post()
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "email": "example@example.com",
+ "frequency": 50000
+}
+subuser_name = "test_url_param"
+response = sg.client.subusers._(subuser_name).monitor.post(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-
-# TRACKING SETTINGS
+## Retrieve monitor settings for a subuser
-## Retrieve Tracking Settings
+Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails.
-**This endpoint allows you to retrieve a list of all tracking settings that you can enable on your account.**
+### GET /subusers/{subuser_name}/monitor
-You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
-For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+```python
+subuser_name = "test_url_param"
+response = sg.client.subusers._(subuser_name).monitor.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
+```
+## Delete monitor settings
-### GET /tracking_settings
+Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails.
+
+### DELETE /subusers/{subuser_name}/monitor
```python
-params = {'limit': 1, 'offset': 1}
-response = sg.client.tracking_settings.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+subuser_name = "test_url_param"
+response = sg.client.subusers._(subuser_name).monitor.delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update Click Tracking Settings
+## Retrieve the monthly email statistics for a single subuser
-**This endpoint allows you to change your current click tracking setting. You can enable, or disable, click tracking using this endpoint.**
+**This endpoint allows you to retrieve the monthly email statistics for a specific subuser.**
-You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+While you can always view the statistics for all email activity on your account, subuser statistics enable you to view specific segments of your stats for your subusers. Emails sent, bounces, and spam reports are always tracked for subusers. Unsubscribes, clicks, and opens are tracked if you have enabled the required settings.
-For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+When using the `sort_by_metric` to sort your stats by a specific metric, you can not sort by the following metrics:
+`bounce_drops`, `deferred`, `invalid_emails`, `processed`, `spam_report_drops`, `spam_reports`, or `unsubscribe_drops`.
-### PATCH /tracking_settings/click
+For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html).
+
+### GET /subusers/{subuser_name}/stats/monthly
```python
-data = {
- "enabled": True
-}
-response = sg.client.tracking_settings.click.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+params = {'date': 'test_string', 'sort_by_direction': 'asc', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1}
+subuser_name = "test_url_param"
+response = sg.client.subusers._(subuser_name).stats.monthly.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve Click Track Settings
+
+# SUPPRESSION
-**This endpoint allows you to retrieve your current click tracking setting.**
+## Retrieve all blocks
-You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+**This endpoint allows you to retrieve a list of all email addresses that are currently on your blocks list.**
-For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server.
-### GET /tracking_settings/click
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html).
+
+### GET /suppression/blocks
```python
-response = sg.client.tracking_settings.click.get()
-print response.status_code
-print response.body
-print response.headers
+params = {'start_time': 1, 'limit': 1, 'end_time': 1, 'offset': 1}
+response = sg.client.suppression.blocks.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update Google Analytics Settings
+## Delete blocks
-**This endpoint allows you to update your current setting for Google Analytics.**
+**This endpoint allows you to delete all email addresses on your blocks list.**
-For more information about using Google Analytics, please refer to [Googles URL Builder](https://support.google.com/analytics/answer/1033867?hl=en) and their article on ["Best Practices for Campaign Building"](https://support.google.com/analytics/answer/1037445).
+There are two options for deleting blocked emails:
-We default the settings to Googles recommendations. For more information, see [Google Analytics Demystified](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/google_analytics_demystified_ga_statistics_vs_sg_statistics.html).
+1. You can delete all blocked emails by setting `delete_all` to true in the request body.
+2. You can delete some blocked emails by specifying the email addresses in an array in the request body.
-You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server.
-For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html).
-### PATCH /tracking_settings/google_analytics
+### DELETE /suppression/blocks
```python
data = {
- "enabled": True,
- "utm_campaign": "website",
- "utm_content": "",
- "utm_medium": "email",
- "utm_source": "sendgrid.com",
- "utm_term": ""
+ "delete_all": False,
+ "emails": [
+ "example1@example.com",
+ "example2@example.com"
+ ]
}
-response = sg.client.tracking_settings.google_analytics.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.suppression.blocks.delete(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve Google Analytics Settings
+## Retrieve a specific block
-**This endpoint allows you to retrieve your current setting for Google Analytics.**
+**This endpoint allows you to retrieve a specific email address from your blocks list.**
-For more information about using Google Analytics, please refer to [Googles URL Builder](https://support.google.com/analytics/answer/1033867?hl=en) and their article on ["Best Practices for Campaign Building"](https://support.google.com/analytics/answer/1037445).
+[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server.
-We default the settings to Googles recommendations. For more information, see [Google Analytics Demystified](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/google_analytics_demystified_ga_statistics_vs_sg_statistics.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html).
-You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+### GET /suppression/blocks/{email}
-For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
-### GET /tracking_settings/google_analytics
+```python
+email = "test_url_param"
+response = sg.client.suppression.blocks._(email).get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
+```
+## Delete a specific block
+
+**This endpoint allows you to delete a specific email address from your blocks list.**
+
+[Blocks](https://sendgrid.com/docs/Glossary/blocks.html) happen when your message was rejected for a reason related to the message, not the recipient address. This can happen when your mail server IP address has been added to a blacklist or blocked by an ISP, or if the message content is flagged by a filter on the receiving server.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html).
+
+### DELETE /suppression/blocks/{email}
```python
-response = sg.client.tracking_settings.google_analytics.get()
-print response.status_code
-print response.body
-print response.headers
+email = "test_url_param"
+response = sg.client.suppression.blocks._(email).delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update Open Tracking Settings
+## Retrieve all bounces
-**This endpoint allows you to update your current settings for open tracking.**
+**This endpoint allows you to retrieve all of your bounces.**
-Open Tracking adds an invisible image at the end of the email which can track email opens. If the email recipient has images enabled on their email client, a request to SendGrids server for the invisible image is executed and an open event is logged. These events are logged in the Statistics portal, Email Activity interface, and are reported by the Event Webhook.
+Bounces are messages that are returned to the server that sent it.
-You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+For more information see:
-For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information
+* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html)
-### PATCH /tracking_settings/open
+### GET /suppression/bounces
+
+
+```python
+params = {'start_time': 1, 'end_time': 1}
+response = sg.client.suppression.bounces.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
+```
+## Delete bounces
+
+**This endpoint allows you to delete all of your bounces. You can also use this endpoint to remove a specific email address from your bounce list.**
+
+Bounces are messages that are returned to the server that sent it.
+
+For more information see:
+
+* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information
+* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html)
+* [Classroom > List Scrubbing Guide](https://sendgrid.com/docs/Classroom/Deliver/list_scrubbing.html)
+
+Note: the `delete_all` and `emails` parameters should be used independently of each other as they have different purposes.
+
+### DELETE /suppression/bounces
```python
data = {
- "enabled": True
+ "delete_all": True,
+ "emails": [
+ "example@example.com",
+ "example2@example.com"
+ ]
}
-response = sg.client.tracking_settings.open.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.suppression.bounces.delete(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Get Open Tracking Settings
+## Retrieve a Bounce
-**This endpoint allows you to retrieve your current settings for open tracking.**
+**This endpoint allows you to retrieve a specific bounce for a given email address.**
-Open Tracking adds an invisible image at the end of the email which can track email opens. If the email recipient has images enabled on their email client, a request to SendGrids server for the invisible image is executed and an open event is logged. These events are logged in the Statistics portal, Email Activity interface, and are reported by the Event Webhook.
+Bounces are messages that are returned to the server that sent it.
-You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+For more information see:
-For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information
+* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html)
+* [Classroom > List Scrubbing Guide](https://sendgrid.com/docs/Classroom/Deliver/list_scrubbing.html)
-### GET /tracking_settings/open
+### GET /suppression/bounces/{email}
```python
-response = sg.client.tracking_settings.open.get()
-print response.status_code
-print response.body
-print response.headers
+email = "test_url_param"
+response = sg.client.suppression.bounces._(email).get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update Subscription Tracking Settings
+## Delete a bounce
-**This endpoint allows you to update your current settings for subscription tracking.**
+**This endpoint allows you to remove an email address from your bounce list.**
-Subscription tracking adds links to the bottom of your emails that allows your recipients to subscribe to, or unsubscribe from, your emails.
+Bounces are messages that are returned to the server that sent it. This endpoint allows you to delete a single email address from your bounce list.
-You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+For more information see:
-For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+* [User Guide > Bounces](https://sendgrid.com/docs/User_Guide/Suppressions/bounces.html) for more information
+* [Glossary > Bounces](https://sendgrid.com/docs/Glossary/Bounces.html)
+* [Classroom > List Scrubbing Guide](https://sendgrid.com/docs/Classroom/Deliver/list_scrubbing.html)
-### PATCH /tracking_settings/subscription
+### DELETE /suppression/bounces/{email}
```python
-data = {
- "enabled": True,
- "html_content": "html content",
- "landing": "landing page html",
- "plain_content": "text content",
- "replace": "replacement tag",
- "url": "url"
-}
-response = sg.client.tracking_settings.subscription.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+params = {'email_address': 'example@example.com'}
+email = "test_url_param"
+response = sg.client.suppression.bounces._(email).delete(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve Subscription Tracking Settings
+## Retrieve all invalid emails
-**This endpoint allows you to retrieve your current settings for subscription tracking.**
+**This endpoint allows you to retrieve a list of all invalid email addresses.**
-Subscription tracking adds links to the bottom of your emails that allows your recipients to subscribe to, or unsubscribe from, your emails.
+An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server.
-You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
-For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/invalid_emails.html).
-### GET /tracking_settings/subscription
+### GET /suppression/invalid_emails
```python
-response = sg.client.tracking_settings.subscription.get()
-print response.status_code
-print response.body
-print response.headers
+params = {'start_time': 1, 'limit': 1, 'end_time': 1, 'offset': 1}
+response = sg.client.suppression.invalid_emails.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-
-# USER
+## Delete invalid emails
-## Get a user's account information.
+**This endpoint allows you to remove email addresses from your invalid email address list.**
-**This endpoint allows you to retrieve your user account details.**
+There are two options for deleting invalid email addresses:
-Your user's account information includes the user's account type and reputation.
+1) You can delete all invalid email addresses by setting `delete_all` to true in the request body.
+2) You can delete some invalid email addresses by specifying certain addresses in an array in the request body.
-Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server.
-For more information about your user profile:
+Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
-* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/invalid_emails.html).
-### GET /user/account
+### DELETE /suppression/invalid_emails
```python
-response = sg.client.user.account.get()
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "delete_all": False,
+ "emails": [
+ "example1@example.com",
+ "example2@example.com"
+ ]
+}
+response = sg.client.suppression.invalid_emails.delete(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve your credit balance
+## Retrieve a specific invalid email
-**This endpoint allows you to retrieve the current credit balance for your account.**
+**This endpoint allows you to retrieve a specific invalid email addresses.**
-Your monthly credit allotment limits the number of emails you may send before incurring overage charges. For more information about credits and billing, please visit our [Clssroom](https://sendgrid.com/docs/Classroom/Basics/Billing/billing_info_and_faqs.html).
+An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server.
-### GET /user/credits
+Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/invalid_emails.html).
+
+### GET /suppression/invalid_emails/{email}
```python
-response = sg.client.user.credits.get()
-print response.status_code
-print response.body
-print response.headers
+email = "test_url_param"
+response = sg.client.suppression.invalid_emails._(email).get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update your account email address
+## Delete a specific invalid email
-**This endpoint allows you to update the email address currently on file for your account.**
+**This endpoint allows you to remove a specific email address from the invalid email address list.**
-Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipients mail server.
-For more information about your user profile:
+Examples include addresses without the @ sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.
-* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/invalid_emails.html).
-### PUT /user/email
+### DELETE /suppression/invalid_emails/{email}
```python
-data = {
- "email": "example@example.com"
-}
-response = sg.client.user.email.put(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+email = "test_url_param"
+response = sg.client.suppression.invalid_emails._(email).delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve your account email address
+## Retrieve a specific spam report
-**This endpoint allows you to retrieve the email address currently on file for your account.**
+**This endpoint allows you to retrieve a specific spam report.**
+
+[Spam reports](https://sendgrid.com/docs/Glossary/spam_reports.html) happen when a recipient indicates that they think your email is [spam](https://sendgrid.com/docs/Glossary/spam.html) and then their email provider reports this to Twilio SendGrid.
+
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html).
+
+### GET /suppression/spam_report/{email}
+
+
+```python
+email = "test_url_param"
+response = sg.client.suppression.spam_report._(email).get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
+```
+## Delete a specific spam report
-Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+**This endpoint allows you to delete a specific spam report.**
-For more information about your user profile:
+[Spam reports](https://sendgrid.com/docs/Glossary/spam_reports.html) happen when a recipient indicates that they think your email is [spam](https://sendgrid.com/docs/Glossary/spam.html) and then their email provider reports this to Twilio SendGrid.
-* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html).
-### GET /user/email
+### DELETE /suppression/spam_report/{email}
```python
-response = sg.client.user.email.get()
-print response.status_code
-print response.body
-print response.headers
+email = "test_url_param"
+response = sg.client.suppression.spam_report._(email).delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update your password
-
-**This endpoint allows you to update your password.**
+## Retrieve all spam reports
-Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+**This endpoint allows you to retrieve all spam reports.**
-For more information about your user profile:
+[Spam reports](https://sendgrid.com/docs/Glossary/spam_reports.html) happen when a recipient indicates that they think your email is [spam](https://sendgrid.com/docs/Glossary/spam.html) and then their email provider reports this to Twilio SendGrid.
-* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html).
-### PUT /user/password
+### GET /suppression/spam_reports
```python
-data = {
- "new_password": "new_password",
- "old_password": "old_password"
-}
-response = sg.client.user.password.put(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+params = {'start_time': 1, 'limit': 1, 'end_time': 1, 'offset': 1}
+response = sg.client.suppression.spam_reports.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update a user's profile
+## Delete spam reports
-**This endpoint allows you to update your current profile details.**
+**This endpoint allows you to delete your spam reports.**
-Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+There are two options for deleting spam reports:
-For more information about your user profile:
+1) You can delete all spam reports by setting "delete_all" to true in the request body.
+2) You can delete some spam reports by specifying the email addresses in an array in the request body.
-* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+[Spam reports](https://sendgrid.com/docs/Glossary/spam_reports.html) happen when a recipient indicates that they think your email is [spam](https://sendgrid.com/docs/Glossary/spam.html) and then their email provider reports this to Twilio SendGrid.
-It should be noted that any one or more of the parameters can be updated via the PATCH /user/profile endpoint. The only requirement is that you include at least one when you PATCH.
+For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html).
-### PATCH /user/profile
+### DELETE /suppression/spam_reports
```python
data = {
- "city": "Orange",
- "first_name": "Example",
- "last_name": "User"
+ "delete_all": False,
+ "emails": [
+ "example1@example.com",
+ "example2@example.com"
+ ]
}
-response = sg.client.user.profile.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.suppression.spam_reports.delete(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Get a user's profile
-
-Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+## Retrieve all global suppressions
-For more information about your user profile:
+**This endpoint allows you to retrieve a list of all email address that are globally suppressed.**
-* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+A global suppression (or global unsubscribe) is an email address of a recipient who does not want to receive any of your messages. A globally suppressed recipient will be removed from any email you send. For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/global_unsubscribes.html).
-### GET /user/profile
+### GET /suppression/unsubscribes
```python
-response = sg.client.user.profile.get()
-print response.status_code
-print response.body
-print response.headers
+params = {'start_time': 1, 'limit': 1, 'end_time': 1, 'offset': 1}
+response = sg.client.suppression.unsubscribes.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Cancel or pause a scheduled send
+
+# TEMPLATES
-**This endpoint allows you to cancel or pause an email that has been scheduled to be sent.**
+## Create a transactional template.
-If the maximum number of cancellations/pauses are added, HTTP 400 will
-be returned.
+**This endpoint allows you to create a transactional template.**
-The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
+Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
-### POST /user/scheduled_sends
+Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+### POST /templates
```python
data = {
- "batch_id": "YOUR_BATCH_ID",
- "status": "pause"
+ "name": "example_name"
}
-response = sg.client.user.scheduled_sends.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.templates.post(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve all scheduled sends
+## Retrieve all transactional templates.
-**This endpoint allows you to retrieve all cancel/paused scheduled send information.**
+**This endpoint allows you to retrieve all transactional templates.**
-The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
+Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
-### GET /user/scheduled_sends
+Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+### GET /templates
```python
-response = sg.client.user.scheduled_sends.get()
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.templates.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update user scheduled send information
+## Edit a transactional template.
-**This endpoint allows you to update the status of a scheduled send for the given `batch_id`.**
+**This endpoint allows you to edit a transactional template.**
-The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
+Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
-### PATCH /user/scheduled_sends/{batch_id}
+Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
+
+
+### PATCH /templates/{template_id}
```python
data = {
- "status": "pause"
+ "name": "new_example_name"
}
-batch_id = "test_url_param"
-response = sg.client.user.scheduled_sends._(batch_id).patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+template_id = "test_url_param"
+response = sg.client.templates._(template_id).patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve scheduled send
-
-**This endpoint allows you to retrieve the cancel/paused scheduled send information for a specific `batch_id`.**
-
-The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
-
-### GET /user/scheduled_sends/{batch_id}
+## Retrieve a single transactional template.
+**This endpoint allows you to retrieve a single transactional template.**
-```python
-batch_id = "test_url_param"
-response = sg.client.user.scheduled_sends._(batch_id).get()
-print response.status_code
-print response.body
-print response.headers
-```
-## Delete a cancellation or pause of a scheduled send
+Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
-**This endpoint allows you to delete the cancellation/pause of a scheduled send.**
+Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
-The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
-### DELETE /user/scheduled_sends/{batch_id}
+### GET /templates/{template_id}
```python
-batch_id = "test_url_param"
-response = sg.client.user.scheduled_sends._(batch_id).delete()
-print response.status_code
-print response.body
-print response.headers
+template_id = "test_url_param"
+response = sg.client.templates._(template_id).get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update Enforced TLS settings
+## Delete a template.
-**This endpoint allows you to update your current Enforced TLS settings.**
+**This endpoint allows you to delete a transactional template.**
-The Enforced TLS settings specify whether or not the recipient is required to support TLS or have a valid certificate. See the [SMTP Ports User Guide](https://sendgrid.com/docs/Classroom/Basics/Email_Infrastructure/smtp_ports.html) for more information on opportunistic TLS.
+Each user can create up to 300 different transactional templates. Transactional templates are specific to accounts and subusers. Templates created on a parent account will not be accessible from the subuser accounts.
-**Note:** If either setting is enabled and the recipient does not support TLS or have a valid certificate, we drop the message and send a block event with TLS required but not supported as the description.
+Transactional templates are templates created specifically for transactional email and are not to be confused with [Marketing Campaigns templates](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/templates.html). For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
-### PATCH /user/settings/enforced_tls
+
+### DELETE /templates/{template_id}
```python
-data = {
- "require_tls": True,
- "require_valid_cert": False
-}
-response = sg.client.user.settings.enforced_tls.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+template_id = "test_url_param"
+response = sg.client.templates._(template_id).delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve current Enforced TLS settings.
+## Create a new transactional template version.
-**This endpoint allows you to retrieve your current Enforced TLS settings.**
+**This endpoint allows you to create a new version of a template.**
-The Enforced TLS settings specify whether or not the recipient is required to support TLS or have a valid certificate. See the [SMTP Ports User Guide](https://sendgrid.com/docs/Classroom/Basics/Email_Infrastructure/smtp_ports.html) for more information on opportunistic TLS.
+Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates.
-**Note:** If either setting is enabled and the recipient does not support TLS or have a valid certificate, we drop the message and send a block event with TLS required but not supported as the description.
+For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
-### GET /user/settings/enforced_tls
+
+### POST /templates/{template_id}/versions
```python
-response = sg.client.user.settings.enforced_tls.get()
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "active": 1,
+ "html_content": "<%body%>",
+ "name": "example_version_name",
+ "plain_content": "<%body%>",
+ "subject": "<%subject%>",
+ "template_id": "ddb96bbc-9b92-425e-8979-99464621b543"
+}
+template_id = "test_url_param"
+response = sg.client.templates._(template_id).versions.post(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update your username
+## Edit a transactional template version.
-**This endpoint allows you to update the username for your account.**
+**This endpoint allows you to edit a version of one of your transactional templates.**
-Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates.
-For more information about your user profile:
+For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
-* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| template_id | string | The ID of the original template |
+| version_id | string | The ID of the template version |
-### PUT /user/username
+### PATCH /templates/{template_id}/versions/{version_id}
```python
data = {
- "username": "test_username"
+ "active": 1,
+ "html_content": "<%body%>",
+ "name": "updated_example_name",
+ "plain_content": "<%body%>",
+ "subject": "<%subject%>"
}
-response = sg.client.user.username.put(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+template_id = "test_url_param"
+version_id = "test_url_param"
+response = sg.client.templates._(template_id).versions._(version_id).patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve your username
+## Retrieve a specific transactional template version.
-**This endpoint allows you to retrieve your current account username.**
+**This endpoint allows you to retrieve a specific version of a template.**
-Keeping your user profile up to date is important. This will help SendGrid to verify who you are as well as contact you should we need to.
+Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates.
-For more information about your user profile:
+For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
-* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| template_id | string | The ID of the original template |
+| version_id | string | The ID of the template version |
-### GET /user/username
+### GET /templates/{template_id}/versions/{version_id}
```python
-response = sg.client.user.username.get()
-print response.status_code
-print response.body
-print response.headers
+template_id = "test_url_param"
+version_id = "test_url_param"
+response = sg.client.templates._(template_id).versions._(version_id).get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update Event Notification Settings
+## Delete a transactional template version.
-**This endpoint allows you to update your current event webhook settings.**
+**This endpoint allows you to delete one of your transactional template versions.**
-If an event type is marked as `true`, then the event webhook will include information about that event.
+Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates.
-SendGrids Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as SendGrid processes your email.
+For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
-Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program.
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| template_id | string | The ID of the original template |
+| version_id | string | The ID of the template version |
-### PATCH /user/webhooks/event/settings
+### DELETE /templates/{template_id}/versions/{version_id}
```python
-data = {
- "bounce": True,
- "click": True,
- "deferred": True,
- "delivered": True,
- "dropped": True,
- "enabled": True,
- "group_resubscribe": True,
- "group_unsubscribe": True,
- "open": True,
- "processed": True,
- "spam_report": True,
- "unsubscribe": True,
- "url": "url"
-}
-response = sg.client.user.webhooks.event.settings.patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+template_id = "test_url_param"
+version_id = "test_url_param"
+response = sg.client.templates._(template_id).versions._(version_id).delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve Event Webhook settings
+## Activate a transactional template version.
+
+**This endpoint allows you to activate a version of one of your templates.**
-**This endpoint allows you to retrieve your current event webhook settings.**
+Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across across all templates.
-If an event type is marked as `true`, then the event webhook will include information about that event.
-SendGrids Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as SendGrid processes your email.
+For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html).
-Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program.
+## URI Parameters
+| URI Parameter | Type | Description |
+|---|---|---|
+| template_id | string | The ID of the original template |
+| version_id | string | The ID of the template version |
-### GET /user/webhooks/event/settings
+### POST /templates/{template_id}/versions/{version_id}/activate
```python
-response = sg.client.user.webhooks.event.settings.get()
-print response.status_code
-print response.body
-print response.headers
+template_id = "test_url_param"
+version_id = "test_url_param"
+response = sg.client.templates._(template_id).versions._(version_id).activate.post()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Test Event Notification Settings
+
+# TRACKING SETTINGS
-**This endpoint allows you to test your event webhook by sending a fake event notification post to the provided URL.**
+## Retrieve Tracking Settings
-SendGrids Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as SendGrid processes your email.
+**This endpoint allows you to retrieve a list of all tracking settings that you can enable on your account.**
-Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program.
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
-### POST /user/webhooks/event/test
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### GET /tracking_settings
```python
-data = {
- "url": "url"
-}
-response = sg.client.user.webhooks.event.test.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+params = {'limit': 1, 'offset': 1}
+response = sg.client.tracking_settings.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Create a parse setting
+## Update Click Tracking Settings
-**This endpoint allows you to create a new inbound parse setting.**
+**This endpoint allows you to change your current click tracking setting. You can enable, or disable, click tracking using this endpoint.**
-The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the content, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html).
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
-### POST /user/webhooks/parse/settings
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### PATCH /tracking_settings/click
```python
data = {
- "hostname": "myhostname.com",
- "send_raw": False,
- "spam_check": True,
- "url": "http://email.myhosthame.com"
+ "enabled": True
}
-response = sg.client.user.webhooks.parse.settings.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.tracking_settings.click.patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve all parse settings
+## Retrieve Click Track Settings
-**This endpoint allows you to retrieve all of your current inbound parse settings.**
+**This endpoint allows you to retrieve your current click tracking setting.**
-The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the contnet, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html).
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
-### GET /user/webhooks/parse/settings
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### GET /tracking_settings/click
```python
-response = sg.client.user.webhooks.parse.settings.get()
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.tracking_settings.click.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update a parse setting
+## Update Google Analytics Settings
-**This endpoint allows you to update a specific inbound parse setting.**
+**This endpoint allows you to update your current setting for Google Analytics.**
-The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the contnet, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html).
+For more information about using Google Analytics, please refer to [Googles URL Builder](https://support.google.com/analytics/answer/1033867?hl=en) and their article on ["Best Practices for Campaign Building"](https://support.google.com/analytics/answer/1037445).
-### PATCH /user/webhooks/parse/settings/{hostname}
+We default the settings to Googles recommendations. For more information, see [Google Analytics Demystified](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/google_analytics_demystified_ga_statistics_vs_sg_statistics.html).
+
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
+
+### PATCH /tracking_settings/google_analytics
```python
data = {
- "send_raw": True,
- "spam_check": False,
- "url": "http://newdomain.com/parse"
+ "enabled": True,
+ "utm_campaign": "website",
+ "utm_content": "",
+ "utm_medium": "email",
+ "utm_source": "sendgrid.com",
+ "utm_term": ""
}
-hostname = "test_url_param"
-response = sg.client.user.webhooks.parse.settings._(hostname).patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.tracking_settings.google_analytics.patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve a specific parse setting
-
-**This endpoint allows you to retrieve a specific inbound parse setting.**
-
-The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the contnet, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html).
+## Retrieve Google Analytics Settings
-### GET /user/webhooks/parse/settings/{hostname}
+**This endpoint allows you to retrieve your current setting for Google Analytics.**
+For more information about using Google Analytics, please refer to [Googles URL Builder](https://support.google.com/analytics/answer/1033867?hl=en) and their article on ["Best Practices for Campaign Building"](https://support.google.com/analytics/answer/1037445).
-```python
-hostname = "test_url_param"
-response = sg.client.user.webhooks.parse.settings._(hostname).get()
-print response.status_code
-print response.body
-print response.headers
-```
-## Delete a parse setting
+We default the settings to Googles recommendations. For more information, see [Google Analytics Demystified](https://sendgrid.com/docs/Classroom/Track/Collecting_Data/google_analytics_demystified_ga_statistics_vs_sg_statistics.html).
-**This endpoint allows you to delete a specific inbound parse setting.**
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
-The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the contnet, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html).
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
-### DELETE /user/webhooks/parse/settings/{hostname}
+### GET /tracking_settings/google_analytics
```python
-hostname = "test_url_param"
-response = sg.client.user.webhooks.parse.settings._(hostname).delete()
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.tracking_settings.google_analytics.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieves Inbound Parse Webhook statistics.
+## Update Open Tracking Settings
+
+**This endpoint allows you to update your current settings for open tracking.**
-**This endpoint allows you to retrieve the statistics for your Parse Webhook useage.**
+Open Tracking adds an invisible image at the end of the email which can track email opens. If the email recipient has images enabled on their email client, a request to SendGrids server for the invisible image is executed and an open event is logged. These events are logged in the Statistics portal, Email Activity interface, and are reported by the Event Webhook.
-SendGrid's Inbound Parse Webhook allows you to parse the contents and attachments of incomming emails. The Parse API can then POST the parsed emails to a URL that you specify. The Inbound Parse Webhook cannot parse messages greater than 20MB in size, including all attachments.
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
-There are a number of pre-made integrations for the SendGrid Parse Webhook which make processing events easy. You can find these integrations in the [Library Index](https://sendgrid.com/docs/Integrate/libraries.html#-Webhook-Libraries).
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
-### GET /user/webhooks/parse/stats
+### PATCH /tracking_settings/open
```python
-params = {'aggregated_by': 'day', 'limit': 'test_string', 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 'test_string'}
-response = sg.client.user.webhooks.parse.stats.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "enabled": True
+}
+response = sg.client.tracking_settings.open.patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-
-# WHITELABEL
-
-## Create a domain whitelabel.
+## Get Open Tracking Settings
-**This endpoint allows you to create a whitelabel for one of your domains.**
+**This endpoint allows you to retrieve your current settings for open tracking.**
-If you are creating a domain whitelabel that you would like a subuser to use, you have two options:
-1. Use the "username" parameter. This allows you to create a whitelabel on behalf of your subuser. This means the subuser is able to see and modify the created whitelabel.
-2. Use the Association workflow (see Associate Domain section). This allows you to assign a whitelabel created by the parent to a subuser. This means the subuser will default to the assigned whitelabel, but will not be able to see or modify that whitelabel. However, if the subuser creates their own whitelabel it will overwrite the assigned whitelabel.
+Open Tracking adds an invisible image at the end of the email which can track email opens. If the email recipient has images enabled on their email client, a request to SendGrids server for the invisible image is executed and an open event is logged. These events are logged in the Statistics portal, Email Activity interface, and are reported by the Event Webhook.
-A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
-For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
-### POST /whitelabel/domains
+### GET /tracking_settings/open
```python
-data = {
- "automatic_security": False,
- "custom_spf": True,
- "default": True,
- "domain": "example.com",
- "ips": [
- "192.168.1.1",
- "192.168.1.2"
- ],
- "subdomain": "news",
- "username": "john@example.com"
-}
-response = sg.client.whitelabel.domains.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.tracking_settings.open.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## List all domain whitelabels.
+## Update Subscription Tracking Settings
-**This endpoint allows you to retrieve a list of all domain whitelabels you have created.**
+**This endpoint allows you to update your current settings for subscription tracking.**
-A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
+Subscription tracking adds links to the bottom of your emails that allows your recipients to subscribe to, or unsubscribe from, your emails.
-For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
-### GET /whitelabel/domains
+### PATCH /tracking_settings/subscription
```python
-params = {'username': 'test_string', 'domain': 'test_string', 'exclude_subusers': 'true', 'limit': 1, 'offset': 1}
-response = sg.client.whitelabel.domains.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "enabled": True,
+ "html_content": "html content",
+ "landing": "landing page html",
+ "plain_content": "text content",
+ "replace": "replacement tag",
+ "url": "url"
+}
+response = sg.client.tracking_settings.subscription.patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Get the default domain whitelabel.
+## Retrieve Subscription Tracking Settings
-**This endpoint allows you to retrieve the default whitelabel for a domain.**
+**This endpoint allows you to retrieve your current settings for subscription tracking.**
-A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
+Subscription tracking adds links to the bottom of your emails that allows your recipients to subscribe to, or unsubscribe from, your emails.
-For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+You can track a variety of the actions your recipients may take when interacting with your emails including opening your emails, clicking on links in your emails, and subscribing to (or unsubscribing from) your emails.
-## URI Parameters
-| URI Parameter | Type | Description |
-|---|---|---|
-| domain | string |The domain to find a default domain whitelabel for. |
+For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html).
-### GET /whitelabel/domains/default
+### GET /tracking_settings/subscription
```python
-response = sg.client.whitelabel.domains.default.get()
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.tracking_settings.subscription.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## List the domain whitelabel associated with the given user.
+
+# USER
-**This endpoint allows you to retrieve all of the whitelabels that have been assigned to a specific subuser.**
+## Get a user's account information.
-A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
+**This endpoint allows you to retrieve your user account details.**
-Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The the parent may then associate the whitelabel via the subuser management tools.
+Your user's account information includes the user's account type and reputation.
-For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+Keeping your user profile up to date is important. This will help Twilio SendGrid to verify who you are as well as contact you should we need to.
-## URI Parameters
-| URI Parameter | Type | Description |
-|---|---|---|
-| username | string | Username of the subuser to find associated whitelabels for. |
+For more information about your user profile:
-### GET /whitelabel/domains/subuser
+* [Twilio SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+
+### GET /user/account
```python
-response = sg.client.whitelabel.domains.subuser.get()
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.account.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Disassociate a domain whitelabel from a given user.
-
-**This endpoint allows you to disassociate a specific whitelabel from a subuser.**
-
-A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
-
-Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The the parent may then associate the whitelabel via the subuser management tools.
+## Retrieve your credit balance
-For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+**This endpoint allows you to retrieve the current credit balance for your account.**
-## URI Parameters
-| URI Parameter | Type | Required? | Description |
-|---|---|---|---|
-| username | string | required | Username for the subuser to find associated whitelabels for. |
+Your monthly credit allotment limits the number of emails you may send before incurring overage charges. For more information about credits and billing, please visit our [Classroom](https://sendgrid.com/docs/Classroom/Basics/Billing/billing_info_and_faqs.html).
-### DELETE /whitelabel/domains/subuser
+### GET /user/credits
```python
-response = sg.client.whitelabel.domains.subuser.delete()
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.credits.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update a domain whitelabel.
+## Update your account email address
-**This endpoint allows you to update the settings for a domain whitelabel.**
+**This endpoint allows you to update the email address currently on file for your account.**
-A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
+Keeping your user profile up to date is important. This will help Twilio SendGrid to verify who you are as well as contact you should we need to.
-For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+For more information about your user profile:
-### PATCH /whitelabel/domains/{domain_id}
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+
+### PUT /user/email
```python
data = {
- "custom_spf": True,
- "default": False
+ "email": "example@example.com"
}
-domain_id = "test_url_param"
-response = sg.client.whitelabel.domains._(domain_id).patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.email.put(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve a domain whitelabel.
+## Retrieve your account email address
-**This endpoint allows you to retrieve a specific domain whitelabel.**
+**This endpoint allows you to retrieve the email address currently on file for your account.**
-A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
+Keeping your user profile up to date is important. This will help Twilio SendGrid to verify who you are as well as contact you should we need to.
-For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+For more information about your user profile:
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
-### GET /whitelabel/domains/{domain_id}
+### GET /user/email
```python
-domain_id = "test_url_param"
-response = sg.client.whitelabel.domains._(domain_id).get()
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.email.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete a domain whitelabel.
+## Update your password
+
+**This endpoint allows you to update your password.**
-**This endpoint allows you to delete a domain whitelabel.**
+Keeping your user profile up to date is important. This will help Twilio SendGrid to verify who you are as well as contact you should we need to.
-A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
+For more information about your user profile:
-For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
-### DELETE /whitelabel/domains/{domain_id}
+### PUT /user/password
```python
-domain_id = "test_url_param"
-response = sg.client.whitelabel.domains._(domain_id).delete()
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "new_password": "new_password",
+ "old_password": "old_password"
+}
+response = sg.client.user.password.put(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Associate a domain whitelabel with a given user.
+## Update a user's profile
-**This endpoint allows you to associate a specific domain whitelabel with a subuser.**
+**This endpoint allows you to update your current profile details.**
-A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
+Keeping your user profile up to date is important. This will help Twilio SendGrid to verify who you are as well as contact you should we need to.
-Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The the parent may then associate the whitelabel via the subuser management tools.
+For more information about your user profile:
-For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
-## URI Parameters
-| URI Parameter | Type | Description |
-|---|---|---|
-| domain_id | integer | ID of the domain whitelabel to associate with the subuser. |
+It should be noted that any one or more of the parameters can be updated via the PATCH /user/profile endpoint. The only requirement is that you include at least one when you PATCH.
-### POST /whitelabel/domains/{domain_id}/subuser
+### PATCH /user/profile
```python
data = {
- "username": "jane@example.com"
+ "city": "Orange",
+ "first_name": "Example",
+ "last_name": "User"
}
-domain_id = "test_url_param"
-response = sg.client.whitelabel.domains._(domain_id).subuser.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.profile.patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Add an IP to a domain whitelabel.
-
-**This endpoint allows you to add an IP address to a domain whitelabel.**
+## Get a user's profile
-A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
+Keeping your user profile up to date is important. This will help Twilio SendGrid to verify who you are as well as contact you should we need to.
-For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+For more information about your user profile:
-## URI Parameters
-| URI Parameter | Type | Description |
-|---|---|---|
-| id | integer | ID of the domain to which you are adding an IP |
+* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
-### POST /whitelabel/domains/{id}/ips
+### GET /user/profile
```python
-data = {
- "ip": "192.168.0.1"
-}
-id = "test_url_param"
-response = sg.client.whitelabel.domains._(id).ips.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.profile.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Remove an IP from a domain whitelabel.
-
-**This endpoint allows you to remove a domain's IP address from that domain's whitelabel.**
+## Cancel or pause a scheduled send
-A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
+**This endpoint allows you to cancel or pause an email that has been scheduled to be sent.**
-For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+If the maximum number of cancellations/pauses are added, HTTP 400 will
+be returned.
-## URI Parameters
-| URI Parameter | Type | Description |
-|---|---|---|
-| id | integer | ID of the domain whitelabel to delete the IP from. |
-| ip | string | IP to remove from the domain whitelabel. |
+The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
-### DELETE /whitelabel/domains/{id}/ips/{ip}
+### POST /user/scheduled_sends
```python
-id = "test_url_param"
-ip = "test_url_param"
-response = sg.client.whitelabel.domains._(id).ips._(ip).delete()
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "batch_id": "YOUR_BATCH_ID",
+ "status": "pause"
+}
+response = sg.client.user.scheduled_sends.post(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Validate a domain whitelabel.
-
-**This endpoint allows you to validate a domain whitelabel. If it fails, it will return an error message describing why the whitelabel could not be validated.**
-
-A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.
+## Retrieve all scheduled sends
-For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)
+**This endpoint allows you to retrieve all cancel/paused scheduled send information.**
-## URI Parameters
-| URI Parameter | Type | Description |
-|---|---|---|
-| id | integer |ID of the domain whitelabel to validate. |
+The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
-### POST /whitelabel/domains/{id}/validate
+### GET /user/scheduled_sends
```python
-id = "test_url_param"
-response = sg.client.whitelabel.domains._(id).validate.post()
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.scheduled_sends.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Create an IP whitelabel
-
-**This endpoint allows you to create an IP whitelabel.**
-
-When creating an IP whitelable, you should use the same subdomain that you used when you created a domain whitelabel.
+## Update user scheduled send information
-A IP whitelabel consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
+**This endpoint allows you to update the status of a scheduled send for the given `batch_id`.**
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
+The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
-### POST /whitelabel/ips
+### PATCH /user/scheduled_sends/{batch_id}
```python
data = {
- "domain": "example.com",
- "ip": "192.168.1.1",
- "subdomain": "email"
+ "status": "pause"
}
-response = sg.client.whitelabel.ips.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+batch_id = "test_url_param"
+response = sg.client.user.scheduled_sends._(batch_id).patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve all IP whitelabels
-
-**This endpoint allows you to retrieve all of the IP whitelabels that have been createdy by this account.**
-
-You may include a search key by using the "ip" parameter. This enables you to perform a prefix search for a given IP segment (e.g. "192.").
+## Retrieve scheduled send
-A IP whitelabel consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
+**This endpoint allows you to retrieve the cancel/paused scheduled send information for a specific `batch_id`.**
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
+The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
-### GET /whitelabel/ips
+### GET /user/scheduled_sends/{batch_id}
```python
-params = {'ip': 'test_string', 'limit': 1, 'offset': 1}
-response = sg.client.whitelabel.ips.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+batch_id = "test_url_param"
+response = sg.client.user.scheduled_sends._(batch_id).get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve an IP whitelabel
-
-**This endpoint allows you to retrieve an IP whitelabel.**
+## Delete a cancellation or pause of a scheduled send
-A IP whitelabel consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
+**This endpoint allows you to delete the cancellation/pause of a scheduled send.**
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
+The Cancel Scheduled Sends feature allows the customer to cancel a scheduled send based on a Batch ID included in the SMTPAPI header.Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
-### GET /whitelabel/ips/{id}
+### DELETE /user/scheduled_sends/{batch_id}
```python
-id = "test_url_param"
-response = sg.client.whitelabel.ips._(id).get()
-print response.status_code
-print response.body
-print response.headers
+batch_id = "test_url_param"
+response = sg.client.user.scheduled_sends._(batch_id).delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete an IP whitelabel
+## Update Enforced TLS settings
-**This endpoint allows you to delete an IP whitelabel.**
+**This endpoint allows you to update your current Enforced TLS settings.**
-A IP whitelabel consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
+The Enforced TLS settings specify whether or not the recipient is required to support TLS or have a valid certificate. See the [SMTP Ports User Guide](https://sendgrid.com/docs/Classroom/Basics/Email_Infrastructure/smtp_ports.html) for more information on opportunistic TLS.
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
+**Note:** If either setting is enabled and the recipient does not support TLS or have a valid certificate, we drop the message and send a block event with TLS required but not supported as the description.
-### DELETE /whitelabel/ips/{id}
+### PATCH /user/settings/enforced_tls
```python
-id = "test_url_param"
-response = sg.client.whitelabel.ips._(id).delete()
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "require_tls": True,
+ "require_valid_cert": False
+}
+response = sg.client.user.settings.enforced_tls.patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Validate an IP whitelabel
+## Retrieve current Enforced TLS settings.
-**This endpoint allows you to validate an IP whitelabel.**
+**This endpoint allows you to retrieve your current Enforced TLS settings.**
-A IP whitelabel consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP. Once SendGrid has verified that the appropriate A record for the IP has been created, the appropriate reverse DNS record for the IP is generated.
+The Enforced TLS settings specify whether or not the recipient is required to support TLS or have a valid certificate. See the [SMTP Ports User Guide](https://sendgrid.com/docs/Classroom/Basics/Email_Infrastructure/smtp_ports.html) for more information on opportunistic TLS.
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/ips.html).
+**Note:** If either setting is enabled and the recipient does not support TLS or have a valid certificate, we drop the message and send a block event with TLS required but not supported as the description.
-### POST /whitelabel/ips/{id}/validate
+### GET /user/settings/enforced_tls
```python
-id = "test_url_param"
-response = sg.client.whitelabel.ips._(id).validate.post()
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.settings.enforced_tls.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Create a Link Whitelabel
+## Update your username
-**This endpoint allows you to create a new link whitelabel.**
+**This endpoint allows you to update the username for your account.**
-Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
+Keeping your user profile up to date is important. This will help Twilio SendGrid to verify who you are as well as contact you should we need to.
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+For more information about your user profile:
-### POST /whitelabel/links
+* [Twilio SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
+
+### PUT /user/username
```python
data = {
- "default": True,
- "domain": "example.com",
- "subdomain": "mail"
+ "username": "test_username"
}
-params = {'limit': 1, 'offset': 1}
-response = sg.client.whitelabel.links.post(request_body=data, query_params=params)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.username.put(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve all link whitelabels
+## Retrieve your username
+
+**This endpoint allows you to retrieve your current account username.**
-**This endpoint allows you to retrieve all link whitelabels.**
+Keeping your user profile up to date is important. This will help Twilio SendGrid to verify who you are as well as contact you should we need to.
-Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
+For more information about your user profile:
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+* [Twilio SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html)
-### GET /whitelabel/links
+### GET /user/username
```python
-params = {'limit': 1}
-response = sg.client.whitelabel.links.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.username.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve a Default Link Whitelabel
+## Update Event Notification Settings
-**This endpoint allows you to retrieve the default link whitelabel.**
+**This endpoint allows you to update your current event webhook settings.**
-Default link whitelabel is the actual link whitelabel to be used when sending messages. If there are multiple link whitelabels, the default is determined by the following order:
-
- - Validated link whitelabels marked as "default"
- - Legacy link whitelabels (migrated from the whitelabel wizard)
- - Default SendGrid link whitelabel (i.e. 100.ct.sendgrid.net)
-
+If an event type is marked as `true`, then the event webhook will include information about that event.
-Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
+Twilio SendGrid's Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as Twilio SendGrid processes your email.
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program.
-### GET /whitelabel/links/default
+### PATCH /user/webhooks/event/settings
```python
-params = {'domain': 'test_string'}
-response = sg.client.whitelabel.links.default.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "bounce": True,
+ "click": True,
+ "deferred": True,
+ "delivered": True,
+ "dropped": True,
+ "enabled": True,
+ "group_resubscribe": True,
+ "group_unsubscribe": True,
+ "open": True,
+ "processed": True,
+ "spam_report": True,
+ "unsubscribe": True,
+ "url": "url"
+}
+response = sg.client.user.webhooks.event.settings.patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve Associated Link Whitelabel
+## Retrieve Event Webhook settings
-**This endpoint allows you to retrieve the associated link whitelabel for a subuser.**
+**This endpoint allows you to retrieve your current event webhook settings.**
-Link whitelables can be associated with subusers from the parent account. This functionality allows
-subusers to send mail using their parent's linke whitelabels. To associate a link whitelabel, the parent account
-must first create a whitelabel and validate it. The parent may then associate that whitelabel with a subuser via the API or the Subuser Management page in the user interface.
+If an event type is marked as `true`, then the event webhook will include information about that event.
-Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
+Twilio SendGrid's Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as Twilio SendGrid processes your email.
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program.
-### GET /whitelabel/links/subuser
+### GET /user/webhooks/event/settings
```python
-params = {'username': 'test_string'}
-response = sg.client.whitelabel.links.subuser.get(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.webhooks.event.settings.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Disassociate a Link Whitelabel
-
-**This endpoint allows you to disassociate a link whitelabel from a subuser.**
+## Test Event Notification Settings
-Link whitelables can be associated with subusers from the parent account. This functionality allows
-subusers to send mail using their parent's linke whitelabels. To associate a link whitelabel, the parent account
-must first create a whitelabel and validate it. The parent may then associate that whitelabel with a subuser via the API or the Subuser Management page in the user interface.
+**This endpoint allows you to test your event webhook by sending a fake event notification post to the provided URL.**
-Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
+Twilio SendGrid's Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as Twilio SendGrid processes your email.
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+Common uses of this data are to remove unsubscribes, react to spam reports, determine unengaged recipients, identify bounced email addresses, or create advanced analytics of your email program.
-### DELETE /whitelabel/links/subuser
+### POST /user/webhooks/event/test
```python
-params = {'username': 'test_string'}
-response = sg.client.whitelabel.links.subuser.delete(query_params=params)
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "url": "url"
+}
+response = sg.client.user.webhooks.event.test.post(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Update a Link Whitelabel
-
-**This endpoint allows you to update a specific link whitelabel. You can use this endpoint to change a link whitelabel's default status.**
+## Create a parse setting
-Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
+**This endpoint allows you to create a new inbound parse setting.**
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the content, and then have that content POSTed by Twilio SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html).
-### PATCH /whitelabel/links/{id}
+### POST /user/webhooks/parse/settings
```python
data = {
- "default": True
+ "hostname": "myhostname.com",
+ "send_raw": False,
+ "spam_check": True,
+ "url": "http://email.myhosthame.com"
}
-id = "test_url_param"
-response = sg.client.whitelabel.links._(id).patch(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.webhooks.parse.settings.post(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Retrieve a Link Whitelabel
-
-**This endpoint allows you to retrieve a specific link whitelabel.**
+## Retrieve all parse settings
-Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
+**This endpoint allows you to retrieve all of your current inbound parse settings.**
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the content, and then have that content POSTed by Twilio SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html).
-### GET /whitelabel/links/{id}
+### GET /user/webhooks/parse/settings
```python
-id = "test_url_param"
-response = sg.client.whitelabel.links._(id).get()
-print response.status_code
-print response.body
-print response.headers
+response = sg.client.user.webhooks.parse.settings.get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Delete a Link Whitelabel
-
-**This endpoint allows you to delete a link whitelabel.**
+## Update a parse setting
-Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
+**This endpoint allows you to update a specific inbound parse setting.**
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the content, and then have that content POSTed by Twilio SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html).
-### DELETE /whitelabel/links/{id}
+### PATCH /user/webhooks/parse/settings/{hostname}
```python
-id = "test_url_param"
-response = sg.client.whitelabel.links._(id).delete()
-print response.status_code
-print response.body
-print response.headers
+data = {
+ "send_raw": True,
+ "spam_check": False,
+ "url": "http://newdomain.com/parse"
+}
+hostname = "test_url_param"
+response = sg.client.user.webhooks.parse.settings._(hostname).patch(request_body=data)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Validate a Link Whitelabel
-
-**This endpoint allows you to validate a link whitelabel.**
+## Retrieve a specific parse setting
-Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
+**This endpoint allows you to retrieve a specific inbound parse setting.**
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
+The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the content, and then have that content POSTed by Twilio SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html).
-### POST /whitelabel/links/{id}/validate
+### GET /user/webhooks/parse/settings/{hostname}
```python
-id = "test_url_param"
-response = sg.client.whitelabel.links._(id).validate.post()
-print response.status_code
-print response.body
-print response.headers
+hostname = "test_url_param"
+response = sg.client.user.webhooks.parse.settings._(hostname).get()
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-## Associate a Link Whitelabel
+## Delete a parse setting
-**This endpoint allows you to associate a link whitelabel with a subuser account.**
+**This endpoint allows you to delete a specific inbound parse setting.**
-Link whitelables can be associated with subusers from the parent account. This functionality allows
-subusers to send mail using their parent's linke whitelabels. To associate a link whitelabel, the parent account
-must first create a whitelabel and validate it. The parent may then associate that whitelabel with a subuser via the API or the Subuser Management page in the user interface.
+The inbound parse webhook allows you to have incoming emails parsed, extracting some or all of the content, and then have that content POSTed by Twilio SendGrid to a URL of your choosing. For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Webhooks/parse.html).
-Email link whitelabels allow all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net.
+### DELETE /user/webhooks/parse/settings/{hostname}
-For more information, please see our [User Guide](https://sendgrid.com/docs/API_Reference/Web_API_v3/Whitelabel/links.html).
-### POST /whitelabel/links/{link_id}/subuser
+```python
+hostname = "test_url_param"
+response = sg.client.user.webhooks.parse.settings._(hostname).delete()
+print(response.status_code)
+print(response.body)
+print(response.headers)
+```
+## Retrieves Inbound Parse Webhook statistics.
+
+**This endpoint allows you to retrieve the statistics for your Parse Webhook usage.**
+
+Twilio SendGrid's Inbound Parse Webhook allows you to parse the contents and attachments of incoming emails. The Parse API can then POST the parsed emails to a URL that you specify. The Inbound Parse Webhook cannot parse messages greater than 20MB in size, including all attachments.
+
+There are a number of pre-made integrations for the Twilio SendGrid Parse Webhook which make processing events easy. You can find these integrations in the [Library Index](https://sendgrid.com/docs/Integrate/libraries.html#-Webhook-Libraries).
+
+### GET /user/webhooks/parse/stats
```python
-data = {
- "username": "jane@example.com"
-}
-link_id = "test_url_param"
-response = sg.client.whitelabel.links._(link_id).subuser.post(request_body=data)
-print response.status_code
-print response.body
-print response.headers
+params = {'aggregated_by': 'day', 'limit': 'test_string', 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 'test_string'}
+response = sg.client.user.webhooks.parse.stats.get(query_params=params)
+print(response.status_code)
+print(response.body)
+print(response.headers)
```
-
diff --git a/activate.sh b/activate.sh
deleted file mode 100755
index 0fe1b6dc6..000000000
--- a/activate.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-# Use this to activate the virtual environment, use the following to execute in current shell
-# . ./activate
-source venv/bin/activate
\ No newline at end of file
diff --git a/app.json b/app.json
index 3c86fae6c..e25064d12 100644
--- a/app.json
+++ b/app.json
@@ -1,11 +1,11 @@
{
- "name": "SendGrid Inbound Parse",
- "description": "Consume and parse POSTs from SendGrid's Inbound Parse Webhook",
+ "name": "Twilio SendGrid Inbound Parse",
+ "description": "Consume and parse POSTs from Twilio SendGrid's Inbound Parse Webhook",
"keywords": [
"sendgrid",
"inbound parse"
],
"website": "http://www.sendgrid.com",
- "repository": "https://github.com/sendgrid/sendgrid-python/tree/master",
- "logo": "https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png"
+ "repository": "https://github.com/sendgrid/sendgrid-python",
+ "logo": "https://sendgrid.com/brand/sg-twilio/SG_Twilio_Lockup_RGBx1.png"
}
\ No newline at end of file
diff --git a/examples/accesssettings/accesssettings.py b/examples/accesssettings/accesssettings.py
index aac0e4a54..17d115f9b 100644
--- a/examples/accesssettings/accesssettings.py
+++ b/examples/accesssettings/accesssettings.py
@@ -1,9 +1,8 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve all recent access attempts #
@@ -20,17 +19,17 @@
# POST /access_settings/whitelist #
data = {
- "ips": [
- {
- "ip": "192.168.1.1"
- },
- {
- "ip": "192.*.*.*"
- },
- {
- "ip": "192.168.1.3/32"
- }
- ]
+ "ips": [
+ {
+ "ip": "192.168.1.1"
+ },
+ {
+ "ip": "192.*.*.*"
+ },
+ {
+ "ip": "192.168.1.3/32"
+ }
+ ]
}
response = sg.client.access_settings.whitelist.post(request_body=data)
print(response.status_code)
@@ -51,11 +50,11 @@
# DELETE /access_settings/whitelist #
data = {
- "ids": [
- 1,
- 2,
- 3
- ]
+ "ids": [
+ 1,
+ 2,
+ 3
+ ]
}
response = sg.client.access_settings.whitelist.delete(request_body=data)
print(response.status_code)
@@ -81,4 +80,3 @@
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/alerts/alerts.py b/examples/alerts/alerts.py
index e30d48748..cdfe008fd 100644
--- a/examples/alerts/alerts.py
+++ b/examples/alerts/alerts.py
@@ -1,18 +1,17 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Create a new Alert #
# POST /alerts #
data = {
- "email_to": "example@example.com",
- "frequency": "daily",
- "type": "stats_notification"
+ "email_to": "example@example.com",
+ "frequency": "daily",
+ "type": "stats_notification"
}
response = sg.client.alerts.post(request_body=data)
print(response.status_code)
@@ -33,7 +32,7 @@
# PATCH /alerts/{alert_id} #
data = {
- "email_to": "example@example.com"
+ "email_to": "example@example.com"
}
alert_id = "test_url_param"
response = sg.client.alerts._(alert_id).patch(request_body=data)
@@ -60,4 +59,3 @@
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/apikeys/apikeys.py b/examples/apikeys/apikeys.py
index 42c3afa10..3e612cb15 100644
--- a/examples/apikeys/apikeys.py
+++ b/examples/apikeys/apikeys.py
@@ -1,22 +1,21 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Create API keys #
# POST /api_keys #
data = {
- "name": "My API Key",
- "sample": "data",
- "scopes": [
- "mail.send",
- "alerts.create",
- "alerts.read"
- ]
+ "name": "My API Key",
+ "sample": "data",
+ "scopes": [
+ "mail.send",
+ "alerts.create",
+ "alerts.read"
+ ]
}
response = sg.client.api_keys.post(request_body=data)
print(response.status_code)
@@ -38,11 +37,11 @@
# PUT /api_keys/{api_key_id} #
data = {
- "name": "A New Hope",
- "scopes": [
- "user.profile.read",
- "user.profile.update"
- ]
+ "name": "A New Hope",
+ "scopes": [
+ "user.profile.read",
+ "user.profile.update"
+ ]
}
api_key_id = "test_url_param"
response = sg.client.api_keys._(api_key_id).put(request_body=data)
@@ -55,7 +54,7 @@
# PATCH /api_keys/{api_key_id} #
data = {
- "name": "A New Hope"
+ "name": "A New Hope"
}
api_key_id = "test_url_param"
response = sg.client.api_keys._(api_key_id).patch(request_body=data)
@@ -82,4 +81,3 @@
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/asm/asm.py b/examples/asm/asm.py
index 43130cf06..1b081b851 100644
--- a/examples/asm/asm.py
+++ b/examples/asm/asm.py
@@ -1,18 +1,17 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Create a new suppression group #
# POST /asm/groups #
data = {
- "description": "Suggestions for products our users might like.",
- "is_default": True,
- "name": "Product Suggestions"
+ "description": "Suggestions for products our users might like.",
+ "is_default": True,
+ "name": "Product Suggestions"
}
response = sg.client.asm.groups.post(request_body=data)
print(response.status_code)
@@ -34,9 +33,9 @@
# PATCH /asm/groups/{group_id} #
data = {
- "description": "Suggestions for items our users might like.",
- "id": 103,
- "name": "Item Suggestions"
+ "description": "Suggestions for items our users might like.",
+ "id": 103,
+ "name": "Item Suggestions"
}
group_id = "test_url_param"
response = sg.client.asm.groups._(group_id).patch(request_body=data)
@@ -69,13 +68,14 @@
# POST /asm/groups/{group_id}/suppressions #
data = {
- "recipient_emails": [
- "test1@example.com",
- "test2@example.com"
- ]
+ "recipient_emails": [
+ "test1@example.com",
+ "test2@example.com"
+ ]
}
group_id = "test_url_param"
-response = sg.client.asm.groups._(group_id).suppressions.post(request_body=data)
+response = sg.client.asm.groups._(
+ group_id).suppressions.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
@@ -95,14 +95,15 @@
# POST /asm/groups/{group_id}/suppressions/search #
data = {
- "recipient_emails": [
- "exists1@example.com",
- "exists2@example.com",
- "doesnotexists@example.com"
- ]
+ "recipient_emails": [
+ "exists1@example.com",
+ "exists2@example.com",
+ "doesnotexists@example.com"
+ ]
}
group_id = "test_url_param"
-response = sg.client.asm.groups._(group_id).suppressions.search.post(request_body=data)
+response = sg.client.asm.groups._(
+ group_id).suppressions.search.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
@@ -132,10 +133,10 @@
# POST /asm/suppressions/global #
data = {
- "recipient_emails": [
- "test1@example.com",
- "test2@example.com"
- ]
+ "recipient_emails": [
+ "test1@example.com",
+ "test2@example.com"
+ ]
}
response = sg.client.asm.suppressions._("global").post(request_body=data)
print(response.status_code)
@@ -171,4 +172,3 @@
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/browsers/browsers.py b/examples/browsers/browsers.py
index c123c12e5..43152260a 100644
--- a/examples/browsers/browsers.py
+++ b/examples/browsers/browsers.py
@@ -1,17 +1,20 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve email statistics by browser. #
# GET /browsers/stats #
-params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'browsers': 'test_string', 'limit': 'test_string', 'offset': 'test_string', 'start_date': '2016-01-01'}
+params = {'end_date': '2016-04-01',
+ 'aggregated_by': 'day',
+ 'browsers': 'test_string',
+ 'limit': 'test_string',
+ 'offset': 'test_string',
+ 'start_date': '2016-01-01'}
response = sg.client.browsers.stats.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/campaigns/campaigns.py b/examples/campaigns/campaigns.py
index c77fc878b..dbbb6c0e1 100644
--- a/examples/campaigns/campaigns.py
+++ b/examples/campaigns/campaigns.py
@@ -1,33 +1,32 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Create a Campaign #
# POST /campaigns #
data = {
- "categories": [
- "spring line"
- ],
- "custom_unsubscribe_url": "",
- "html_content": "Check out our spring line!
",
- "ip_pool": "marketing",
- "list_ids": [
- 110,
- 124
- ],
- "plain_content": "Check out our spring line!",
- "segment_ids": [
- 110
- ],
- "sender_id": 124451,
- "subject": "New Products for Spring!",
- "suppression_group_id": 42,
- "title": "March Newsletter"
+ "categories": [
+ "spring line"
+ ],
+ "custom_unsubscribe_url": "",
+ "html_content": "Check out our spring line!
",
+ "ip_pool": "marketing",
+ "list_ids": [
+ 110,
+ 124
+ ],
+ "plain_content": "Check out our spring line!",
+ "segment_ids": [
+ 110
+ ],
+ "sender_id": 124451,
+ "subject": "New Products for Spring!",
+ "suppression_group_id": 42,
+ "title": "March Newsletter"
}
response = sg.client.campaigns.post(request_body=data)
print(response.status_code)
@@ -49,13 +48,13 @@
# PATCH /campaigns/{campaign_id} #
data = {
- "categories": [
- "summer line"
- ],
- "html_content": "Check out our summer line!
",
- "plain_content": "Check out our summer line!",
- "subject": "New Products for Summer!",
- "title": "May Newsletter"
+ "categories": [
+ "summer line"
+ ],
+ "html_content": "Check out our summer line!
",
+ "plain_content": "Check out our summer line!",
+ "subject": "New Products for Summer!",
+ "title": "May Newsletter"
}
campaign_id = "test_url_param"
response = sg.client.campaigns._(campaign_id).patch(request_body=data)
@@ -88,10 +87,11 @@
# PATCH /campaigns/{campaign_id}/schedules #
data = {
- "send_at": 1489451436
+ "send_at": 1489451436
}
campaign_id = "test_url_param"
-response = sg.client.campaigns._(campaign_id).schedules.patch(request_body=data)
+response = sg.client.campaigns._(
+ campaign_id).schedules.patch(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
@@ -101,7 +101,7 @@
# POST /campaigns/{campaign_id}/schedules #
data = {
- "send_at": 1489771528
+ "send_at": 1489771528
}
campaign_id = "test_url_param"
response = sg.client.campaigns._(campaign_id).schedules.post(request_body=data)
@@ -144,11 +144,11 @@
# POST /campaigns/{campaign_id}/schedules/test #
data = {
- "to": "your.email@example.com"
+ "to": "your.email@example.com"
}
campaign_id = "test_url_param"
-response = sg.client.campaigns._(campaign_id).schedules.test.post(request_body=data)
+response = sg.client.campaigns._(
+ campaign_id).schedules.test.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/categories/categories.py b/examples/categories/categories.py
index 7984f0fe0..b8275713f 100644
--- a/examples/categories/categories.py
+++ b/examples/categories/categories.py
@@ -1,9 +1,8 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve all categories #
@@ -19,7 +18,8 @@
# Retrieve Email Statistics for Categories #
# GET /categories/stats #
-params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01', 'categories': 'test_string'}
+params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1,
+ 'offset': 1, 'start_date': '2016-01-01', 'categories': 'test_string'}
response = sg.client.categories.stats.get(query_params=params)
print(response.status_code)
print(response.body)
@@ -29,9 +29,14 @@
# Retrieve sums of email stats for each category [Needs: Stats object defined, has category ID?] #
# GET /categories/stats/sums #
-params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'start_date': '2016-01-01', 'sort_by_direction': 'asc'}
+params = {'end_date': '2016-04-01',
+ 'aggregated_by': 'day',
+ 'limit': 1,
+ 'sort_by_metric': 'test_string',
+ 'offset': 1,
+ 'start_date': '2016-01-01',
+ 'sort_by_direction': 'asc'}
response = sg.client.categories.stats.sums.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/clients/clients.py b/examples/clients/clients.py
index 7831ef78f..023a440db 100644
--- a/examples/clients/clients.py
+++ b/examples/clients/clients.py
@@ -1,15 +1,16 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve email statistics by client type. #
# GET /clients/stats #
-params = {'aggregated_by': 'day', 'start_date': '2016-01-01', 'end_date': '2016-04-01'}
+params = {'aggregated_by': 'day',
+ 'start_date': '2016-01-01',
+ 'end_date': '2016-04-01'}
response = sg.client.clients.stats.get(query_params=params)
print(response.status_code)
print(response.body)
@@ -19,10 +20,11 @@
# Retrieve stats by a specific client type. #
# GET /clients/{client_type}/stats #
-params = {'aggregated_by': 'day', 'start_date': '2016-01-01', 'end_date': '2016-04-01'}
+params = {'aggregated_by': 'day',
+ 'start_date': '2016-01-01',
+ 'end_date': '2016-04-01'}
client_type = "test_url_param"
response = sg.client.clients._(client_type).stats.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/contactdb/contactdb.py b/examples/contactdb/contactdb.py
index 59b5b2e42..b702974df 100644
--- a/examples/contactdb/contactdb.py
+++ b/examples/contactdb/contactdb.py
@@ -1,17 +1,16 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Create a Custom Field #
# POST /contactdb/custom_fields #
data = {
- "name": "pet",
- "type": "text"
+ "name": "pet",
+ "type": "text"
}
response = sg.client.contactdb.custom_fields.post(request_body=data)
print(response.status_code)
@@ -52,7 +51,7 @@
# POST /contactdb/lists #
data = {
- "name": "your list name"
+ "name": "your list name"
}
response = sg.client.contactdb.lists.post(request_body=data)
print(response.status_code)
@@ -73,10 +72,10 @@
# DELETE /contactdb/lists #
data = [
- 1,
- 2,
- 3,
- 4
+ 1,
+ 2,
+ 3,
+ 4
]
response = sg.client.contactdb.lists.delete(request_body=data)
print(response.status_code)
@@ -88,11 +87,13 @@
# PATCH /contactdb/lists/{list_id} #
data = {
- "name": "newlistname"
+ "name": "newlistname"
}
params = {'list_id': 1}
list_id = "test_url_param"
-response = sg.client.contactdb.lists._(list_id).patch(request_body=data, query_params=params)
+response = sg.client.contactdb.lists._(list_id).patch(
+ request_body=data,
+ query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
@@ -124,11 +125,12 @@
# POST /contactdb/lists/{list_id}/recipients #
data = [
- "recipient_id1",
- "recipient_id2"
+ "recipient_id1",
+ "recipient_id2"
]
list_id = "test_url_param"
-response = sg.client.contactdb.lists._(list_id).recipients.post(request_body=data)
+response = sg.client.contactdb.lists._(
+ list_id).recipients.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
@@ -137,9 +139,10 @@
# Retrieve all recipients on a List #
# GET /contactdb/lists/{list_id}/recipients #
-params = {'page': 1, 'page_size': 1, 'list_id': 1}
+params = {'page': 1, 'page_size': 1}
list_id = "test_url_param"
-response = sg.client.contactdb.lists._(list_id).recipients.get(query_params=params)
+response = sg.client.contactdb.lists._(
+ list_id).recipients.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
@@ -150,7 +153,8 @@
list_id = "test_url_param"
recipient_id = "test_url_param"
-response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).post()
+response = sg.client.contactdb.lists._(
+ list_id).recipients._(recipient_id).post()
print(response.status_code)
print(response.body)
print(response.headers)
@@ -162,7 +166,8 @@
params = {'recipient_id': 1, 'list_id': 1}
list_id = "test_url_param"
recipient_id = "test_url_param"
-response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).delete(query_params=params)
+response = sg.client.contactdb.lists._(list_id).recipients._(
+ recipient_id).delete(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
@@ -172,11 +177,11 @@
# PATCH /contactdb/recipients #
data = [
- {
- "email": "jones@example.com",
- "first_name": "Guy",
- "last_name": "Jones"
- }
+ {
+ "email": "jones@example.com",
+ "first_name": "Guy",
+ "last_name": "Jones"
+ }
]
response = sg.client.contactdb.recipients.patch(request_body=data)
print(response.status_code)
@@ -188,18 +193,18 @@
# POST /contactdb/recipients #
data = [
- {
- "age": 25,
- "email": "example@example.com",
- "first_name": "",
- "last_name": "User"
- },
- {
- "age": 25,
- "email": "example2@example.com",
- "first_name": "Example",
- "last_name": "User"
- }
+ {
+ "age": 25,
+ "email": "example@example.com",
+ "first_name": "",
+ "last_name": "User"
+ },
+ {
+ "age": 25,
+ "email": "example2@example.com",
+ "first_name": "Example",
+ "last_name": "User"
+ }
]
response = sg.client.contactdb.recipients.post(request_body=data)
print(response.status_code)
@@ -221,8 +226,8 @@
# DELETE /contactdb/recipients #
data = [
- "recipient_id1",
- "recipient_id2"
+ "recipient_id1",
+ "recipient_id2"
]
response = sg.client.contactdb.recipients.delete(request_body=data)
print(response.status_code)
@@ -301,28 +306,28 @@
# POST /contactdb/segments #
data = {
- "conditions": [
- {
- "and_or": "",
- "field": "last_name",
- "operator": "eq",
- "value": "Miller"
- },
- {
- "and_or": "and",
- "field": "last_clicked",
- "operator": "gt",
- "value": "01/02/2015"
- },
- {
- "and_or": "or",
- "field": "clicks.campaign_identifier",
- "operator": "eq",
- "value": "513"
- }
- ],
- "list_id": 4,
- "name": "Last Name Miller"
+ "conditions": [
+ {
+ "and_or": "",
+ "field": "last_name",
+ "operator": "eq",
+ "value": "Miller"
+ },
+ {
+ "and_or": "and",
+ "field": "last_clicked",
+ "operator": "gt",
+ "value": "01/02/2015"
+ },
+ {
+ "and_or": "or",
+ "field": "clicks.campaign_identifier",
+ "operator": "eq",
+ "value": "513"
+ }
+ ],
+ "list_id": 4,
+ "name": "Last Name Miller"
}
response = sg.client.contactdb.segments.post(request_body=data)
print(response.status_code)
@@ -343,20 +348,22 @@
# PATCH /contactdb/segments/{segment_id} #
data = {
- "conditions": [
- {
- "and_or": "",
- "field": "last_name",
- "operator": "eq",
- "value": "Miller"
- }
- ],
- "list_id": 5,
- "name": "The Millers"
+ "conditions": [
+ {
+ "and_or": "",
+ "field": "last_name",
+ "operator": "eq",
+ "value": "Miller"
+ }
+ ],
+ "list_id": 5,
+ "name": "The Millers"
}
params = {'segment_id': 'test_string'}
segment_id = "test_url_param"
-response = sg.client.contactdb.segments._(segment_id).patch(request_body=data, query_params=params)
+response = sg.client.contactdb.segments._(segment_id).patch(
+ request_body=data,
+ query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
@@ -378,7 +385,8 @@
params = {'delete_contacts': 'true'}
segment_id = "test_url_param"
-response = sg.client.contactdb.segments._(segment_id).delete(query_params=params)
+response = sg.client.contactdb.segments._(
+ segment_id).delete(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
@@ -389,8 +397,8 @@
params = {'page': 1, 'page_size': 1}
segment_id = "test_url_param"
-response = sg.client.contactdb.segments._(segment_id).recipients.get(query_params=params)
+response = sg.client.contactdb.segments._(
+ segment_id).recipients.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/dataresidency/set_region.py b/examples/dataresidency/set_region.py
new file mode 100644
index 000000000..9aae2611f
--- /dev/null
+++ b/examples/dataresidency/set_region.py
@@ -0,0 +1,37 @@
+import sendgrid
+import os
+
+from sendgrid import Email, To, Content, Mail
+
+# Example 1
+# setting region to be "global"
+
+sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
+from_email = Email("example@abc.com")
+to_email = To("example@abc.com")
+subject = "Sending with SendGrid is Fun"
+content = Content("text/plain", "and easy to do anywhere, even with Python")
+mail = Mail(from_email, to_email, subject, content)
+sg.set_sendgrid_data_residency("global")
+print(sg.client.host)
+response = sg.client.mail.send.post(request_body=mail.get())
+print(response)
+print(response.status_code)
+print(response.body)
+print(response.headers)
+
+# Example 2
+# setting region to "eu"
+sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY_EU'))
+sg.set_sendgrid_data_residency("eu")
+from_email = Email("example@abc.com")
+to_email = To("example@abc.com")
+subject = "Sending with SendGrid is Fun"
+content = Content("text/plain", "and easy to do anywhere, even with Python")
+print(sg.client.host)
+mail = Mail(from_email, to_email, subject, content)
+response = sg.client.mail.send.post(request_body=mail.get())
+print(response)
+print(response.status_code)
+print(response.body)
+print(response.headers)
\ No newline at end of file
diff --git a/examples/devices/devices.py b/examples/devices/devices.py
index 108e98452..50c96243d 100644
--- a/examples/devices/devices.py
+++ b/examples/devices/devices.py
@@ -1,17 +1,18 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve email statistics by device type. #
# GET /devices/stats #
-params = {'aggregated_by': 'day', 'limit': 1, 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 1}
+params = {'aggregated_by': 'day', 'limit': 1,
+ 'start_date': '2016-01-01',
+ 'end_date': '2016-04-01',
+ 'offset': 1}
response = sg.client.devices.stats.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/geo/geo.py b/examples/geo/geo.py
index 7d58ec085..64265b201 100644
--- a/examples/geo/geo.py
+++ b/examples/geo/geo.py
@@ -1,17 +1,20 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve email statistics by country and state/province. #
# GET /geo/stats #
-params = {'end_date': '2016-04-01', 'country': 'US', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01'}
+params = {'end_date': '2016-04-01',
+ 'country': 'US',
+ 'aggregated_by': 'day',
+ 'limit': 1,
+ 'offset': 1,
+ 'start_date': '2016-01-01'}
response = sg.client.geo.stats.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/helpers/README.md b/examples/helpers/README.md
new file mode 100644
index 000000000..8d7594d44
--- /dev/null
+++ b/examples/helpers/README.md
@@ -0,0 +1,73 @@
+## Using helper class to send emails
+You can use helper classes to customize the process of sending emails using SendGrid. Each process (such as sending a mock email,
+building attachments, configuring settings, building personalizations, etc.) are made easy using helpers. All you need is a file with
+all the classes imported and you can start sending emails!
+
+> Note: You will need move this file to the root directory of this project to execute properly.
+
+### Creating a simple email object and sending it
+The example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L9)
+defines minimum requirement to send an email.
+```
+ from_email = Email("test@example.com")
+ subject = "Hello World from the SendGrid Python Library"
+ to_email = Email("test@example.com")
+```
+You can use `Email` class to define a mail id.
+
+```
+content = Content("text/plain", "some text here")
+```
+The `Content` class takes mainly two parameters: MIME type and the actual content of the email, it then returns the JSON-ready representation of this content.
+
+```
+ mail = Mail(from_email, to_email, subject, content)
+```
+After adding the above we create a mail object using `Mail` class, it takes the following parameters: email address to send from, subject line of emails, email address to send to, content of the message.
+For more information on parameters and usage, see [here](../mail/mail.py)
+
+### Creating Personalizations
+
+The personalization helper can be used to create personalizations and customize various aspects of an email. See example [here](mail_example.py) in `build_multiple_emails_personalized()`, and refer [here](https://docs.sendgrid.com/for-developers/sending-email/personalizations) for more documentation.
+```
+ mock_personalization = Personalization()
+
+ for to_addr in personalization['to_list']:
+ mock_personalization.add_to(to_addr)
+
+ mock_personalization.set_from(from_addr)
+ mock_personalization.add_cc(cc_addr)
+ # etc...
+```
+
+### Creating Attachments
+
+To create attachments, we use the `Attachment` class and make sure the content is base64 encoded before passing it into attachment.content.
+```
+ attachment = Attachment()
+ attachment.content = ("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNl"
+ "Y3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12")
+```
+Another example: [Link](../../use_cases/attachment.md)
+
+### Managing Settings
+
+To configure settings in mail, you can use the `MailSettings` class. The class takes some [parameters](../mailsettings/mailsettings.py#L1)(such as bcc_settings, bypass_list_management, footer_settings, sandbox_mode)
+
+To add tracking settings, you can add `TrackingSettings` class. See example [here](mail_example.py#L118) and parameters and usage [here](../trackingsettings/trackingsettings.py).
+
+### Sending email
+
+After you have configured every component and added your own functions, you can send emails.
+```
+ sg = SendGridAPIClient()
+ data = build_kitchen_sink()
+ response = sg.send(data)
+```
+Make sure you have [environment variable](../../TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key) set up!
+Full example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L203).
+
+### Using Dynamic Templates
+You can use dynamic (handlebars) transactional templates to make things easy and less time taking. To make this work, you should have dynamic template created within your SendGrid account.
+
+See Full example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L221).
diff --git a/examples/helpers/eventwebhook/eventwebhook_example.py b/examples/helpers/eventwebhook/eventwebhook_example.py
new file mode 100644
index 000000000..91ad8d64b
--- /dev/null
+++ b/examples/helpers/eventwebhook/eventwebhook_example.py
@@ -0,0 +1,14 @@
+from sendgrid.helpers.eventwebhook import EventWebhook, EventWebhookHeader
+
+def is_valid_signature(request):
+ public_key = 'base64-encoded public key'
+
+ event_webhook = EventWebhook()
+ ec_public_key = event_webhook.convert_public_key_to_ecdsa(public_key)
+
+ return event_webhook.verify_signature(
+ request.text,
+ request.headers[EventWebhookHeader.SIGNATURE],
+ request.headers[EventWebhookHeader.TIMESTAMP],
+ ec_public_key
+ )
diff --git a/examples/helpers/mail/mail_example.py b/examples/helpers/mail/mail_example.py
deleted file mode 100644
index 9d5133d5e..000000000
--- a/examples/helpers/mail/mail_example.py
+++ /dev/null
@@ -1,144 +0,0 @@
-import json
-import os
-import urllib2
-from sendgrid.helpers.mail import *
-from sendgrid import *
-
-# NOTE: you will need move this file to the root directory of this project to execute properly.
-
-def build_hello_email():
- """Minimum required to send an email"""
- from_email = Email("test@example.com")
- subject = "Hello World from the SendGrid Python Library"
- to_email = Email("test@example.com")
- content = Content("text/plain", "some text here")
- mail = Mail(from_email, subject, to_email, content)
- mail.personalizations[0].add_to(Email("test2@example.com"))
-
- return mail.get()
-
-def build_kitchen_sink():
- """All settings set"""
- mail = Mail()
-
- mail.from_email = Email("test@example.com", "Example User")
-
- mail.subject = "Hello World from the SendGrid Python Library"
-
- personalization = Personalization()
- personalization.add_to(Email("test1@example.com", "Example User"))
- personalization.add_to(Email("test2@example.com", "Example User"))
- personalization.add_cc(Email("test3@example.com", "Example User"))
- personalization.add_cc(Email("test4@example.com", "Example User"))
- personalization.add_bcc(Email("test5@example.com"))
- personalization.add_bcc(Email("test6@example.com"))
- personalization.subject = "Hello World from the Personalized SendGrid Python Library"
- personalization.add_header(Header("X-Test", "test"))
- personalization.add_header(Header("X-Mock", "true"))
- personalization.add_substitution(Substitution("%name%", "Example User"))
- personalization.add_substitution(Substitution("%city%", "Denver"))
- personalization.add_custom_arg(CustomArg("user_id", "343"))
- personalization.add_custom_arg(CustomArg("type", "marketing"))
- personalization.send_at = 1443636843
- mail.add_personalization(personalization)
-
- personalization2 = Personalization()
- personalization2.add_to(Email("test1@example.com", "Example User"))
- personalization2.add_to(Email("test2@example.com", "Example User"))
- personalization2.add_cc(Email("test3@example.com", "Example User"))
- personalization2.add_cc(Email("test4@example.com", "Eric Shallock"))
- personalization2.add_bcc(Email("test5@example.com"))
- personalization2.add_bcc(Email("test6@example.com"))
- personalization2.subject = "Hello World from the Personalized SendGrid Python Library"
- personalization2.add_header(Header("X-Test", "test"))
- personalization2.add_header(Header("X-Mock", "true"))
- personalization2.add_substitution(Substitution("%name%", "Example User"))
- personalization2.add_substitution(Substitution("%city%", "Denver"))
- personalization2.add_custom_arg(CustomArg("user_id", "343"))
- personalization2.add_custom_arg(CustomArg("type", "marketing"))
- personalization2.send_at = 1443636843
- mail.add_personalization(personalization2)
-
- mail.add_content(Content("text/plain", "some text here"))
- mail.add_content(Content("text/html", "some text here"))
-
- attachment = Attachment()
- attachment.content = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12"
- attachment.type = "application/pdf"
- attachment.filename = "balance_001.pdf"
- attachment.disposition = "attachment"
- attachment.content_id = "Balance Sheet"
- mail.add_attachment(attachment)
-
- attachment2 = Attachment()
- attachment2.content = "BwdW"
- attachment2.type = "image/png"
- attachment2.filename = "banner.png"
- attachment2.disposition = "inline"
- attachment2.content_id = "Banner"
- mail.add_attachment(attachment2)
-
- mail.template_id = "13b8f94f-bcae-4ec6-b752-70d6cb59f932"
-
- mail.add_section(Section("%section1%", "Substitution Text for Section 1"))
- mail.add_section(Section("%section2%", "Substitution Text for Section 2"))
-
- mail.add_header(Header("X-Test1", "test1"))
- mail.add_header(Header("X-Test3", "test2"))
-
- mail.add_category(Category("May"))
- mail.add_category(Category("2016"))
-
- mail.add_custom_arg(CustomArg("campaign", "welcome"))
- mail.add_custom_arg(CustomArg("weekday", "morning"))
-
- mail.send_at = 1443636842
-
- # This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) to work
- # mail.set_batch_id("N2VkYjBjYWItMGU4OC0xMWU2LWJhMzYtZjQ1Yzg5OTBkNzkxLWM5ZTUyZjNhOA")
-
- mail.asm = ASM(99, [4, 5, 6, 7, 8])
-
- mail.ip_pool_name = "24"
-
- mail_settings = MailSettings()
- mail_settings.bcc_settings = BCCSettings(True, Email("test@example.com"))
- mail_settings.bypass_list_management = BypassListManagement(True)
- mail_settings.footer_settings = FooterSettings(True, "Footer Text", "Footer Text")
- mail_settings.sandbox_mode = SandBoxMode(True)
- mail_settings.spam_check = SpamCheck(True, 1, "https://spamcatcher.sendgrid.com")
- mail.mail_settings = mail_settings
-
- tracking_settings = TrackingSettings()
- tracking_settings.click_tracking = ClickTracking(True, True)
- tracking_settings.open_tracking = OpenTracking(True, "Optional tag to replace with the open image in the body of the message")
- tracking_settings.subscription_tracking = SubscriptionTracking(True, "text to insert into the text/plain portion of the message", "html to insert into the text/html portion of the message", "Optional tag to replace with the open image in the body of the message")
- tracking_settings.ganalytics = Ganalytics(True, "some source", "some medium", "some term", "some_content", "some_campaign")
- mail.tracking_settings = tracking_settings
-
- mail.reply_to = Email("test@example.com")
-
- return mail.get()
-
-def send_hello_email():
- # Assumes you set your environment variable:
- # https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key
- sg = SendGridAPIClient()
- data = build_hello_email()
- response = sg.client.mail.send.post(request_body=data)
- print(response.status_code)
- print(response.headers)
- print(response.body)
-
-def send_kitchen_sink():
- # Assumes you set your environment variable:
- # https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key
- sg = SendGridAPIClient()
- data = build_kitchen_sink()
- response = sg.client.mail.send.post(request_body=data)
- print(response.status_code)
- print(response.headers)
- print(response.body)
-
-send_hello_email() # this will actually send an email
-send_kitchen_sink() # this will only send an email if you set SandBox Mode to False
diff --git a/examples/helpers/mail_example.py b/examples/helpers/mail_example.py
new file mode 100644
index 000000000..f6905787b
--- /dev/null
+++ b/examples/helpers/mail_example.py
@@ -0,0 +1,382 @@
+import os
+import json
+
+from sendgrid import SendGridAPIClient
+from sendgrid.helpers.mail import *
+
+
+# NOTE: you will need move this file to the root
+# directory of this project to execute properly.
+
+
+def build_hello_email():
+ ## Send a Single Email to a Single Recipient
+
+ message = Mail(from_email=From('from@example.com', 'Example From Name'),
+ to_emails=To('to@example.com', 'Example To Name'),
+ subject=Subject('Sending with SendGrid is Fun'),
+ plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'),
+ html_content=HtmlContent('and easy to do anywhere, even with Python'))
+
+ try:
+ print(json.dumps(message.get(), sort_keys=True, indent=4))
+ return message.get()
+
+ except SendGridException as e:
+ print(e.message)
+
+ mock_personalization = Personalization()
+ personalization_dict = get_mock_personalization_dict()
+
+ for cc_addr in personalization_dict['cc_list']:
+ mock_personalization.add_to(cc_addr)
+
+ for bcc_addr in personalization_dict['bcc_list']:
+ mock_personalization.add_bcc(bcc_addr)
+
+ for header in personalization_dict['headers']:
+ mock_personalization.add_header(header)
+
+ for substitution in personalization_dict['substitutions']:
+ mock_personalization.add_substitution(substitution)
+
+ for arg in personalization_dict['custom_args']:
+ mock_personalization.add_custom_arg(arg)
+
+ mock_personalization.subject = personalization_dict['subject']
+ mock_personalization.send_at = personalization_dict['send_at']
+
+ message.add_personalization(mock_personalization)
+
+ return message
+
+def get_mock_personalization_dict():
+ """Get a dict of personalization mock."""
+ mock_pers = dict()
+
+ mock_pers['to_list'] = [To("test1@example.com",
+ "Example User"),
+ To("test2@example.com",
+ "Example User")]
+
+ mock_pers['cc_list'] = [To("test3@example.com",
+ "Example User"),
+ To("test4@example.com",
+ "Example User")]
+
+ mock_pers['bcc_list'] = [To("test5@example.com"),
+ To("test6@example.com")]
+
+ mock_pers['subject'] = ("Hello World from the Personalized "
+ "SendGrid Python Library")
+
+ mock_pers['headers'] = [Header("X-Test", "test"),
+ Header("X-Mock", "true")]
+
+ mock_pers['substitutions'] = [Substitution("%name%", "Example User"),
+ Substitution("%city%", "Denver")]
+
+ mock_pers['custom_args'] = [CustomArg("user_id", "343"),
+ CustomArg("type", "marketing")]
+
+ mock_pers['send_at'] = 1443636843
+ return mock_pers
+
+def build_multiple_emails_personalized():
+ # Note that the domain for all From email addresses must match
+
+ message = Mail(from_email=From('from@example.com', 'Example From Name'),
+ subject=Subject('Sending with SendGrid is Fun'),
+ plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'),
+ html_content=HtmlContent('and easy to do anywhere, even with Python'))
+
+ mock_personalization = Personalization()
+ mock_personalization.add_to(To('test@example.com', 'Example User 1'))
+ mock_personalization.add_cc(Cc('test1@example.com', 'Example User 2'))
+ message.add_personalization(mock_personalization)
+
+ mock_personalization_2 = Personalization()
+ mock_personalization_2.add_to(To('test2@example.com', 'Example User 3'))
+ mock_personalization_2.set_from(From('from@example.com', 'Example From Name 2'))
+ mock_personalization_2.add_bcc(Bcc('test3@example.com', 'Example User 4'))
+ message.add_personalization(mock_personalization_2)
+
+ try:
+ print(json.dumps(message.get(), sort_keys=True, indent=4))
+ return message.get()
+
+ except SendGridException as e:
+ print(e.message)
+
+ return message
+
+def build_attachment1():
+ """Build attachment mock. Make sure your content is base64 encoded before passing into attachment.content.
+ Another example: https://github.com/sendgrid/sendgrid-python/blob/HEAD/use_cases/attachment.md"""
+
+ attachment = Attachment()
+ attachment.file_content = ("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNl"
+ "Y3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12")
+ attachment.file_type = "application/pdf"
+ attachment.file_name = "balance_001.pdf"
+ attachment.disposition = "attachment"
+ attachment.content_id = "Balance Sheet"
+ return attachment
+
+
+def build_attachment2():
+ """Build attachment mock."""
+ attachment = Attachment()
+ attachment.file_content = "BwdW"
+ attachment.file_type = "image/png"
+ attachment.file_name = "banner.png"
+ attachment.disposition = "inline"
+ attachment.content_id = "Banner"
+ return attachment
+
+def build_kitchen_sink():
+ """All settings set"""
+ from sendgrid.helpers.mail import (
+ Mail, From, To, Cc, Bcc, Subject, PlainTextContent,
+ HtmlContent, SendGridException, Substitution,
+ Header, CustomArg, SendAt, Content, MimeType, Attachment,
+ FileName, FileContent, FileType, Disposition, ContentId,
+ TemplateId, Section, ReplyTo, Category, BatchId, Asm,
+ GroupId, GroupsToDisplay, IpPoolName, MailSettings,
+ BccSettings, BccSettingsEmail, BypassListManagement,
+ FooterSettings, FooterText, FooterHtml, SandBoxMode,
+ SpamCheck, SpamThreshold, SpamUrl, TrackingSettings,
+ ClickTracking, SubscriptionTracking, SubscriptionText,
+ SubscriptionHtml, SubscriptionSubstitutionTag,
+ OpenTracking, OpenTrackingSubstitutionTag, Ganalytics,
+ UtmSource, UtmMedium, UtmTerm, UtmContent, UtmCampaign)
+ import time
+ import datetime
+
+ message = Mail()
+
+ # Define Personalizations
+
+ message.to = To('test1@sendgrid.com', 'Example User1', p=0)
+ message.to = [
+ To('test2@sendgrid.com', 'Example User2', p=0),
+ To('test3@sendgrid.com', 'Example User3', p=0)
+ ]
+
+ message.cc = Cc('test4@example.com', 'Example User4', p=0)
+ message.cc = [
+ Cc('test5@example.com', 'Example User5', p=0),
+ Cc('test6@example.com', 'Example User6', p=0)
+ ]
+
+ message.bcc = Bcc('test7@example.com', 'Example User7', p=0)
+ message.bcc = [
+ Bcc('test8@example.com', 'Example User8', p=0),
+ Bcc('test9@example.com', 'Example User9', p=0)
+ ]
+
+ message.subject = Subject('Sending with SendGrid is Fun 0', p=0)
+
+ message.header = Header('X-Test1', 'Test1', p=0)
+ message.header = Header('X-Test2', 'Test2', p=0)
+ message.header = [
+ Header('X-Test3', 'Test3', p=0),
+ Header('X-Test4', 'Test4', p=0)
+ ]
+
+ message.substitution = Substitution('%name1%', 'Example Name 1', p=0)
+ message.substitution = Substitution('%city1%', 'Example City 1', p=0)
+ message.substitution = [
+ Substitution('%name2%', 'Example Name 2', p=0),
+ Substitution('%city2%', 'Example City 2', p=0)
+ ]
+
+ message.custom_arg = CustomArg('marketing1', 'true', p=0)
+ message.custom_arg = CustomArg('transactional1', 'false', p=0)
+ message.custom_arg = [
+ CustomArg('marketing2', 'false', p=0),
+ CustomArg('transactional2', 'true', p=0)
+ ]
+
+ message.send_at = SendAt(1461775051, p=0)
+
+ message.to = To('test10@example.com', 'Example User10', p=1)
+ message.to = [
+ To('test11@example.com', 'Example User11', p=1),
+ To('test12@example.com', 'Example User12', p=1)
+ ]
+
+ message.cc = Cc('test13@example.com', 'Example User13', p=1)
+ message.cc = [
+ Cc('test14@example.com', 'Example User14', p=1),
+ Cc('test15@example.com', 'Example User15', p=1)
+ ]
+
+ message.bcc = Bcc('test16@example.com', 'Example User16', p=1)
+ message.bcc = [
+ Bcc('test17@example.com', 'Example User17', p=1),
+ Bcc('test18@example.com', 'Example User18', p=1)
+ ]
+
+ message.header = Header('X-Test5', 'Test5', p=1)
+ message.header = Header('X-Test6', 'Test6', p=1)
+ message.header = [
+ Header('X-Test7', 'Test7', p=1),
+ Header('X-Test8', 'Test8', p=1)
+ ]
+
+ message.substitution = Substitution('%name3%', 'Example Name 3', p=1)
+ message.substitution = Substitution('%city3%', 'Example City 3', p=1)
+ message.substitution = [
+ Substitution('%name4%', 'Example Name 4', p=1),
+ Substitution('%city4%', 'Example City 4', p=1)
+ ]
+
+ message.custom_arg = CustomArg('marketing3', 'true', p=1)
+ message.custom_arg = CustomArg('transactional3', 'false', p=1)
+ message.custom_arg = [
+ CustomArg('marketing4', 'false', p=1),
+ CustomArg('transactional4', 'true', p=1)
+ ]
+
+ message.send_at = SendAt(1461775052, p=1)
+
+ message.subject = Subject('Sending with SendGrid is Fun 1', p=1)
+
+ # The values below this comment are global to entire message
+
+ message.from_email = From('help@twilio.com', 'Twilio SendGrid')
+
+ message.reply_to = ReplyTo('help_reply@twilio.com', 'Twilio SendGrid Reply')
+
+ message.subject = Subject('Sending with SendGrid is Fun 2')
+
+ message.content = Content(MimeType.text, 'and easy to do anywhere, even with Python')
+ message.content = Content(MimeType.html, 'and easy to do anywhere, even with Python')
+ message.content = [
+ Content('text/calendar', 'Party Time!!'),
+ Content('text/custom', 'Party Time 2!!')
+ ]
+
+ message.attachment = Attachment(FileContent('base64 encoded content 1'),
+ FileName('balance_001.pdf'),
+ FileType('application/pdf'),
+ Disposition('attachment'),
+ ContentId('Content ID 1'))
+ message.attachment = [
+ Attachment(FileContent('base64 encoded content 2'),
+ FileName('banner.png'),
+ FileType('image/png'),
+ Disposition('inline'),
+ ContentId('Content ID 2')),
+ Attachment(FileContent('base64 encoded content 3'),
+ FileName('banner2.png'),
+ FileType('image/png'),
+ Disposition('inline'),
+ ContentId('Content ID 3'))
+ ]
+
+ message.template_id = TemplateId('13b8f94f-bcae-4ec6-b752-70d6cb59f932')
+
+ message.section = Section('%section1%', 'Substitution for Section 1 Tag')
+ message.section = [
+ Section('%section2%', 'Substitution for Section 2 Tag'),
+ Section('%section3%', 'Substitution for Section 3 Tag')
+ ]
+
+ message.header = Header('X-Test9', 'Test9')
+ message.header = Header('X-Test10', 'Test10')
+ message.header = [
+ Header('X-Test11', 'Test11'),
+ Header('X-Test12', 'Test12')
+ ]
+
+ message.category = Category('Category 1')
+ message.category = Category('Category 2')
+ message.category = [
+ Category('Category 1'),
+ Category('Category 2')
+ ]
+
+ message.custom_arg = CustomArg('marketing5', 'false')
+ message.custom_arg = CustomArg('transactional5', 'true')
+ message.custom_arg = [
+ CustomArg('marketing6', 'true'),
+ CustomArg('transactional6', 'false')
+ ]
+
+ message.send_at = SendAt(1461775053)
+
+ message.batch_id = BatchId("HkJ5yLYULb7Rj8GKSx7u025ouWVlMgAi")
+
+ message.asm = Asm(GroupId(1), GroupsToDisplay([1,2,3,4]))
+
+ message.ip_pool_name = IpPoolName("IP Pool Name")
+
+ mail_settings = MailSettings()
+ mail_settings.bcc_settings = BccSettings(False, BccSettingsTo("bcc@twilio.com"))
+ mail_settings.bypass_list_management = BypassListManagement(False)
+ mail_settings.footer_settings = FooterSettings(True, FooterText("w00t"), FooterHtml("w00t!"))
+ mail_settings.sandbox_mode = SandBoxMode(True)
+ mail_settings.spam_check = SpamCheck(True, SpamThreshold(5), SpamUrl("https://example.com"))
+ message.mail_settings = mail_settings
+
+ tracking_settings = TrackingSettings()
+ tracking_settings.click_tracking = ClickTracking(True, False)
+ tracking_settings.open_tracking = OpenTracking(True, OpenTrackingSubstitutionTag("open_tracking"))
+ tracking_settings.subscription_tracking = SubscriptionTracking(
+ True,
+ SubscriptionText("Goodbye"),
+ SubscriptionHtml("Goodbye!"),
+ SubscriptionSubstitutionTag("unsubscribe"))
+ tracking_settings.ganalytics = Ganalytics(
+ True,
+ UtmSource("utm_source"),
+ UtmMedium("utm_medium"),
+ UtmTerm("utm_term"),
+ UtmContent("utm_content"),
+ UtmCampaign("utm_campaign"))
+ message.tracking_settings = tracking_settings
+
+ return message
+
+def send_multiple_emails_personalized():
+ # Assumes you set your environment variable:
+ # https://github.com/sendgrid/sendgrid-python/blob/HEAD/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key
+ message = build_multiple_emails_personalized()
+ sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
+ response = sendgrid_client.send(message=message)
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+
+def send_hello_email():
+ # Assumes you set your environment variable:
+ # https://github.com/sendgrid/sendgrid-python/blob/HEAD/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key
+ message = build_hello_email()
+ sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
+ response = sendgrid_client.send(message=message)
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+
+
+def send_kitchen_sink():
+ # Assumes you set your environment variable:
+ # https://github.com/sendgrid/sendgrid-python/blob/HEAD/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key
+ message = build_kitchen_sink()
+ sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
+ response = sendgrid_client.send(message=message)
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+
+
+## this will actually send an email
+# send_hello_email()
+
+## this will send multiple emails
+# send_multiple_emails_personalized()
+
+## this will only send an email if you set SandBox Mode to False
+# send_kitchen_sink()
diff --git a/examples/helpers/stats/stats_example.py b/examples/helpers/stats/stats_example.py
new file mode 100644
index 000000000..f22baa5c4
--- /dev/null
+++ b/examples/helpers/stats/stats_example.py
@@ -0,0 +1,101 @@
+import json
+import os
+from sendgrid.helpers.stats import *
+from sendgrid import *
+
+# NOTE: you will need to move this file to the root directory of this project to execute properly.
+
+# Assumes you set your environment variable:
+# See: https://github.com/sendgrid/sendgrid-python/blob/HEAD/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key
+sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
+
+
+def pprint_json(json_raw):
+ print(json.dumps(json.loads(json_raw), indent=2, sort_keys=True))
+
+
+def build_global_stats():
+ global_stats = Stats()
+ global_stats.start_date = '2017-10-14'
+ global_stats.end_date = '2017-10-20'
+ global_stats.aggregated_by = 'day'
+ return global_stats.get()
+
+
+def build_category_stats():
+ category_stats = CategoryStats('2017-10-15', ['foo', 'bar'])
+ # category_stats.start_date = '2017-10-15'
+ # category_stats.add_category(Category("foo"))
+ # category_stats.add_category(Category("bar"))
+ return category_stats.get()
+
+
+def build_category_stats_sums():
+ category_stats = CategoryStats()
+ category_stats.start_date = '2017-10-15'
+ category_stats.limit = 5
+ category_stats.offset = 1
+ return category_stats.get()
+
+
+def build_subuser_stats():
+ subuser_stats = SubuserStats('2017-10-20', ['aaronmakks','foo'])
+ # subuser_stats.start_date = '2017-10-15'
+ # subuser_stats.add_subuser(Subuser("foo"))
+ # subuser_stats.add_subuser(Subuser("bar"))
+ return subuser_stats.get()
+
+
+def build_subuser_stats_sums():
+ subuser_stats = SubuserStats()
+ subuser_stats.start_date = '2017-10-15'
+ subuser_stats.limit = 5
+ subuser_stats.offset = 1
+ return subuser_stats.get()
+
+
+def get_global_stats():
+ stats_params = build_global_stats()
+ response = sg.client.stats.get(query_params=stats_params)
+ print(response.status_code)
+ print(response.headers)
+ pprint_json(response.body)
+
+
+def get_category_stats():
+ stats_params = build_category_stats()
+ response = sg.client.categories.stats.get(query_params=stats_params)
+ print(response.status_code)
+ print(response.headers)
+ pprint_json(response.body)
+
+
+def get_category_stats_sums():
+ stats_params = build_category_stats_sums()
+ response = sg.client.categories.stats.sums.get(query_params=stats_params)
+ print(response.status_code)
+ print(response.headers)
+ pprint_json(response.body)
+
+
+def get_subuser_stats():
+ stats_params = build_subuser_stats()
+ response = sg.client.subusers.stats.get(query_params=stats_params)
+ print(response.status_code)
+ print(response.headers)
+ pprint_json(response.body)
+
+
+def get_subuser_stats_sums():
+ stats_params = build_subuser_stats_sums()
+ response = sg.client.subusers.stats.sums.get(query_params=stats_params)
+ print(response.status_code)
+ print(response.headers)
+ pprint_json(response.body)
+
+
+get_global_stats()
+get_category_stats()
+get_category_stats_sums()
+get_subuser_stats()
+get_subuser_stats_sums()
diff --git a/examples/ips/ips.py b/examples/ips/ips.py
index 6c48ae306..316d0c858 100644
--- a/examples/ips/ips.py
+++ b/examples/ips/ips.py
@@ -1,15 +1,15 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve all IP addresses #
# GET /ips #
-params = {'subuser': 'test_string', 'ip': 'test_string', 'limit': 1, 'exclude_whitelabels': 'true', 'offset': 1}
+params = {'subuser': 'test_string', 'ip': 'test_string',
+ 'limit': 1, 'exclude_whitelabels': 'true', 'offset': 1}
response = sg.client.ips.get(query_params=params)
print(response.status_code)
print(response.body)
@@ -29,7 +29,7 @@
# POST /ips/pools #
data = {
- "name": "marketing"
+ "name": "marketing"
}
response = sg.client.ips.pools.post(request_body=data)
print(response.status_code)
@@ -50,7 +50,7 @@
# PUT /ips/pools/{pool_name} #
data = {
- "name": "new_pool_name"
+ "name": "new_pool_name"
}
pool_name = "test_url_param"
response = sg.client.ips.pools._(pool_name).put(request_body=data)
@@ -83,7 +83,7 @@
# POST /ips/pools/{pool_name}/ips #
data = {
- "ip": "0.0.0.0"
+ "ip": "0.0.0.0"
}
pool_name = "test_url_param"
response = sg.client.ips.pools._(pool_name).ips.post(request_body=data)
@@ -107,7 +107,7 @@
# POST /ips/warmup #
data = {
- "ip": "0.0.0.0"
+ "ip": "0.0.0.0"
}
response = sg.client.ips.warmup.post(request_body=data)
print(response.status_code)
@@ -152,4 +152,3 @@
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/mail/mail.py b/examples/mail/mail.py
index fef420e87..d2ccc80f0 100644
--- a/examples/mail/mail.py
+++ b/examples/mail/mail.py
@@ -1,9 +1,8 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Create a batch ID #
@@ -27,148 +26,148 @@
##################################################
# v3 Mail Send #
# POST /mail/send #
-# This endpoint has a helper, check it out [here](https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/README.md).
+# This endpoint has a helper, check it out
+# [here](https://github.com/sendgrid/sendgrid-python/blob/HEAD/use_cases/README.md).
data = {
- "asm": {
- "group_id": 1,
- "groups_to_display": [
- 1,
- 2,
- 3
- ]
- },
- "attachments": [
- {
- "content": "[BASE64 encoded content block here]",
- "content_id": "ii_139db99fdb5c3704",
- "disposition": "inline",
- "filename": "file1.jpg",
- "name": "file1",
- "type": "jpg"
- }
- ],
- "batch_id": "[YOUR BATCH ID GOES HERE]",
- "categories": [
- "category1",
- "category2"
- ],
- "content": [
- {
- "type": "text/html",
- "value": "Hello, world!
"
- }
- ],
- "custom_args": {
- "New Argument 1": "New Value 1",
- "activationAttempt": "1",
- "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"
- },
- "from": {
- "email": "sam.smith@example.com",
- "name": "Sam Smith"
- },
- "headers": {},
- "ip_pool_name": "[YOUR POOL NAME GOES HERE]",
- "mail_settings": {
- "bcc": {
- "email": "ben.doe@example.com",
- "enable": True
- },
- "bypass_list_management": {
- "enable": True
- },
- "footer": {
- "enable": True,
- "html": "ThanksThe SendGrid Team
",
- "text": "Thanks,/n The SendGrid Team"
- },
- "sandbox_mode": {
- "enable": False
- },
- "spam_check": {
- "enable": True,
- "post_to_url": "http://example.com/compliance",
- "threshold": 3
- }
- },
- "personalizations": [
- {
- "bcc": [
+ "asm": {
+ "group_id": 1,
+ "groups_to_display": [
+ 1,
+ 2,
+ 3
+ ]
+ },
+ "attachments": [
{
- "email": "sam.doe@example.com",
- "name": "Sam Doe"
+ "content": "[BASE64 encoded content block here]",
+ "content_id": "ii_139db99fdb5c3704",
+ "disposition": "inline",
+ "filename": "file1.jpg",
+ "name": "file1",
+ "type": "jpg"
}
- ],
- "cc": [
+ ],
+ "batch_id": "[YOUR BATCH ID GOES HERE]",
+ "categories": [
+ "category1",
+ "category2"
+ ],
+ "content": [
{
- "email": "jane.doe@example.com",
- "name": "Jane Doe"
+ "type": "text/html",
+ "value": "Hello, world!
"
}
- ],
- "custom_args": {
- "New Argument 1": "New Value 1",
- "activationAttempt": "1",
+ ],
+ "custom_args": {
+ "New Argument 1": "New Value 1",
+ "activationAttempt": "1",
"customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"
- },
- "headers": {
- "X-Accept-Language": "en",
- "X-Mailer": "MyApp"
- },
- "send_at": 1409348513,
- "subject": "Hello, World!",
- "substitutions": {
- "id": "substitutions",
- "type": "object"
- },
- "to": [
+ },
+ "from": {
+ "email": "sam.smith@example.com",
+ "name": "Sam Smith"
+ },
+ "headers": {},
+ "ip_pool_name": "[YOUR POOL NAME GOES HERE]",
+ "mail_settings": {
+ "bcc": {
+ "email": "ben.doe@example.com",
+ "enable": True
+ },
+ "bypass_list_management": {
+ "enable": True
+ },
+ "footer": {
+ "enable": True,
+ "html": "ThanksThe SendGrid Team
",
+ "text": "Thanks,/n The SendGrid Team"
+ },
+ "sandbox_mode": {
+ "enable": False
+ },
+ "spam_check": {
+ "enable": True,
+ "post_to_url": "http://example.com/compliance",
+ "threshold": 3
+ }
+ },
+ "personalizations": [
{
- "email": "john.doe@example.com",
- "name": "John Doe"
+ "bcc": [
+ {
+ "email": "sam.doe@example.com",
+ "name": "Sam Doe"
+ }
+ ],
+ "cc": [
+ {
+ "email": "jane.doe@example.com",
+ "name": "Jane Doe"
+ }
+ ],
+ "custom_args": {
+ "New Argument 1": "New Value 1",
+ "activationAttempt": "1",
+ "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"
+ },
+ "headers": {
+ "X-Accept-Language": "en",
+ "X-Mailer": "MyApp"
+ },
+ "send_at": 1409348513,
+ "subject": "Hello, World!",
+ "substitutions": {
+ "id": "substitutions",
+ "type": "object"
+ },
+ "to": [
+ {
+ "email": "john.doe@example.com",
+ "name": "John Doe"
+ }
+ ]
+ }
+ ],
+ "reply_to": {
+ "email": "sam.smith@example.com",
+ "name": "Sam Smith"
+ },
+ "sections": {
+ "section": {
+ ":sectionName1": "section 1 text",
+ ":sectionName2": "section 2 text"
+ }
+ },
+ "send_at": 1409348513,
+ "subject": "Hello, World!",
+ "template_id": "[YOUR TEMPLATE ID GOES HERE]",
+ "tracking_settings": {
+ "click_tracking": {
+ "enable": True,
+ "enable_text": True
+ },
+ "ganalytics": {
+ "enable": True,
+ "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]",
+ "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]",
+ "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]",
+ "utm_name": "[NAME OF YOUR CAMPAIGN]",
+ "utm_term": "[IDENTIFY PAID KEYWORDS HERE]"
+ },
+ "open_tracking": {
+ "enable": True,
+ "substitution_tag": "%opentrack"
+ },
+ "subscription_tracking": {
+ "enable": True,
+ "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
+ "substitution_tag": "<%click here%>",
+ "text": "If you would like to unsubscribe and stop receiving these emails <% click here %>."
}
- ]
- }
- ],
- "reply_to": {
- "email": "sam.smith@example.com",
- "name": "Sam Smith"
- },
- "sections": {
- "section": {
- ":sectionName1": "section 1 text",
- ":sectionName2": "section 2 text"
- }
- },
- "send_at": 1409348513,
- "subject": "Hello, World!",
- "template_id": "[YOUR TEMPLATE ID GOES HERE]",
- "tracking_settings": {
- "click_tracking": {
- "enable": True,
- "enable_text": True
- },
- "ganalytics": {
- "enable": True,
- "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]",
- "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]",
- "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]",
- "utm_name": "[NAME OF YOUR CAMPAIGN]",
- "utm_term": "[IDENTIFY PAID KEYWORDS HERE]"
- },
- "open_tracking": {
- "enable": True,
- "substitution_tag": "%opentrack"
- },
- "subscription_tracking": {
- "enable": True,
- "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
- "substitution_tag": "<%click here%>",
- "text": "If you would like to unsubscribe and stop receiveing these emails <% click here %>."
}
- }
}
response = sg.client.mail.send.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/mailboxproviders/mailboxproviders.py b/examples/mailboxproviders/mailboxproviders.py
index 1b75ecac5..4fbf470e2 100644
--- a/examples/mailboxproviders/mailboxproviders.py
+++ b/examples/mailboxproviders/mailboxproviders.py
@@ -1,17 +1,20 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve email statistics by mailbox provider. #
# GET /mailbox_providers/stats #
-params = {'end_date': '2016-04-01', 'mailbox_providers': 'test_string', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01'}
+params = {'end_date': '2016-04-01',
+ 'mailbox_providers': 'test_string',
+ 'aggregated_by': 'day',
+ 'limit': 1,
+ 'offset': 1,
+ 'start_date': '2016-01-01'}
response = sg.client.mailbox_providers.stats.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/mailsettings/mailsettings.py b/examples/mailsettings/mailsettings.py
index 18c57b960..a4d46e399 100644
--- a/examples/mailsettings/mailsettings.py
+++ b/examples/mailsettings/mailsettings.py
@@ -1,9 +1,8 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve all mail settings #
@@ -20,11 +19,11 @@
# PATCH /mail_settings/address_whitelist #
data = {
- "enabled": True,
- "list": [
- "email1@example.com",
- "example.com"
- ]
+ "enabled": True,
+ "list": [
+ "email1@example.com",
+ "example.com"
+ ]
}
response = sg.client.mail_settings.address_whitelist.patch(request_body=data)
print(response.status_code)
@@ -45,8 +44,8 @@
# PATCH /mail_settings/bcc #
data = {
- "email": "email@example.com",
- "enabled": False
+ "email": "email@example.com",
+ "enabled": False
}
response = sg.client.mail_settings.bcc.patch(request_body=data)
print(response.status_code)
@@ -67,9 +66,9 @@
# PATCH /mail_settings/bounce_purge #
data = {
- "enabled": True,
- "hard_bounces": 5,
- "soft_bounces": 5
+ "enabled": True,
+ "hard_bounces": 5,
+ "soft_bounces": 5
}
response = sg.client.mail_settings.bounce_purge.patch(request_body=data)
print(response.status_code)
@@ -90,9 +89,9 @@
# PATCH /mail_settings/footer #
data = {
- "enabled": True,
- "html_content": "...",
- "plain_content": "..."
+ "enabled": True,
+ "html_content": "...",
+ "plain_content": "..."
}
response = sg.client.mail_settings.footer.patch(request_body=data)
print(response.status_code)
@@ -113,8 +112,8 @@
# PATCH /mail_settings/forward_bounce #
data = {
- "email": "example@example.com",
- "enabled": True
+ "email": "example@example.com",
+ "enabled": True
}
response = sg.client.mail_settings.forward_bounce.patch(request_body=data)
print(response.status_code)
@@ -135,8 +134,8 @@
# PATCH /mail_settings/forward_spam #
data = {
- "email": "",
- "enabled": False
+ "email": "",
+ "enabled": False
}
response = sg.client.mail_settings.forward_spam.patch(request_body=data)
print(response.status_code)
@@ -157,7 +156,7 @@
# PATCH /mail_settings/plain_content #
data = {
- "enabled": False
+ "enabled": False
}
response = sg.client.mail_settings.plain_content.patch(request_body=data)
print(response.status_code)
@@ -178,9 +177,9 @@
# PATCH /mail_settings/spam_check #
data = {
- "enabled": True,
- "max_score": 5,
- "url": "url"
+ "enabled": True,
+ "max_score": 5,
+ "url": "url"
}
response = sg.client.mail_settings.spam_check.patch(request_body=data)
print(response.status_code)
@@ -201,8 +200,8 @@
# PATCH /mail_settings/template #
data = {
- "enabled": True,
- "html_content": "<% body %>"
+ "enabled": True,
+ "html_content": "<% body %>"
}
response = sg.client.mail_settings.template.patch(request_body=data)
print(response.status_code)
@@ -217,4 +216,3 @@
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/partnersettings/partnersettings.py b/examples/partnersettings/partnersettings.py
index 37f77f4e6..d3675a6ba 100644
--- a/examples/partnersettings/partnersettings.py
+++ b/examples/partnersettings/partnersettings.py
@@ -1,9 +1,8 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Returns a list of all partner settings. #
@@ -20,9 +19,9 @@
# PATCH /partner_settings/new_relic #
data = {
- "enable_subuser_statistics": True,
- "enabled": True,
- "license_key": ""
+ "enable_subuser_statistics": True,
+ "enabled": True,
+ "license_key": ""
}
response = sg.client.partner_settings.new_relic.patch(request_body=data)
print(response.status_code)
@@ -37,4 +36,3 @@
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/scopes/scopes.py b/examples/scopes/scopes.py
index 124f77d39..99519dc3e 100644
--- a/examples/scopes/scopes.py
+++ b/examples/scopes/scopes.py
@@ -1,9 +1,8 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve a list of scopes for which this user has access. #
@@ -13,4 +12,3 @@
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/whitelabel/whitelabel.py b/examples/senderauthentication/senderauthentication.py
similarity index 67%
rename from examples/whitelabel/whitelabel.py
rename to examples/senderauthentication/senderauthentication.py
index f529d3ed2..f842d9302 100644
--- a/examples/whitelabel/whitelabel.py
+++ b/examples/senderauthentication/senderauthentication.py
@@ -3,23 +3,23 @@
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
-# Create a domain whitelabel. #
+# Create a domain authentication. #
# POST /whitelabel/domains #
data = {
- "automatic_security": False,
- "custom_spf": True,
- "default": True,
- "domain": "example.com",
- "ips": [
- "192.168.1.1",
- "192.168.1.2"
- ],
- "subdomain": "news",
- "username": "john@example.com"
+ "automatic_security": False,
+ "custom_spf": True,
+ "default": True,
+ "domain": "example.com",
+ "ips": [
+ "192.168.1.1",
+ "192.168.1.2"
+ ],
+ "subdomain": "news",
+ "username": "john@example.com"
}
response = sg.client.whitelabel.domains.post(request_body=data)
print(response.status_code)
@@ -27,17 +27,18 @@
print(response.headers)
##################################################
-# List all domain whitelabels. #
+# List all domain authentications. #
# GET /whitelabel/domains #
-params = {'username': 'test_string', 'domain': 'test_string', 'exclude_subusers': 'true', 'limit': 1, 'offset': 1}
+params = {'username': 'test_string', 'domain': 'test_string',
+ 'exclude_subusers': 'true', 'limit': 1, 'offset': 1}
response = sg.client.whitelabel.domains.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Get the default domain whitelabel. #
+# Get the default domain authentication. #
# GET /whitelabel/domains/default #
response = sg.client.whitelabel.domains.default.get()
@@ -46,7 +47,7 @@
print(response.headers)
##################################################
-# List the domain whitelabel associated with the given user. #
+# List the domain authentication associated with the given user. #
# GET /whitelabel/domains/subuser #
response = sg.client.whitelabel.domains.subuser.get()
@@ -55,7 +56,7 @@
print(response.headers)
##################################################
-# Disassociate a domain whitelabel from a given user. #
+# Disassociate a domain authentication from a given user. #
# DELETE /whitelabel/domains/subuser #
response = sg.client.whitelabel.domains.subuser.delete()
@@ -64,12 +65,12 @@
print(response.headers)
##################################################
-# Update a domain whitelabel. #
+# Update a domain authentication. #
# PATCH /whitelabel/domains/{domain_id} #
data = {
- "custom_spf": True,
- "default": False
+ "custom_spf": True,
+ "default": False
}
domain_id = "test_url_param"
response = sg.client.whitelabel.domains._(domain_id).patch(request_body=data)
@@ -78,7 +79,7 @@
print(response.headers)
##################################################
-# Retrieve a domain whitelabel. #
+# Retrieve a domain authentication. #
# GET /whitelabel/domains/{domain_id} #
domain_id = "test_url_param"
@@ -88,7 +89,7 @@
print(response.headers)
##################################################
-# Delete a domain whitelabel. #
+# Delete a domain authentication. #
# DELETE /whitelabel/domains/{domain_id} #
domain_id = "test_url_param"
@@ -98,60 +99,61 @@
print(response.headers)
##################################################
-# Associate a domain whitelabel with a given user. #
+# Associate a domain authentication with a given user. #
# POST /whitelabel/domains/{domain_id}/subuser #
data = {
- "username": "jane@example.com"
+ "username": "jane@example.com"
}
domain_id = "test_url_param"
-response = sg.client.whitelabel.domains._(domain_id).subuser.post(request_body=data)
+response = sg.client.whitelabel.domains._(
+ domain_id).subuser.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Add an IP to a domain whitelabel. #
+# Add an IP to a domain authentication. #
# POST /whitelabel/domains/{id}/ips #
data = {
- "ip": "192.168.0.1"
+ "ip": "192.168.0.1"
}
-id = "test_url_param"
-response = sg.client.whitelabel.domains._(id).ips.post(request_body=data)
+id_ = "test_url_param"
+response = sg.client.whitelabel.domains._(id_).ips.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Remove an IP from a domain whitelabel. #
+# Remove an IP from a domain authentication. #
# DELETE /whitelabel/domains/{id}/ips/{ip} #
-id = "test_url_param"
+id_ = "test_url_param"
ip = "test_url_param"
-response = sg.client.whitelabel.domains._(id).ips._(ip).delete()
+response = sg.client.whitelabel.domains._(id_).ips._(ip).delete()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Validate a domain whitelabel. #
+# Validate a domain authentication. #
# POST /whitelabel/domains/{id}/validate #
-id = "test_url_param"
-response = sg.client.whitelabel.domains._(id).validate.post()
+id_ = "test_url_param"
+response = sg.client.whitelabel.domains._(id_).validate.post()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Create an IP whitelabel #
+# Create a reverse DNS record #
# POST /whitelabel/ips #
data = {
- "domain": "example.com",
- "ip": "192.168.1.1",
- "subdomain": "email"
+ "domain": "example.com",
+ "ip": "192.168.1.1",
+ "subdomain": "email"
}
response = sg.client.whitelabel.ips.post(request_body=data)
print(response.status_code)
@@ -159,7 +161,7 @@
print(response.headers)
##################################################
-# Retrieve all IP whitelabels #
+# Create a reverse DNS record #
# GET /whitelabel/ips #
params = {'ip': 'test_string', 'limit': 1, 'offset': 1}
@@ -169,52 +171,53 @@
print(response.headers)
##################################################
-# Retrieve an IP whitelabel #
+# Retrieve a reverse DNS record #
# GET /whitelabel/ips/{id} #
-id = "test_url_param"
-response = sg.client.whitelabel.ips._(id).get()
+id_ = "test_url_param"
+response = sg.client.whitelabel.ips._(id_).get()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Delete an IP whitelabel #
+# Delete a reverse DNS record #
# DELETE /whitelabel/ips/{id} #
-id = "test_url_param"
-response = sg.client.whitelabel.ips._(id).delete()
+id_ = "test_url_param"
+response = sg.client.whitelabel.ips._(id_).delete()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Validate an IP whitelabel #
+# Validate a reverse DNS record #
# POST /whitelabel/ips/{id}/validate #
-id = "test_url_param"
-response = sg.client.whitelabel.ips._(id).validate.post()
+id_ = "test_url_param"
+response = sg.client.whitelabel.ips._(id_).validate.post()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Create a Link Whitelabel #
+# Create a Link Branding #
# POST /whitelabel/links #
data = {
- "default": True,
- "domain": "example.com",
- "subdomain": "mail"
+ "default": True,
+ "domain": "example.com",
+ "subdomain": "mail"
}
params = {'limit': 1, 'offset': 1}
-response = sg.client.whitelabel.links.post(request_body=data, query_params=params)
+response = sg.client.whitelabel.links.post(
+ request_body=data, query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Retrieve all link whitelabels #
+# Retrieve all link brandings #
# GET /whitelabel/links #
params = {'limit': 1}
@@ -224,7 +227,7 @@
print(response.headers)
##################################################
-# Retrieve a Default Link Whitelabel #
+# Retrieve a Default Link Branding #
# GET /whitelabel/links/default #
params = {'domain': 'test_string'}
@@ -234,7 +237,7 @@
print(response.headers)
##################################################
-# Retrieve Associated Link Whitelabel #
+# Retrieve Associated Link Branding #
# GET /whitelabel/links/subuser #
params = {'username': 'test_string'}
@@ -244,7 +247,7 @@
print(response.headers)
##################################################
-# Disassociate a Link Whitelabel #
+# Disassociate a Link Branding #
# DELETE /whitelabel/links/subuser #
params = {'username': 'test_string'}
@@ -254,58 +257,58 @@
print(response.headers)
##################################################
-# Update a Link Whitelabel #
+# Update a Link Branding #
# PATCH /whitelabel/links/{id} #
data = {
- "default": True
+ "default": True
}
-id = "test_url_param"
-response = sg.client.whitelabel.links._(id).patch(request_body=data)
+id_ = "test_url_param"
+response = sg.client.whitelabel.links._(id_).patch(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Retrieve a Link Whitelabel #
+# Retrieve a Link Branding #
# GET /whitelabel/links/{id} #
-id = "test_url_param"
-response = sg.client.whitelabel.links._(id).get()
+id_ = "test_url_param"
+response = sg.client.whitelabel.links._(id_).get()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Delete a Link Whitelabel #
+# Delete a Link Branding #
# DELETE /whitelabel/links/{id} #
-id = "test_url_param"
-response = sg.client.whitelabel.links._(id).delete()
+id_ = "test_url_param"
+response = sg.client.whitelabel.links._(id_).delete()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Validate a Link Whitelabel #
+# Validate a Link Branding #
# POST /whitelabel/links/{id}/validate #
-id = "test_url_param"
-response = sg.client.whitelabel.links._(id).validate.post()
+id_ = "test_url_param"
+response = sg.client.whitelabel.links._(id_).validate.post()
print(response.status_code)
print(response.body)
print(response.headers)
##################################################
-# Associate a Link Whitelabel #
+# Associate a Link Branding #
# POST /whitelabel/links/{link_id}/subuser #
data = {
- "username": "jane@example.com"
+ "username": "jane@example.com"
}
link_id = "test_url_param"
-response = sg.client.whitelabel.links._(link_id).subuser.post(request_body=data)
+response = sg.client.whitelabel.links._(
+ link_id).subuser.post(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/senders/senders.py b/examples/senders/senders.py
index f21459b71..55eb44631 100644
--- a/examples/senders/senders.py
+++ b/examples/senders/senders.py
@@ -1,30 +1,29 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Create a Sender Identity #
# POST /senders #
data = {
- "address": "123 Elm St.",
- "address_2": "Apt. 456",
- "city": "Denver",
- "country": "United States",
- "from": {
- "email": "from@example.com",
- "name": "Example INC"
- },
- "nickname": "My Sender ID",
- "reply_to": {
- "email": "replyto@example.com",
- "name": "Example INC"
- },
- "state": "Colorado",
- "zip": "80202"
+ "address": "123 Elm St.",
+ "address_2": "Apt. 456",
+ "city": "Denver",
+ "country": "United States",
+ "from": {
+ "email": "from@example.com",
+ "name": "Example INC"
+ },
+ "nickname": "My Sender ID",
+ "reply_to": {
+ "email": "replyto@example.com",
+ "name": "Example INC"
+ },
+ "state": "Colorado",
+ "zip": "80202"
}
response = sg.client.senders.post(request_body=data)
print(response.status_code)
@@ -45,21 +44,21 @@
# PATCH /senders/{sender_id} #
data = {
- "address": "123 Elm St.",
- "address_2": "Apt. 456",
- "city": "Denver",
- "country": "United States",
- "from": {
- "email": "from@example.com",
- "name": "Example INC"
- },
- "nickname": "My Sender ID",
- "reply_to": {
- "email": "replyto@example.com",
- "name": "Example INC"
- },
- "state": "Colorado",
- "zip": "80202"
+ "address": "123 Elm St.",
+ "address_2": "Apt. 456",
+ "city": "Denver",
+ "country": "United States",
+ "from": {
+ "email": "from@example.com",
+ "name": "Example INC"
+ },
+ "nickname": "My Sender ID",
+ "reply_to": {
+ "email": "replyto@example.com",
+ "name": "Example INC"
+ },
+ "state": "Colorado",
+ "zip": "80202"
}
sender_id = "test_url_param"
response = sg.client.senders._(sender_id).patch(request_body=data)
@@ -96,4 +95,3 @@
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/stats/stats.py b/examples/stats/stats.py
index a7bf3362e..cde422447 100644
--- a/examples/stats/stats.py
+++ b/examples/stats/stats.py
@@ -1,17 +1,16 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve global email statistics #
# GET /stats #
-params = {'aggregated_by': 'day', 'limit': 1, 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 1}
+params = {'aggregated_by': 'day', 'limit': 1,
+ 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 1}
response = sg.client.stats.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/subusers/subusers.py b/examples/subusers/subusers.py
index 6aa91e535..0f5ba6fe0 100644
--- a/examples/subusers/subusers.py
+++ b/examples/subusers/subusers.py
@@ -1,22 +1,21 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Create Subuser #
# POST /subusers #
data = {
- "email": "John@example.com",
- "ips": [
- "1.1.1.1",
- "2.2.2.2"
- ],
- "password": "johns_password",
- "username": "John@example.com"
+ "email": "John@example.com",
+ "ips": [
+ "1.1.1.1",
+ "2.2.2.2"
+ ],
+ "password": "johns_password",
+ "username": "John@example.com"
}
response = sg.client.subusers.post(request_body=data)
print(response.status_code)
@@ -47,7 +46,12 @@
# Retrieve email statistics for your subusers. #
# GET /subusers/stats #
-params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'offset': 1, 'start_date': '2016-01-01', 'subusers': 'test_string'}
+params = {'end_date': '2016-04-01',
+ 'aggregated_by': 'day',
+ 'limit': 1,
+ 'offset': 1,
+ 'start_date': '2016-01-01',
+ 'subusers': 'test_string'}
response = sg.client.subusers.stats.get(query_params=params)
print(response.status_code)
print(response.body)
@@ -57,7 +61,12 @@
# Retrieve monthly stats for all subusers #
# GET /subusers/stats/monthly #
-params = {'subuser': 'test_string', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'date': 'test_string', 'sort_by_direction': 'asc'}
+params = {'subuser': 'test_string',
+ 'limit': 1,
+ 'sort_by_metric': 'test_string',
+ 'offset': 1,
+ 'date': 'test_string',
+ 'sort_by_direction': 'asc'}
response = sg.client.subusers.stats.monthly.get(query_params=params)
print(response.status_code)
print(response.body)
@@ -67,7 +76,13 @@
# Retrieve the totals for each email statistic metric for all subusers. #
# GET /subusers/stats/sums #
-params = {'end_date': '2016-04-01', 'aggregated_by': 'day', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1, 'start_date': '2016-01-01', 'sort_by_direction': 'asc'}
+params = {'end_date': '2016-04-01',
+ 'aggregated_by': 'day',
+ 'limit': 1,
+ 'sort_by_metric': 'test_string',
+ 'offset': 1,
+ 'start_date': '2016-01-01',
+ 'sort_by_direction': 'asc'}
response = sg.client.subusers.stats.sums.get(query_params=params)
print(response.status_code)
print(response.body)
@@ -78,7 +93,7 @@
# PATCH /subusers/{subuser_name} #
data = {
- "disabled": False
+ "disabled": False
}
subuser_name = "test_url_param"
response = sg.client.subusers._(subuser_name).patch(request_body=data)
@@ -101,7 +116,7 @@
# PUT /subusers/{subuser_name}/ips #
data = [
- "127.0.0.1"
+ "127.0.0.1"
]
subuser_name = "test_url_param"
response = sg.client.subusers._(subuser_name).ips.put(request_body=data)
@@ -114,8 +129,8 @@
# PUT /subusers/{subuser_name}/monitor #
data = {
- "email": "example@example.com",
- "frequency": 500
+ "email": "example@example.com",
+ "frequency": 500
}
subuser_name = "test_url_param"
response = sg.client.subusers._(subuser_name).monitor.put(request_body=data)
@@ -128,8 +143,8 @@
# POST /subusers/{subuser_name}/monitor #
data = {
- "email": "example@example.com",
- "frequency": 50000
+ "email": "example@example.com",
+ "frequency": 50000
}
subuser_name = "test_url_param"
response = sg.client.subusers._(subuser_name).monitor.post(request_body=data)
@@ -161,10 +176,14 @@
# Retrieve the monthly email statistics for a single subuser #
# GET /subusers/{subuser_name}/stats/monthly #
-params = {'date': 'test_string', 'sort_by_direction': 'asc', 'limit': 1, 'sort_by_metric': 'test_string', 'offset': 1}
+params = {'date': 'test_string',
+ 'sort_by_direction': 'asc',
+ 'limit': 1,
+ 'sort_by_metric': 'test_string',
+ 'offset': 1}
subuser_name = "test_url_param"
-response = sg.client.subusers._(subuser_name).stats.monthly.get(query_params=params)
+response = sg.client.subusers._(
+ subuser_name).stats.monthly.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/suppression/suppression.py b/examples/suppression/suppression.py
index abdaef76d..430f76f35 100644
--- a/examples/suppression/suppression.py
+++ b/examples/suppression/suppression.py
@@ -1,9 +1,8 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve all blocks #
@@ -20,11 +19,11 @@
# DELETE /suppression/blocks #
data = {
- "delete_all": False,
- "emails": [
- "example1@example.com",
- "example2@example.com"
- ]
+ "delete_all": False,
+ "emails": [
+ "example1@example.com",
+ "example2@example.com"
+ ]
}
response = sg.client.suppression.blocks.delete(request_body=data)
print(response.status_code)
@@ -66,11 +65,11 @@
# DELETE /suppression/bounces #
data = {
- "delete_all": True,
- "emails": [
- "example@example.com",
- "example2@example.com"
- ]
+ "delete_all": True,
+ "emails": [
+ "example@example.com",
+ "example2@example.com"
+ ]
}
response = sg.client.suppression.bounces.delete(request_body=data)
print(response.status_code)
@@ -113,11 +112,11 @@
# DELETE /suppression/invalid_emails #
data = {
- "delete_all": False,
- "emails": [
- "example1@example.com",
- "example2@example.com"
- ]
+ "delete_all": False,
+ "emails": [
+ "example1@example.com",
+ "example2@example.com"
+ ]
}
response = sg.client.suppression.invalid_emails.delete(request_body=data)
print(response.status_code)
@@ -179,11 +178,11 @@
# DELETE /suppression/spam_reports #
data = {
- "delete_all": False,
- "emails": [
- "example1@example.com",
- "example2@example.com"
- ]
+ "delete_all": False,
+ "emails": [
+ "example1@example.com",
+ "example2@example.com"
+ ]
}
response = sg.client.suppression.spam_reports.delete(request_body=data)
print(response.status_code)
@@ -199,4 +198,3 @@
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/templates/templates.py b/examples/templates/templates.py
index 9d3d5dd4b..9b5210191 100644
--- a/examples/templates/templates.py
+++ b/examples/templates/templates.py
@@ -1,16 +1,15 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Create a transactional template. #
# POST /templates #
data = {
- "name": "example_name"
+ "name": "example_name"
}
response = sg.client.templates.post(request_body=data)
print(response.status_code)
@@ -31,7 +30,7 @@
# PATCH /templates/{template_id} #
data = {
- "name": "new_example_name"
+ "name": "new_example_name"
}
template_id = "test_url_param"
response = sg.client.templates._(template_id).patch(request_body=data)
@@ -64,12 +63,12 @@
# POST /templates/{template_id}/versions #
data = {
- "active": 1,
- "html_content": "<%body%>",
- "name": "example_version_name",
- "plain_content": "<%body%>",
- "subject": "<%subject%>",
- "template_id": "ddb96bbc-9b92-425e-8979-99464621b543"
+ "active": 1,
+ "html_content": "<%body%>",
+ "name": "example_version_name",
+ "plain_content": "<%body%>",
+ "subject": "<%subject%>",
+ "template_id": "ddb96bbc-9b92-425e-8979-99464621b543"
}
template_id = "test_url_param"
response = sg.client.templates._(template_id).versions.post(request_body=data)
@@ -82,15 +81,16 @@
# PATCH /templates/{template_id}/versions/{version_id} #
data = {
- "active": 1,
- "html_content": "<%body%>",
- "name": "updated_example_name",
- "plain_content": "<%body%>",
- "subject": "<%subject%>"
+ "active": 1,
+ "html_content": "<%body%>",
+ "name": "updated_example_name",
+ "plain_content": "<%body%>",
+ "subject": "<%subject%>"
}
template_id = "test_url_param"
version_id = "test_url_param"
-response = sg.client.templates._(template_id).versions._(version_id).patch(request_body=data)
+response = sg.client.templates._(template_id).versions._(
+ version_id).patch(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
@@ -123,8 +123,8 @@
template_id = "test_url_param"
version_id = "test_url_param"
-response = sg.client.templates._(template_id).versions._(version_id).activate.post()
+response = sg.client.templates._(
+ template_id).versions._(version_id).activate.post()
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/trackingsettings/trackingsettings.py b/examples/trackingsettings/trackingsettings.py
index 80dbe243a..b3c49f8b2 100644
--- a/examples/trackingsettings/trackingsettings.py
+++ b/examples/trackingsettings/trackingsettings.py
@@ -1,9 +1,8 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Retrieve Tracking Settings #
@@ -20,7 +19,7 @@
# PATCH /tracking_settings/click #
data = {
- "enabled": True
+ "enabled": True
}
response = sg.client.tracking_settings.click.patch(request_body=data)
print(response.status_code)
@@ -41,14 +40,15 @@
# PATCH /tracking_settings/google_analytics #
data = {
- "enabled": True,
- "utm_campaign": "website",
- "utm_content": "",
- "utm_medium": "email",
- "utm_source": "sendgrid.com",
- "utm_term": ""
+ "enabled": True,
+ "utm_campaign": "website",
+ "utm_content": "",
+ "utm_medium": "email",
+ "utm_source": "sendgrid.com",
+ "utm_term": ""
}
-response = sg.client.tracking_settings.google_analytics.patch(request_body=data)
+response = sg.client.tracking_settings.google_analytics.patch(
+ request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
@@ -67,7 +67,7 @@
# PATCH /tracking_settings/open #
data = {
- "enabled": True
+ "enabled": True
}
response = sg.client.tracking_settings.open.patch(request_body=data)
print(response.status_code)
@@ -88,12 +88,12 @@
# PATCH /tracking_settings/subscription #
data = {
- "enabled": True,
- "html_content": "html content",
- "landing": "landing page html",
- "plain_content": "text content",
- "replace": "replacement tag",
- "url": "url"
+ "enabled": True,
+ "html_content": "html content",
+ "landing": "landing page html",
+ "plain_content": "text content",
+ "replace": "replacement tag",
+ "url": "url"
}
response = sg.client.tracking_settings.subscription.patch(request_body=data)
print(response.status_code)
@@ -108,4 +108,3 @@
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/examples/user/user.py b/examples/user/user.py
index 9e3f24766..5160f9ff8 100644
--- a/examples/user/user.py
+++ b/examples/user/user.py
@@ -1,9 +1,8 @@
import sendgrid
-import json
import os
-sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
+sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
##################################################
# Get a user's account information. #
@@ -28,7 +27,7 @@
# PUT /user/email #
data = {
- "email": "example@example.com"
+ "email": "example@example.com"
}
response = sg.client.user.email.put(request_body=data)
print(response.status_code)
@@ -49,8 +48,8 @@
# PUT /user/password #
data = {
- "new_password": "new_password",
- "old_password": "old_password"
+ "new_password": "new_password",
+ "old_password": "old_password"
}
response = sg.client.user.password.put(request_body=data)
print(response.status_code)
@@ -62,9 +61,9 @@
# PATCH /user/profile #
data = {
- "city": "Orange",
- "first_name": "Example",
- "last_name": "User"
+ "city": "Orange",
+ "first_name": "Example",
+ "last_name": "User"
}
response = sg.client.user.profile.patch(request_body=data)
print(response.status_code)
@@ -85,8 +84,8 @@
# POST /user/scheduled_sends #
data = {
- "batch_id": "YOUR_BATCH_ID",
- "status": "pause"
+ "batch_id": "YOUR_BATCH_ID",
+ "status": "pause"
}
response = sg.client.user.scheduled_sends.post(request_body=data)
print(response.status_code)
@@ -107,7 +106,7 @@
# PATCH /user/scheduled_sends/{batch_id} #
data = {
- "status": "pause"
+ "status": "pause"
}
batch_id = "test_url_param"
response = sg.client.user.scheduled_sends._(batch_id).patch(request_body=data)
@@ -140,8 +139,8 @@
# PATCH /user/settings/enforced_tls #
data = {
- "require_tls": True,
- "require_valid_cert": False
+ "require_tls": True,
+ "require_valid_cert": False
}
response = sg.client.user.settings.enforced_tls.patch(request_body=data)
print(response.status_code)
@@ -162,7 +161,7 @@
# PUT /user/username #
data = {
- "username": "test_username"
+ "username": "test_username"
}
response = sg.client.user.username.put(request_body=data)
print(response.status_code)
@@ -183,19 +182,19 @@
# PATCH /user/webhooks/event/settings #
data = {
- "bounce": True,
- "click": True,
- "deferred": True,
- "delivered": True,
- "dropped": True,
- "enabled": True,
- "group_resubscribe": True,
- "group_unsubscribe": True,
- "open": True,
- "processed": True,
- "spam_report": True,
- "unsubscribe": True,
- "url": "url"
+ "bounce": True,
+ "click": True,
+ "deferred": True,
+ "delivered": True,
+ "dropped": True,
+ "enabled": True,
+ "group_resubscribe": True,
+ "group_unsubscribe": True,
+ "open": True,
+ "processed": True,
+ "spam_report": True,
+ "unsubscribe": True,
+ "url": "url"
}
response = sg.client.user.webhooks.event.settings.patch(request_body=data)
print(response.status_code)
@@ -216,7 +215,7 @@
# POST /user/webhooks/event/test #
data = {
- "url": "url"
+ "url": "url"
}
response = sg.client.user.webhooks.event.test.post(request_body=data)
print(response.status_code)
@@ -228,10 +227,10 @@
# POST /user/webhooks/parse/settings #
data = {
- "hostname": "myhostname.com",
- "send_raw": False,
- "spam_check": True,
- "url": "http://email.myhosthame.com"
+ "hostname": "myhostname.com",
+ "send_raw": False,
+ "spam_check": True,
+ "url": "http://email.myhosthame.com"
}
response = sg.client.user.webhooks.parse.settings.post(request_body=data)
print(response.status_code)
@@ -252,12 +251,13 @@
# PATCH /user/webhooks/parse/settings/{hostname} #
data = {
- "send_raw": True,
- "spam_check": False,
- "url": "http://newdomain.com/parse"
+ "send_raw": True,
+ "spam_check": False,
+ "url": "http://newdomain.com/parse"
}
hostname = "test_url_param"
-response = sg.client.user.webhooks.parse.settings._(hostname).patch(request_body=data)
+response = sg.client.user.webhooks.parse.settings._(
+ hostname).patch(request_body=data)
print(response.status_code)
print(response.body)
print(response.headers)
@@ -286,9 +286,12 @@
# Retrieves Inbound Parse Webhook statistics. #
# GET /user/webhooks/parse/stats #
-params = {'aggregated_by': 'day', 'limit': 'test_string', 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 'test_string'}
+params = {'aggregated_by': 'day',
+ 'limit': 'test_string',
+ 'start_date': '2016-01-01',
+ 'end_date': '2016-04-01',
+ 'offset': 'test_string'}
response = sg.client.user.webhooks.parse.stats.get(query_params=params)
print(response.status_code)
print(response.body)
print(response.headers)
-
diff --git a/live_test.py b/live_test.py
new file mode 100644
index 000000000..d666140fb
--- /dev/null
+++ b/live_test.py
@@ -0,0 +1,357 @@
+## Send a Single Email to a Single Recipient
+import os
+import json
+from sendgrid import SendGridAPIClient
+from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, SendGridException
+
+message = Mail(from_email=From('help@twilio.com', 'Twilio SendGrid'),
+ to_emails=To('ethomas@twilio.com', 'Elmer Thomas'),
+ subject=Subject('Sending with SendGrid is Fun'),
+ plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'),
+ html_content=HtmlContent('and easy to do anywhere, even with Python'))
+
+try:
+ print(json.dumps(message.get(), sort_keys=True, indent=4))
+ sendgrid_client = SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
+ response = sendgrid_client.send(message=message)
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+except SendGridException as e:
+ print(e.message)
+
+# Send a Single Email to Multiple Recipients
+import os
+import json
+from sendgrid import SendGridAPIClient
+from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, SendGridException
+
+to_emails = [
+ To('ethomas@twilio.com', 'Elmer SendGrid'),
+ To('elmer.thomas@gmail.com', 'Elmer Thomas')
+]
+message = Mail(from_email=From('help@twilio.com', 'Twilio SendGrid'),
+ to_emails=to_emails,
+ subject=Subject('Sending with SendGrid is Fun'),
+ plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'),
+ html_content=HtmlContent('and easy to do anywhere, even with Python'))
+
+try:
+ print(json.dumps(message.get(), sort_keys=True, indent=4))
+ sendgrid_client = SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
+ response = sendgrid_client.send(message=message)
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+except SendGridException as e:
+ print(e.message)
+
+# Send Multiple Emails to Multiple Recipients
+
+import os
+import json
+from sendgrid import SendGridAPIClient
+from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, SendGridException, Substitution
+import time
+import datetime
+
+to_emails = [
+ To(email='ethomas@twilio.com',
+ name='Elmer Twilio',
+ substitutions={
+ Substitution('-name-', 'Elmer Twilio'),
+ Substitution('-github-', 'http://github.com/ethomas'),
+ },
+ subject=Subject('Override Global Subject')),
+ To(email='elmer.thomas@gmail.com',
+ name='Elmer Thomas',
+ substitutions={
+ Substitution('-name-', 'Elmer Thomas'),
+ Substitution('-github-', 'http://github.com/thinkingserious'),
+ })
+]
+ts = time.time()
+global_substitutions = Substitution('-time-', datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))
+message = Mail(from_email=From('help@twilio.com', 'Twilio SendGrid'),
+ to_emails=to_emails,
+ subject=Subject('Hi -name-'),
+ plain_text_content=PlainTextContent('Hello -name-, your github is -github-, email sent at -time-'),
+ html_content=HtmlContent('Hello -name-, your github is here email sent at -time-'),
+ global_substitutions=global_substitutions,
+ is_multiple=True)
+
+try:
+ print(json.dumps(message.get(), sort_keys=True, indent=4))
+ sendgrid_client = SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
+ response = sendgrid_client.send(message=message)
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+except SendGridException as e:
+ print(e.message)
+
+# Kitchen Sink - an example with all settings used
+
+import os
+import json
+from sendgrid import SendGridAPIClient
+from sendgrid.helpers.mail import (
+ Mail, From, To, Cc, Bcc, Subject, PlainTextContent,
+ HtmlContent, SendGridException, Substitution,
+ Header, CustomArg, SendAt, Content, MimeType, Attachment,
+ FileName, FileContent, FileType, Disposition, ContentId,
+ TemplateId, Section, ReplyTo, Category, BatchId, Asm,
+ GroupId, GroupsToDisplay, IpPoolName, MailSettings,
+ BccSettings, BccSettingsEmail, BypassListManagement,
+ FooterSettings, FooterText, FooterHtml, SandBoxMode,
+ SpamCheck, SpamThreshold, SpamUrl, TrackingSettings,
+ ClickTracking, SubscriptionTracking, SubscriptionText,
+ SubscriptionHtml, SubscriptionSubstitutionTag,
+ OpenTracking, OpenTrackingSubstitutionTag, Ganalytics,
+ UtmSource, UtmMedium, UtmTerm, UtmContent, UtmCampaign)
+import time
+import datetime
+
+message = Mail()
+
+# Define Personalizations
+
+message.to = To('elmer+test1@sendgrid.com', 'Example User1', p=0)
+message.to = [
+ To('elmer+test2@sendgrid.com', 'Example User2', p=0),
+ To('elmer+test3@sendgrid.com', 'Example User3', p=0)
+]
+
+message.cc = Cc('test4@example.com', 'Example User4', p=0)
+message.cc = [
+ Cc('test5@example.com', 'Example User5', p=0),
+ Cc('test6@example.com', 'Example User6', p=0)
+]
+
+message.bcc = Bcc('test7@example.com', 'Example User7', p=0)
+message.bcc = [
+ Bcc('test8@example.com', 'Example User8', p=0),
+ Bcc('test9@example.com', 'Example User9', p=0)
+]
+
+message.subject = Subject('Sending with SendGrid is Fun 0', p=0)
+
+message.header = Header('X-Test1', 'Test1', p=0)
+message.header = Header('X-Test2', 'Test2', p=0)
+message.header = [
+ Header('X-Test3', 'Test3', p=0),
+ Header('X-Test4', 'Test4', p=0)
+]
+
+message.substitution = Substitution('%name1%', 'Example Name 1', p=0)
+message.substitution = Substitution('%city1%', 'Example City 1', p=0)
+message.substitution = [
+ Substitution('%name2%', 'Example Name 2', p=0),
+ Substitution('%city2%', 'Example City 2', p=0)
+]
+
+message.custom_arg = CustomArg('marketing1', 'true', p=0)
+message.custom_arg = CustomArg('transactional1', 'false', p=0)
+message.custom_arg = [
+ CustomArg('marketing2', 'false', p=0),
+ CustomArg('transactional2', 'true', p=0)
+]
+
+message.send_at = SendAt(1461775051, p=0)
+
+message.to = To('test10@example.com', 'Example User10', p=1)
+message.to = [
+ To('test11@example.com', 'Example User11', p=1),
+ To('test12@example.com', 'Example User12', p=1)
+]
+
+message.cc = Cc('test13@example.com', 'Example User13', p=1)
+message.cc = [
+ Cc('test14@example.com', 'Example User14', p=1),
+ Cc('test15@example.com', 'Example User15', p=1)
+]
+
+message.bcc = Bcc('test16@example.com', 'Example User16', p=1)
+message.bcc = [
+ Bcc('test17@example.com', 'Example User17', p=1),
+ Bcc('test18@example.com', 'Example User18', p=1)
+]
+
+message.header = Header('X-Test5', 'Test5', p=1)
+message.header = Header('X-Test6', 'Test6', p=1)
+message.header = [
+ Header('X-Test7', 'Test7', p=1),
+ Header('X-Test8', 'Test8', p=1)
+]
+
+message.substitution = Substitution('%name3%', 'Example Name 3', p=1)
+message.substitution = Substitution('%city3%', 'Example City 3', p=1)
+message.substitution = [
+ Substitution('%name4%', 'Example Name 4', p=1),
+ Substitution('%city4%', 'Example City 4', p=1)
+]
+
+message.custom_arg = CustomArg('marketing3', 'true', p=1)
+message.custom_arg = CustomArg('transactional3', 'false', p=1)
+message.custom_arg = [
+ CustomArg('marketing4', 'false', p=1),
+ CustomArg('transactional4', 'true', p=1)
+]
+
+message.send_at = SendAt(1461775052, p=1)
+
+message.subject = Subject('Sending with SendGrid is Fun 1', p=1)
+
+# The values below this comment are global to entire message
+
+message.from_email = From('help@twilio.com', 'Twilio SendGrid')
+
+message.reply_to = ReplyTo('help_reply@twilio.com', 'Twilio SendGrid Reply')
+
+message.subject = Subject('Sending with SendGrid is Fun 2')
+
+message.content = Content(MimeType.text, 'and easy to do anywhere, even with Python')
+message.content = Content(MimeType.html, 'and easy to do anywhere, even with Python')
+message.content = [
+ Content('text/calendar', 'Party Time!!'),
+ Content('text/custom', 'Party Time 2!!')
+]
+
+message.attachment = Attachment(FileContent('base64 encoded content 1'),
+ FileType('application/pdf'),
+ FileName('balance_001.pdf'),
+ Disposition('attachment'),
+ ContentId('Content ID 1'))
+message.attachment = [
+ Attachment(FileContent('base64 encoded content 2'),
+ FileType('image/png'),
+ FileName('banner.png'),
+ Disposition('inline'),
+ ContentId('Content ID 2')),
+ Attachment(FileContent('base64 encoded content 3'),
+ FileType('image/png'),
+ FileName('banner2.png'),
+ Disposition('inline'),
+ ContentId('Content ID 3'))
+]
+
+message.template_id = TemplateId('13b8f94f-bcae-4ec6-b752-70d6cb59f932')
+
+message.section = Section('%section1%', 'Substitution for Section 1 Tag')
+message.section = [
+ Section('%section2%', 'Substitution for Section 2 Tag'),
+ Section('%section3%', 'Substitution for Section 3 Tag')
+]
+
+message.header = Header('X-Test9', 'Test9')
+message.header = Header('X-Test10', 'Test10')
+message.header = [
+ Header('X-Test11', 'Test11'),
+ Header('X-Test12', 'Test12')
+]
+
+message.category = Category('Category 1')
+message.category = Category('Category 2')
+message.category = [
+ Category('Category 1'),
+ Category('Category 2')
+]
+
+message.custom_arg = CustomArg('marketing5', 'false')
+message.custom_arg = CustomArg('transactional5', 'true')
+message.custom_arg = [
+ CustomArg('marketing6', 'true'),
+ CustomArg('transactional6', 'false')
+]
+
+message.send_at = SendAt(1461775053)
+
+message.batch_id = BatchId("HkJ5yLYULb7Rj8GKSx7u025ouWVlMgAi")
+
+message.asm = Asm(GroupId(1), GroupsToDisplay([1,2,3,4]))
+
+message.ip_pool_name = IpPoolName("IP Pool Name")
+
+mail_settings = MailSettings()
+mail_settings.bcc_settings = BccSettings(False, BccSettingsEmail("bcc@twilio.com"))
+mail_settings.bypass_list_management = BypassListManagement(False)
+mail_settings.footer_settings = FooterSettings(True, FooterText("w00t"), FooterHtml("w00t!"))
+mail_settings.sandbox_mode = SandBoxMode(True)
+mail_settings.spam_check = SpamCheck(True, SpamThreshold(5), SpamUrl("https://example.com"))
+message.mail_settings = mail_settings
+
+tracking_settings = TrackingSettings()
+tracking_settings.click_tracking = ClickTracking(True, False)
+tracking_settings.open_tracking = OpenTracking(True, OpenTrackingSubstitutionTag("open_tracking"))
+tracking_settings.subscription_tracking = SubscriptionTracking(
+ True,
+ SubscriptionText("Goodbye"),
+ SubscriptionHtml("Goodbye!"),
+ SubscriptionSubstitutionTag("unsubscribe"))
+tracking_settings.ganalytics = Ganalytics(
+ True,
+ UtmSource("utm_source"),
+ UtmMedium("utm_medium"),
+ UtmTerm("utm_term"),
+ UtmContent("utm_content"),
+ UtmCampaign("utm_campaign"))
+message.tracking_settings = tracking_settings
+
+try:
+ sendgrid_client = SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
+ print(json.dumps(message.get(), sort_keys=True, indent=4))
+ response = sendgrid_client.send(message=message)
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+except SendGridException as e:
+ print(e.message)
+
+## Send a Single Email to a Single Recipient with a Dynamic Template
+import os
+import json
+from sendgrid import SendGridAPIClient
+from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, SendGridException, DynamicTemplateData
+
+message = Mail(from_email=From('help@twilio.com', 'Twilio SendGrid'),
+ to_emails=To('ethomas@twilio.com', 'Elmer Thomas'),
+ subject=Subject('Sending with SendGrid is Fun'),
+ plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'),
+ html_content=HtmlContent('and easy to do anywhere, even with Python'))
+message.dynamic_template_data = DynamicTemplateData({
+ "total":"$ 239.85",
+ "items":[
+ {
+ "text":"New Line Sneakers",
+ "image":"https://marketing-image-production.s3.amazonaws.com/uploads/8dda1131320a6d978b515cc04ed479df259a458d5d45d58b6b381cae0bf9588113e80ef912f69e8c4cc1ef1a0297e8eefdb7b270064cc046b79a44e21b811802.png",
+ "price":"$ 79.95"
+ },
+ {
+ "text":"Old Line Sneakers",
+ "image":"https://marketing-image-production.s3.amazonaws.com/uploads/3629f54390ead663d4eb7c53702e492de63299d7c5f7239efdc693b09b9b28c82c924225dcd8dcb65732d5ca7b7b753c5f17e056405bbd4596e4e63a96ae5018.png",
+ "price":"$ 79.95"
+ },
+ {
+ "text":"Blue Line Sneakers",
+ "image":"https://marketing-image-production.s3.amazonaws.com/uploads/00731ed18eff0ad5da890d876c456c3124a4e44cb48196533e9b95fb2b959b7194c2dc7637b788341d1ff4f88d1dc88e23f7e3704726d313c57f350911dd2bd0.png",
+ "price":"$ 79.95"
+ }
+ ],
+ "receipt":True,
+ "name":"Sample Name",
+ "address01":"1234 Fake St.",
+ "address02":"Apt. 123",
+ "city":"Place",
+ "state":"CO",
+ "zip":"80202"
+})
+
+try:
+ print(json.dumps(message.get(), sort_keys=True, indent=4))
+ sendgrid_client = SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
+ response = sendgrid_client.send(message=message)
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+except SendGridException as e:
+ print(e.message)
diff --git a/proposals/mail-helper-refactor.md b/proposals/mail-helper-refactor.md
new file mode 100644
index 000000000..70798c262
--- /dev/null
+++ b/proposals/mail-helper-refactor.md
@@ -0,0 +1,337 @@
+# This is the original proposal for v6.0.0
+
+# Send a Single Email to a Single Recipient
+
+The following code assumes you are storing the API key in an [environment variable (recommended)](../TROUBLESHOOTING.md#environment). If you don't have your key stored in an environment variable, you can assign it directly to `apikey` for testing purposes.
+
+This is the minimum code needed to send an email.
+
+```python
+import os
+from sendgrid import SendGridAPIClient
+from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, SendGridException
+
+message = Mail(from_email=From('from@example.com', 'From Name'),
+ to_emails=To('to@example.com', 'To Name'),
+ subject=Subject('Sending with SendGrid is Fun'),
+ plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'),
+ html_content=HtmlContent('and easy to do anywhere, even with Python'))
+
+try:
+ sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_apikey'))
+ response = sendgrid_client.send(message=message)
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+except SendGridException as e:
+ print(e.read())
+```
+
+# Send a Single Email to Multiple Recipients
+
+The following code assumes you are storing the API key in an [environment variable (recommended)](../TROUBLESHOOTING.md#environment). If you don't have your key stored in an environment variable, you can assign it directly to `apikey` for testing purposes.
+
+```python
+import os
+import sendgrid
+from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent
+
+to_emails = [
+ To('to0@example.com', 'To Name 0'),
+ To('to1@example.com', 'To Name 1')
+]
+msg = Mail(from_email=From('from@example.com', 'From Name'),
+ to_emails=to_emails,
+ subject=Subject('Sending with Twilio SendGrid is Fun'),
+ plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'),
+ html_content=HtmlContent('and easy to do anywhere, even with Python'))
+
+try:
+ response = sendgrid.send(msg, os.environ.get('SENDGRID_apikey'))
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+except Exception as e:
+ print(e.read())
+```
+
+# Send Multiple Emails to Multiple Recipients
+
+The following code assumes you are storing the API key in an [environment variable (recommended)](../TROUBLESHOOTING.md#environment). If you don't have your key stored in an environment variable, you can assign it directly to `apikey` for testing purposes.
+
+```python
+import os
+import sendgrid
+from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent
+
+to_emails = [
+ To(email='to0@example.com',
+ name='To Name 0',
+ substitutions={
+ '-name-': 'To Name 0',
+ '-github-': 'http://github.com/mbernier',
+ },
+ subject=Subject('Override Global Subject')),
+ To(email='to1@example.com',
+ name='To Name 1',
+ substitutions={
+ '-name-': 'To Name 1',
+ '-github-': 'http://github.com/thinkingserious',
+ })
+]
+global_substitutions = {
+ '-time-': strftime("%Y-%m-%d %H:%M:%S", gmtime())
+}
+msg = Mail(from_email=From('from@example.com', 'From Name'),
+ to_emails=to_emails,
+ subject=Subject('Hi -name-'),
+ plain_text_content=PlainTextContent('Hello -name-, your github is -github-, email sent at -time-'),
+ html_content=HtmlContent('Hello -name-, your github is here email sent at -time-'),
+ global_substitutions=global_substitutions)
+
+try:
+ response = sendgrid.send(msg, os.environ.get('SENDGRID_apikey'))
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+except Exception as e:
+ print(e.read())
+```
+
+# Kitchen Sink - an example with all settings used
+
+The following code assumes you are storing the API key in an [environment variable (recommended)](../TROUBLESHOOTING.md#environment). If you don't have your key stored in an environment variable, you can assign it directly to `apikey` for testing purposes.
+
+```python
+import os
+import sendgrid
+from sendgrid.helpers.mail import *
+
+msg = Mail(from_email=From('from@example.com', 'From Name'),
+ to_email=To('to@example.com', 'To Name'),
+ subject=Subject('Sending with Twilio SendGrid is Fun'),
+ plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'),
+ html_content=HtmlContent('and easy to do anywhere, even with Python'))
+
+# For a detailed description of each of these settings, please see the [documentation](https://sendgrid.com/docs/API_Reference/api_v3.html).
+
+msg.to = To('test1@example.com', 'Example User1')
+msg.to = [
+ To('test2@example.com', 'Example User2'),
+ To('test3@example.com', 'Example User3')
+]
+
+msg.cc = Cc('test4@example.com', 'Example User4')
+msg.cc = [
+ Cc('test5@example.com', 'Example User5'),
+ Cc('test6@example.com', 'Example User6')
+]
+
+msg.bcc = Bcc('test7@example.com', 'Example User7')
+msg.bcc = [
+ Bcc('test8@example.com', 'Example User8'),
+ Bcc('test9@example.com', 'Example User9')
+]
+
+msg.header = Header('X-Test1', 'Test1')
+msg.header = Header('X-Test2', 'Test2')
+msg.header = [
+ Header('X-Test3', 'Test3'),
+ Header('X-Test4', 'Test4')
+]
+
+msg.custom_arg = CustomArg('marketing1', 'false')
+msg.custom_arg = CustomArg('transactional1', 'true')
+msg.custom_arg = [
+ CustomArg('marketing2', 'true'),
+ CustomArg('transactional2', 'false')
+]
+
+msg.send_at = SendAt(1461775051)
+
+# If you need to add more [Personalizations](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html), here is an example of adding another Personalization by passing in a personalization index.
+
+msg.to = To('test10@example.com', 'Example User10', p=1)
+msg.to = [
+ To('test11@example.com', 'Example User11', p=1),
+ To('test12@example.com', 'Example User12', p=1)
+]
+
+msg.cc = Cc('test13@example.com', 'Example User13', p=1)
+msg.cc = [
+ Cc('test14@example.com', 'Example User14', p=1),
+ Cc('test15@example.com', 'Example User15', p=1)
+]
+
+msg.bcc = Bcc('test16@example.com', 'Example User16', p=1)
+msg.bcc = [
+ Bcc('test17@example.com', 'Example User17', p=1),
+ Bcc('test18@example.com', 'Example User18', p=1)
+]
+
+msg.header = Header('X-Test5', 'Test5', p=1)
+msg.header = Header('X-Test6', 'Test6', p=1)
+msg.headers = [
+ Header('X-Test7', 'Test7', p=1),
+ Header('X-Test8', 'Test8', p=1)
+]
+
+msg.substitution = Substitution('%name3%', 'Example Name 3', p=1)
+msg.substitution = Substitution('%city3%', 'Redwood City', p=1)
+msg.substitution = [
+ Substitution('%name4%', 'Example Name 4', p=1),
+ Substitution('%city4%', 'London', p=1)
+]
+
+msg.custom_arg = CustomArg('marketing3', 'true', p=1)
+msg.custom_arg = CustomArg('transactional3', 'false', p=1)
+msg.custom_arg = [
+ CustomArg('marketing4', 'false', p=1),
+ CustomArg('transactional4', 'true', p=1)
+]
+
+msg.send_at = SendAt(1461775052, p=1)
+
+# The values below this comment are global to the entire message
+
+msg.global_subject = Subject('Sending with Twilio SendGrid is Fun')
+
+msg.content = Content(MimeType.Text, 'and easy to do anywhere, even with Python')
+msg.content = Content(MimeType.Html, 'and easy to do anywhere, even with Python')
+msg.content = [
+ Content('text/calendar', 'Party Time!!'),
+ Content('text/custom', 'Party Time 2!!')
+]
+
+msg.attachment = Attachment(FileName('balance_001.pdf'),
+ File('base64 encoded content'),
+ Type('application/pdf'),
+ Disposition('attachment'),
+ Name('Balance Sheet'))
+msg.attachment = [
+ Attachment(FileName('banner.png'),
+ File('base64 encoded content'),
+ Type('image/png'),
+ Disposition('inline'),
+ Name('Banner')),
+ Attachment(FileName('banner2.png'),
+ File('base64 encoded content'),
+ Type('image/png'),
+ Disposition('inline'),
+ Name('Banner 2'))
+]
+
+msg.template_id = TemplateId('13b8f94f-bcae-4ec6-b752-70d6cb59f932')
+
+msg.global_header = Header('X-Day', 'Monday')
+msg.global_headers = [
+ Header('X-Month', 'January'),
+ Header('X-Year', '2017')
+]
+
+msg.section = Section('%section1%', 'Substitution for Section 1 Tag')
+msg.section = [
+ Section('%section2%', 'Substitution for Section 2 Tag'),
+ Section('%section3%', 'Substitution for Section 3 Tag')
+]
+
+try:
+ response = sendgrid.send(msg, os.environ.get('SENDGRID_apikey'))
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+except Exception as e:
+ print(e.read())
+```
+
+# Attachments
+
+The following code assumes you are storing the API key in an [environment variable (recommended)](../TROUBLESHOOTING.md#environment). If you don't have your key stored in an environment variable, you can assign it directly to `apikey` for testing purposes.
+
+```python
+import os
+import sendgrid
+from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, Attachment
+
+msg = Mail(from_email=From('from@example.com', 'From Name'),
+ to_emails=To('to@example.com', 'To Name'),
+ subject=Subject('Sending with Twilio SendGrid is Fun'),
+ plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'),
+ html_content=HtmlContent('and easy to do anywhere, even with Python'))
+msg.attachment = Attachment(FileName('balance_001.pdf'),
+ File('base64 encoded content'),
+ Type('application/pdf'),
+ Disposition('attachment'),
+ Name('Balance Sheet'))
+
+try:
+ response = sendgrid.send(msg, os.environ.get('SENDGRID_apikey'))
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+except Exception as e:
+ print(e.read())
+```
+
+# Transactional Templates
+
+The following code assumes you are storing the API key in an [environment variable (recommended)](../TROUBLESHOOTING.md#environment). If you don't have your key stored in an environment variable, you can assign it directly to `apikey` for testing purposes.
+
+For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing.
+
+Template ID (replace with your own):
+
+```text
+13b8f94f-bcae-4ec6-b752-70d6cb59f932
+```
+
+Email Subject:
+
+```text
+<%subject%>
+```
+
+Template Body:
+
+```html
+
+
+
+
+
+Hello -name-,
+
+I'm glad you are trying out the template feature!
+
+<%body%>
+
+I hope you are having a great day in -city- :)
+
+
+
+```
+
+```python
+import os
+import sendgrid
+from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, Attachment
+
+msg = Mail(from_email=From('from@example.com', 'From Name'),
+ to_emails=To('to@example.com', 'To Name'),
+ subject=Subject('Sending with Twilio SendGrid is Fun'),
+ plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'),
+ html_content=HtmlContent('and easy to do anywhere, even with Python'))
+msg.substitution = [
+ Substitution('-name-', 'Example User'),
+ Substitution('-city-', 'Denver')
+]
+msg.template_id = TemplateId('13b8f94f-bcae-4ec6-b752-70d6cb59f932')
+
+try:
+ response = sendgrid.send(msg, os.environ.get('SENDGRID_apikey'))
+ print(response.status_code)
+ print(response.body)
+ print(response.headers)
+except Exception as e:
+ print(e.read())
+```
diff --git a/register.py b/register.py
deleted file mode 100644
index 23feaf5a8..000000000
--- a/register.py
+++ /dev/null
@@ -1,7 +0,0 @@
-import pypandoc
-import os
-
-output = pypandoc.convert('README.md', 'rst')
-f = open('README.txt','w+')
-f.write(output)
-f.close()
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 34d770b5b..ed2594a90 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,6 @@
-Flask==0.10.1
-PyYAML==3.11
-python-http-client==2.2.1
-six==1.10.0
+Flask==3.1.0
+PyYAML>=4.2b1
+python-http-client>=3.2.1
+six==1.17.0
+cryptography>=45.0.6
+more-itertools==5.0.0
diff --git a/sendgrid/__init__.py b/sendgrid/__init__.py
index 8ae134780..cd994dd2f 100644
--- a/sendgrid/__init__.py
+++ b/sendgrid/__init__.py
@@ -1,4 +1,24 @@
-from .version import __version__ # noqa
-# v3 API
+"""
+This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via
+Python.
+
+For more information on this library, see the README on GitHub.
+ http://github.com/sendgrid/sendgrid-python
+For more information on the Twilio SendGrid v3 API, see the v3 docs:
+ http://sendgrid.com/docs/API_Reference/api_v3.html
+For the user guide, code examples, and more, visit the main docs page:
+ http://sendgrid.com/docs/index.html
+
+Available subpackages
+---------------------
+helpers
+ Modules to help with common tasks.
+"""
+
+from .helpers.endpoints import * # noqa
+from .helpers.mail import * # noqa
+from .helpers.stats import * # noqa
+from .helpers.eventwebhook import * # noqa
from .sendgrid import SendGridAPIClient # noqa
-from .helpers.mail.mail import Email # noqa
+from .twilio_email import TwilioEmailAPIClient # noqa
+from .version import __version__
diff --git a/sendgrid/base_interface.py b/sendgrid/base_interface.py
new file mode 100644
index 000000000..f94f09479
--- /dev/null
+++ b/sendgrid/base_interface.py
@@ -0,0 +1,83 @@
+import python_http_client
+
+region_host_dict = {'eu':'https://api.eu.sendgrid.com','global':'https://api.sendgrid.com'}
+
+class BaseInterface(object):
+ def __init__(self, auth, host, impersonate_subuser):
+ """
+ Construct the Twilio SendGrid v3 API object.
+ Note that the underlying client is being set up during initialization,
+ therefore changing attributes in runtime will not affect HTTP client
+ behaviour.
+
+ :param auth: the authorization header
+ :type auth: string
+ :param impersonate_subuser: the subuser to impersonate. Will be passed
+ by "On-Behalf-Of" header by underlying
+ client. See
+ https://sendgrid.com/docs/User_Guide/Settings/subusers.html
+ for more details
+ :type impersonate_subuser: string
+ :param host: base URL for API calls
+ :type host: string
+ """
+ from . import __version__
+ self.auth = auth
+ self.impersonate_subuser = impersonate_subuser
+ self.version = __version__
+ self.useragent = 'sendgrid/{};python'.format(self.version)
+ self.host = host
+
+ self.client = python_http_client.Client(
+ host=self.host,
+ request_headers=self._default_headers,
+ version=3)
+
+ @property
+ def _default_headers(self):
+ """Set the default header for a Twilio SendGrid v3 API call"""
+ headers = {
+ "Authorization": self.auth,
+ "User-Agent": self.useragent,
+ "Accept": 'application/json'
+ }
+ if self.impersonate_subuser:
+ headers['On-Behalf-Of'] = self.impersonate_subuser
+
+ return headers
+
+ def reset_request_headers(self):
+ self.client.request_headers = self._default_headers
+
+ def send(self, message):
+ """Make a Twilio SendGrid v3 API request with the request body generated by
+ the Mail object
+
+ :param message: The Twilio SendGrid v3 API request body generated by the Mail
+ object
+ :type message: Mail
+ """
+ if not isinstance(message, dict):
+ message = message.get()
+
+ return self.client.mail.send.post(request_body=message)
+
+ def set_sendgrid_data_residency(self, region):
+ """
+ Client libraries contain setters for specifying region/edge.
+ This supports global and eu regions only. This set will likely expand in the future.
+ Global is the default residency (or region)
+ Global region means the message will be sent through https://api.sendgrid.com
+ EU region means the message will be sent through https://api.eu.sendgrid.com
+ :param region: string
+ :return:
+ """
+ if region in region_host_dict.keys():
+ self.host = region_host_dict[region]
+ if self._default_headers is not None:
+ self.client = python_http_client.Client(
+ host=self.host,
+ request_headers=self._default_headers,
+ version=3)
+ else:
+ raise ValueError("region can only be \"eu\" or \"global\"")
diff --git a/sendgrid/helpers/__init__.py b/sendgrid/helpers/__init__.py
index e69de29bb..fb29c5e2e 100644
--- a/sendgrid/helpers/__init__.py
+++ b/sendgrid/helpers/__init__.py
@@ -0,0 +1 @@
+"""Modules to help with SendGrid v3 API common tasks."""
diff --git a/sendgrid/helpers/endpoints/__init__.py b/sendgrid/helpers/endpoints/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/sendgrid/helpers/endpoints/ip/__init__.py b/sendgrid/helpers/endpoints/ip/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/sendgrid/helpers/endpoints/ip/unassigned.py b/sendgrid/helpers/endpoints/ip/unassigned.py
new file mode 100644
index 000000000..816050d3d
--- /dev/null
+++ b/sendgrid/helpers/endpoints/ip/unassigned.py
@@ -0,0 +1,59 @@
+import json
+
+
+def format_ret(return_set, as_json=False):
+ """ decouple, allow for modifications to return type
+ returns a list of ip addresses in object or json form """
+ ret_list = list()
+ for item in return_set:
+ d = {"ip": item}
+ ret_list.append(d)
+
+ if as_json:
+ return json.dumps(ret_list)
+
+ return ret_list
+
+
+def unassigned(data, as_json=False):
+ """ https://sendgrid.com/docs/API_Reference/api_v3.html#ip-addresses
+ The /ips rest endpoint returns information about the IP addresses
+ and the usernames assigned to an IP
+
+ unassigned returns a listing of the IP addresses that are allocated
+ but have 0 users assigned
+
+
+ data (response.body from sg.client.ips.get())
+ as_json False -> get list of dicts
+ True -> get json object
+
+ example:
+ sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
+
+ params = {
+ 'subuser': 'test_string',
+ 'ip': 'test_string',
+ 'limit': 1,
+ 'exclude_whitelabels':
+ 'true', 'offset': 1
+ }
+ response = sg.client.ips.get(query_params=params)
+ if response.status_code == 201:
+ data = response.body
+ unused = unassigned(data)
+ """
+
+ no_subusers = set()
+
+ if not isinstance(data, list):
+ return format_ret(no_subusers, as_json=as_json)
+
+ for current in data:
+ num_subusers = len(current["subusers"])
+ if num_subusers == 0:
+ current_ip = current["ip"]
+ no_subusers.add(current_ip)
+
+ ret_val = format_ret(no_subusers, as_json=as_json)
+ return ret_val
diff --git a/sendgrid/helpers/eventwebhook/__init__.py b/sendgrid/helpers/eventwebhook/__init__.py
new file mode 100644
index 000000000..9d618bf3a
--- /dev/null
+++ b/sendgrid/helpers/eventwebhook/__init__.py
@@ -0,0 +1,56 @@
+from cryptography.exceptions import InvalidSignature
+from cryptography.hazmat.primitives import hashes
+from cryptography.hazmat.primitives.asymmetric import ec
+from cryptography.hazmat.primitives.serialization import load_pem_public_key
+import base64
+from .eventwebhook_header import EventWebhookHeader
+
+class EventWebhook:
+ """
+ This class allows you to use the Event Webhook feature. Read the docs for
+ more details: https://sendgrid.com/docs/for-developers/tracking-events/event
+ """
+
+ def __init__(self, public_key=None):
+ """
+ Construct the Event Webhook verifier object
+ :param public_key: verification key under Mail Settings
+ :type public_key: string
+ """
+ self.public_key = self.convert_public_key_to_ecdsa(public_key) if public_key else public_key
+
+ def convert_public_key_to_ecdsa(self, public_key):
+ """
+ Convert the public key string to an EllipticCurvePublicKey object.
+
+ :param public_key: verification key under Mail Settings
+ :type public_key string
+ :return: An EllipticCurvePublicKey object using the ECDSA algorithm
+ :rtype cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey
+ """
+ pem_key = "-----BEGIN PUBLIC KEY-----\n" + public_key + "\n-----END PUBLIC KEY-----"
+ return load_pem_public_key(pem_key.encode("utf-8"))
+
+ def verify_signature(self, payload, signature, timestamp, public_key=None):
+ """
+ Verify signed event webhook requests.
+
+ :param payload: event payload in the request body
+ :type payload: string
+ :param signature: value obtained from the 'X-Twilio-Email-Event-Webhook-Signature' header
+ :type signature: string
+ :param timestamp: value obtained from the 'X-Twilio-Email-Event-Webhook-Timestamp' header
+ :type timestamp: string
+ :param public_key: elliptic curve public key
+ :type public_key: cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey
+ :return: true or false if signature is valid
+ """
+ timestamped_payload = (timestamp + payload).encode('utf-8')
+ decoded_signature = base64.b64decode(signature)
+
+ key = public_key or self.public_key
+ try:
+ key.verify(decoded_signature, timestamped_payload, ec.ECDSA(hashes.SHA256()))
+ return True
+ except InvalidSignature:
+ return False
diff --git a/sendgrid/helpers/eventwebhook/eventwebhook_header.py b/sendgrid/helpers/eventwebhook/eventwebhook_header.py
new file mode 100644
index 000000000..a41a48524
--- /dev/null
+++ b/sendgrid/helpers/eventwebhook/eventwebhook_header.py
@@ -0,0 +1,10 @@
+class EventWebhookHeader:
+ """
+ This class lists headers that get posted to the webhook. Read the docs for
+ more details: https://sendgrid.com/docs/for-developers/tracking-events/event
+ """
+ SIGNATURE = 'X-Twilio-Email-Event-Webhook-Signature'
+ TIMESTAMP = 'X-Twilio-Email-Event-Webhook-Timestamp'
+
+ def __init__(self):
+ pass
diff --git a/sendgrid/helpers/inbound/README.md b/sendgrid/helpers/inbound/README.md
index bc69d1189..79e5b4544 100644
--- a/sendgrid/helpers/inbound/README.md
+++ b/sendgrid/helpers/inbound/README.md
@@ -1,13 +1,17 @@
-**This helper is a stand alone module to help get you started consuming and processing Inbound Parse data.**
+**This helper is a stand-alone module to help get you started consuming and processing Inbound Parse data.**
## Table of Contents
-* [Quick Start for Local Testing with Sample Data](#quick_start_local_sample)
-* [Quick Start for Local Testing with Real Data](#quick_start_local_real)
-* [Deploy to Heroku](#heroku)
-* [Code Walkthrough](#code_walkthrough)
-* [Testing the Source Code](#testing)
-* [Contributing](#contributing)
+- [Quick Start for Local Testing with Sample Data](#quick-start-for-local-testing-with-sample-data)
+- [Quick Start for Local Testing with Real Data](#quick-start-for-local-testing-with-real-data)
+- [Deploy to Heroku](#deploy-to-heroku)
+- [Code Walkthrough](#code-walkthrough)
+ - [app.py](#apppy)
+ - [config.py & config.yml](#configpy--configyml)
+ - [parse.py](#parsepy)
+ - [send.py & /sample_data](#sendpy--sampledata)
+- [Testing the Source Code](#testing-the-source-code)
+- [Contributing](#contributing)
# Quick Start for Local Testing with Sample Data
@@ -32,7 +36,7 @@ pip install -r requirements.txt
python sendgrid/helpers/inbound/send.py ./sendgrid/helpers/inbound/sample_data/default_data.txt
```
-More sample data can be found [here](https://github.com/sendgrid/sendgrid-python/tree/master/sendgrid/helpers/inbound/sample_data).
+More sample data can be found [here](sample_data).
View the results in the first terminal.
@@ -67,7 +71,7 @@ Next, send an email to [anything]@inbound.yourdomain.com, then look at the termi
Get a [Heroku](https://www.heroku.com) account.
-[](https://heroku.com/deploy?template=https://github.com/sendgrid/sendgrid-python/tree/master)
+[](https://heroku.com/deploy?template=https://github.com/sendgrid/sendgrid-python/tree/main)
[Setup your MX records.](https://sendgrid.com/docs/Classroom/Basics/Inbound_Parse_Webhook/setting_up_the_inbound_parse_webhook.html#-Setup) Depending on your domain name host, you may need to wait up to 48 hours for the settings to propagate.
@@ -96,7 +100,7 @@ heroku git:remote -a [name-of-your-app]
---make changes---
git add .
git commit -m "update configuration"
-git push heroku master
+git push heroku main
```
@@ -123,12 +127,12 @@ This module is used to send sample test data. It is useful for testing and devel
Tests are located in the root of this project in the /test folder:
-- [test_config.py](https://github.com/sendgrid/sendgrid-python/blob/master/test/test_config.py)
-- [test_parse.py](https://github.com/sendgrid/sendgrid-python/blob/master/test/test_parse.py)
+- [test_config.py](../../../test/test_config.py)
+- [test_parse.py](../../../test/test_parse.py)
-Learn about testing this code [here](https://github.com/sendgrid/sendgrid-python/blob/master/CONTRIBUTING.md#testing).
+Learn about testing this code [here](../../../CONTRIBUTING.md#testing).
# Contributing
-If you would like to contribute to this project, please see our [contributing guide](https://github.com/sendgrid/sendgrid-python/blob/master/CONTRIBUTING.md). Thanks!
+If you would like to contribute to this project, please see our [contributing guide](../../../CONTRIBUTING.md). Thanks!
diff --git a/sendgrid/helpers/inbound/__init__.py b/sendgrid/helpers/inbound/__init__.py
index 160689d5b..85ab4d0b5 100644
--- a/sendgrid/helpers/inbound/__init__.py
+++ b/sendgrid/helpers/inbound/__init__.py
@@ -1,2 +1,13 @@
+"""
+Inbound Parse helper
+--------------------
+This is a standalone module to help get you started consuming and processing
+Inbound Parse data. It provides a Flask server to listen for Inbound Parse
+POSTS, and utilities to send sample data to the server.
+
+See README.txt for detailed usage instructions, including quick-start guides
+for local testing and Heroku deployment.
+"""
+
from .config import * # noqa
from .parse import * # noqa
diff --git a/sendgrid/helpers/inbound/app.py b/sendgrid/helpers/inbound/app.py
index 5129427c4..0d4435907 100755
--- a/sendgrid/helpers/inbound/app.py
+++ b/sendgrid/helpers/inbound/app.py
@@ -1,4 +1,6 @@
-"""Receiver module for processing SendGrid Inbound Parse messages"""
+"""Receiver module for processing SendGrid Inbound Parse messages.
+
+See README.txt for usage instructions."""
try:
from config import Config
except:
@@ -20,13 +22,15 @@
@app.route('/', methods=['GET'])
def index():
+ """Show index page to confirm that server is running."""
return render_template('index.html')
@app.route(config.endpoint, methods=['POST'])
def inbound_parse():
+ """Process POST from Inbound Parse and print received data."""
parse = Parse(config, request)
- # Sample proccessing action
+ # Sample processing action
print(parse.key_values())
# Tell SendGrid's Inbound Parse to stop sending POSTs
# Everything is 200 OK :)
diff --git a/sendgrid/helpers/inbound/config.py b/sendgrid/helpers/inbound/config.py
index 1bd076b76..06ca683cb 100644
--- a/sendgrid/helpers/inbound/config.py
+++ b/sendgrid/helpers/inbound/config.py
@@ -1,10 +1,11 @@
-"""Setup credentials (.env) and application variables (config.yml)"""
+"""Set up credentials (.env) and application variables (config.yml)"""
import os
import yaml
class Config(object):
"""All configuration for this app is loaded here"""
+
def __init__(self, **opts):
if os.environ.get('ENV') != 'prod': # We are not in Heroku
self.init_environment()
@@ -14,8 +15,8 @@ def __init__(self, **opts):
self.path = opts.get(
'path', os.path.abspath(os.path.dirname(__file__))
)
- with open(self.path + '/config.yml') as stream:
- config = yaml.load(stream)
+ with open('{0}/config.yml'.format(self.path)) as stream:
+ config = yaml.load(stream, Loader=yaml.FullLoader)
self._debug_mode = config['debug_mode']
self._endpoint = config['endpoint']
self._host = config['host']
@@ -27,28 +28,38 @@ def init_environment():
"""Allow variables assigned in .env available using
os.environ.get('VAR_NAME')"""
base_path = os.path.abspath(os.path.dirname(__file__))
- if os.path.exists(base_path + '/.env'):
- for line in open(base_path + '/.env'):
- var = line.strip().split('=')
- if len(var) == 2:
- os.environ[var[0]] = var[1]
+ env_path = '{0}/.env'.format(base_path)
+ if os.path.exists(env_path):
+ with open(env_path) as f:
+ lines = f.readlines()
+ for line in lines:
+ var = line.strip().split('=')
+ if len(var) == 2:
+ os.environ[var[0]] = var[1]
@property
def debug_mode(self):
+ """Flask debug mode - set to False in production."""
return self._debug_mode
@property
def endpoint(self):
+ """Endpoint to receive Inbound Parse POSTs."""
return self._endpoint
@property
def host(self):
+ """URL that the sender will POST to."""
return self._host
@property
def keys(self):
+ """Incoming Parse fields to parse. For reference, see
+ https://sendgrid.com/docs/Classroom/Basics/Inbound_Parse_Webhook/setting_up_the_inbound_parse_webhook.html
+ """
return self._keys
@property
def port(self):
+ """Port to listen on."""
return self._port
diff --git a/sendgrid/helpers/inbound/parse.py b/sendgrid/helpers/inbound/parse.py
index 77b6683ad..49627a121 100644
--- a/sendgrid/helpers/inbound/parse.py
+++ b/sendgrid/helpers/inbound/parse.py
@@ -7,6 +7,7 @@
class Parse(object):
+
def __init__(self, config, request):
self._keys = config.keys
self._request = request
diff --git a/sendgrid/helpers/inbound/sample_data/default_data.txt b/sendgrid/helpers/inbound/sample_data/default_data.txt
index cdf52d68b..7c3ce6be2 100644
--- a/sendgrid/helpers/inbound/sample_data/default_data.txt
+++ b/sendgrid/helpers/inbound/sample_data/default_data.txt
@@ -20,7 +20,7 @@ inbound@inbound.example.com
--xYzZY
Content-Disposition: form-data; name="html"
-Hello SendGrid!
+Hello Twilio SendGrid!
--xYzZY
Content-Disposition: form-data; name="from"
@@ -29,7 +29,7 @@ Example User
--xYzZY
Content-Disposition: form-data; name="text"
-Hello SendGrid!
+Hello Twilio SendGrid!
--xYzZY
Content-Disposition: form-data; name="sender_ip"
diff --git a/sendgrid/helpers/inbound/sample_data/raw_data.txt b/sendgrid/helpers/inbound/sample_data/raw_data.txt
index eff28c385..12f64cb4a 100644
--- a/sendgrid/helpers/inbound/sample_data/raw_data.txt
+++ b/sendgrid/helpers/inbound/sample_data/raw_data.txt
@@ -16,13 +16,13 @@ Content-Type: multipart/alternative; boundary=001a113ee97c89842f0539be8e7a
--001a113ee97c89842f0539be8e7a
Content-Type: text/plain; charset=UTF-8
-Hello SendGrid!
+Hello Twilio SendGrid!
--001a113ee97c89842f0539be8e7a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
-Hello SendGrid!
+Hello Twilio SendGrid!
--001a113ee97c89842f0539be8e7a--
diff --git a/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt b/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt
index f8cd93fc2..058fd8a64 100644
--- a/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt
+++ b/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt
@@ -19,13 +19,13 @@ Content-Type: multipart/alternative; boundary=001a1140ffb6f4fc5f053a2257e0
--001a1140ffb6f4fc5f053a2257e0
Content-Type: text/plain; charset=UTF-8
-Hello SendGrid!
+Hello Twilio SendGrid!
--001a1140ffb6f4fc5f053a2257e0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
-Hello SendGrid!
+Hello Twilio SendGrid!
--001a1140ffb6f4fc5f053a2257e0--
diff --git a/sendgrid/helpers/inbound/send.py b/sendgrid/helpers/inbound/send.py
index cc3d95612..8dbfa68d2 100644
--- a/sendgrid/helpers/inbound/send.py
+++ b/sendgrid/helpers/inbound/send.py
@@ -1,7 +1,8 @@
-"""A module for sending test SendGrid Inbound Parse messages
+"""A module for sending test SendGrid Inbound Parse messages.
Usage: ./send.py [path to file containing test data]"""
import argparse
import sys
+from io import open
try:
from config import Config
except ImportError:
@@ -11,35 +12,50 @@
class Send(object):
+
def __init__(self, url):
+ """Create a Send object with target `url`."""
self._url = url
def test_payload(self, payload_filepath):
+ """Send a test payload.
+
+ Load a payload from payload_filepath, apply headers, and POST self.url.
+ Return the response object.
+ """
headers = {
"User-Agent": "SendGrid-Test",
"Content-Type": "multipart/form-data; boundary=xYzZY"
}
client = Client(host=self.url, request_headers=headers)
- f = open(payload_filepath, 'r')
+ f = open(payload_filepath, 'r', encoding='utf-8')
data = f.read()
return client.post(request_body=data)
@property
def url(self):
+ """URL to send to."""
return self._url
-config = Config()
-parser = argparse.ArgumentParser(description='Test data and optional host.')
-parser.add_argument('data',
- type=str,
- help='path to the sample data')
-parser.add_argument('-host',
- type=str,
- help='name of host to send the sample data to',
- default=config.host, required=False)
-args = parser.parse_args()
-send = Send(args.host)
-response = send.test_payload(sys.argv[1])
-print(response.status_code)
-print(response.headers)
-print(response.body)
+
+def main():
+ config = Config()
+ parser = argparse.ArgumentParser(
+ description='Test data and optional host.')
+ parser.add_argument('data',
+ type=str,
+ help='path to the sample data')
+ parser.add_argument('-host',
+ type=str,
+ help='name of host to send the sample data to',
+ default=config.host, required=False)
+ args = parser.parse_args()
+ send = Send(args.host)
+ response = send.test_payload(sys.argv[1])
+ print(response.status_code)
+ print(response.headers)
+ print(response.body)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/sendgrid/helpers/inbound/templates/index.html b/sendgrid/helpers/inbound/templates/index.html
index b0f0954db..7cbede381 100644
--- a/sendgrid/helpers/inbound/templates/index.html
+++ b/sendgrid/helpers/inbound/templates/index.html
@@ -3,8 +3,8 @@
SendGrid Incoming Parse
- You have successfuly launched the server!
+ You have successfully launched the server!
- Check out the documentation on how to use this software to utilize the SendGrid Inbound Parse webhook.
+ Check out the documentation on how to use this software to utilize the SendGrid Inbound Parse webhook.