From 1936e24d0ae79600fe52aace3b8b6780f2397edd Mon Sep 17 00:00:00 2001 From: d grossman Date: Tue, 17 Oct 2017 10:38:54 -0700 Subject: [PATCH 01/82] Get unassigned IPs #392, made helper function --- sendgrid/helpers/endpoints/__init__.py | 0 sendgrid/helpers/endpoints/ip/__init__.py | 0 .../helpers/endpoints/ip/test_unassigned.py | 80 +++++++++++++++++++ sendgrid/helpers/endpoints/ip/unassigned.py | 52 ++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 sendgrid/helpers/endpoints/__init__.py create mode 100644 sendgrid/helpers/endpoints/ip/__init__.py create mode 100644 sendgrid/helpers/endpoints/ip/test_unassigned.py create mode 100644 sendgrid/helpers/endpoints/ip/unassigned.py 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/test_unassigned.py b/sendgrid/helpers/endpoints/ip/test_unassigned.py new file mode 100644 index 000000000..cc2af3b40 --- /dev/null +++ b/sendgrid/helpers/endpoints/ip/test_unassigned.py @@ -0,0 +1,80 @@ +import json +import pytest + +from .unassigned import unassigned + + +def test_unassigned_ip(): + + ret_json = '''[ { + "ip": "167.89.21.3", + "pools": [ + "pool1", + "pool2" + ], + "whitelabeled": false, + "start_date": 1409616000, + "subusers": [ + "tim@sendgrid.net" + ], + "warmup": false, + "assigned_at": 1482883200 + }, + { + "ip": "192.168.1.1", + "pools": [ + "pool1", + "pool2" + ], + "whitelabeled": false, + "start_date": 1409616000, + "subusers": [ + "tim@sendgrid.net" + ], + "warmup": false, + "assigned_at": 1482883200 + }, + { + "ip": "208.115.214.22", + "pools": [], + "whitelabeled": true, + "rdns": "o1.email.burgermail.com", + "start_date": 1409616000, + "subusers": [], + "warmup": false, + "assigned_at": 1482883200 + }, + { + "ip": "208.115.214.23", + "pools": [], + "whitelabeled": true, + "rdns": "o1.email.burgermail.com", + "start_date": 1409616000, + "subusers": [], + "warmup": false, + "assigned_at": 1482883200 + + } ] + ''' + + def get_all_ip(): + ret_val = json.loads(ret_json) + return ret_val + + data = {"208.115.214.23", "208.115.214.22"} + + as_json = True + calculated = unassigned(get_all_ip(), as_json=as_json) + calculated = json.loads(calculated) + + for item in calculated: + assert item["ip"] in data + + as_json = False + calculated = unassigned(get_all_ip(), as_json=as_json) + + for item in calculated: + assert item["ip"] in data + + calculated = unassigned(dict(), as_json=as_json) + assert calculated == [] diff --git a/sendgrid/helpers/endpoints/ip/unassigned.py b/sendgrid/helpers/endpoints/ip/unassigned.py new file mode 100644 index 000000000..075f19857 --- /dev/null +++ b/sendgrid/helpers/endpoints/ip/unassigned.py @@ -0,0 +1,52 @@ +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 usera assigned + + + data (response.body from sg.client.ips.get()) + as_json False -> get list of dicts + True -> get json object + + example: + sg = sendgrid.SendGridAPIClient(apikey=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 = unassinged(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 From c8fc9eb87a764ee27b9a0b7a9ea40fd29c3ba1f0 Mon Sep 17 00:00:00 2001 From: d grossman Date: Tue, 17 Oct 2017 10:45:29 -0700 Subject: [PATCH 02/82] break up tests --- .../helpers/endpoints/ip/test_unassigned.py | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/sendgrid/helpers/endpoints/ip/test_unassigned.py b/sendgrid/helpers/endpoints/ip/test_unassigned.py index cc2af3b40..a639f34a9 100644 --- a/sendgrid/helpers/endpoints/ip/test_unassigned.py +++ b/sendgrid/helpers/endpoints/ip/test_unassigned.py @@ -3,15 +3,12 @@ from .unassigned import unassigned - -def test_unassigned_ip(): - - ret_json = '''[ { - "ip": "167.89.21.3", +ret_json = '''[ { + "ip": "167.89.21.3", "pools": [ - "pool1", - "pool2" - ], + "pool1", + "pool2" + ], "whitelabeled": false, "start_date": 1409616000, "subusers": [ @@ -57,9 +54,13 @@ def test_unassigned_ip(): } ] ''' - def get_all_ip(): - ret_val = json.loads(ret_json) - return ret_val +def get_all_ip(): + ret_val = json.loads(ret_json) + return ret_val + + + +def test_unassigned_ip_json(): data = {"208.115.214.23", "208.115.214.22"} @@ -70,11 +71,17 @@ def get_all_ip(): for item in calculated: assert item["ip"] in data +def test_unassigned_ip_obj(): + + data = {"208.115.214.23", "208.115.214.22"} + as_json = False calculated = unassigned(get_all_ip(), as_json=as_json) for item in calculated: assert item["ip"] in data +def test_unassigned_baddata(): + as_json = False calculated = unassigned(dict(), as_json=as_json) assert calculated == [] From df73eb0b066b73fa62963fbb2e925d587d679d18 Mon Sep 17 00:00:00 2001 From: d grossman Date: Tue, 17 Oct 2017 10:53:21 -0700 Subject: [PATCH 03/82] make the python2.6 travis build happy --- sendgrid/helpers/endpoints/ip/test_unassigned.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sendgrid/helpers/endpoints/ip/test_unassigned.py b/sendgrid/helpers/endpoints/ip/test_unassigned.py index a639f34a9..be5904018 100644 --- a/sendgrid/helpers/endpoints/ip/test_unassigned.py +++ b/sendgrid/helpers/endpoints/ip/test_unassigned.py @@ -59,10 +59,17 @@ def get_all_ip(): return ret_val +def make_data(): + data = set() + data.add("208.115.214.23") + data.add("208.115.214.22") + return data + + def test_unassigned_ip_json(): - data = {"208.115.214.23", "208.115.214.22"} + data = make_data() as_json = True calculated = unassigned(get_all_ip(), as_json=as_json) @@ -73,7 +80,7 @@ def test_unassigned_ip_json(): def test_unassigned_ip_obj(): - data = {"208.115.214.23", "208.115.214.22"} + data = make_data() as_json = False calculated = unassigned(get_all_ip(), as_json=as_json) From 9f0932f4634f5abeb24947d6078e6d49558f5a41 Mon Sep 17 00:00:00 2001 From: Aaron Mak Kang Sheng Date: Sun, 22 Oct 2017 10:11:27 +0800 Subject: [PATCH 04/82] Add global stats helper --- examples/helpers/stats/stats_example.py | 27 +++++++ sendgrid/helpers/stats/README.md | 1 + sendgrid/helpers/stats/__init__.py | 1 + sendgrid/helpers/stats/stats.py | 98 +++++++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 examples/helpers/stats/stats_example.py create mode 100644 sendgrid/helpers/stats/README.md create mode 100644 sendgrid/helpers/stats/__init__.py create mode 100644 sendgrid/helpers/stats/stats.py diff --git a/examples/helpers/stats/stats_example.py b/examples/helpers/stats/stats_example.py new file mode 100644 index 000000000..3d2846e11 --- /dev/null +++ b/examples/helpers/stats/stats_example.py @@ -0,0 +1,27 @@ +import json +import os +from sendgrid.helpers.stats import * +from sendgrid import * + +# NOTE: you will need move this file to the root directory of this project to execute properly. + + +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 get_global_stats(): + # 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(apikey=os.environ.get('SENDGRID_API_KEY')) + stats_params = build_global_stats() + response = sg.client.stats.get(query_params=stats_params) + print(response.status_code) + print(response.headers) + print(json.dumps(json.loads(response.body), indent=4, sort_keys=True)) + +get_global_stats() \ No newline at end of file diff --git a/sendgrid/helpers/stats/README.md b/sendgrid/helpers/stats/README.md new file mode 100644 index 000000000..2c062c3be --- /dev/null +++ b/sendgrid/helpers/stats/README.md @@ -0,0 +1 @@ +**This helper allows you to quickly and easily build a Stats object for sending your email stats to a database.** \ No newline at end of file diff --git a/sendgrid/helpers/stats/__init__.py b/sendgrid/helpers/stats/__init__.py new file mode 100644 index 000000000..9ee4dcdd8 --- /dev/null +++ b/sendgrid/helpers/stats/__init__.py @@ -0,0 +1 @@ +from .stats import * # noqa diff --git a/sendgrid/helpers/stats/stats.py b/sendgrid/helpers/stats/stats.py new file mode 100644 index 000000000..398fe7583 --- /dev/null +++ b/sendgrid/helpers/stats/stats.py @@ -0,0 +1,98 @@ +import json +import csv + + +class Stats(object): + def __init__( + self, start_date=None): + self._start_date = None + self._end_date = None + self._aggregated_by = None + self._sort_by_metric = None + self._sort_by_direction = None + self._limit = None + self._offset = None + + # Minimum required for stats + if start_date: + self.start_date = start_date + + def __str__(self): + return str(self.get()) + + def get(self): + """ + :return: response stats dict + """ + stats = {} + if self.start_date is not None: + stats["start_date"] = self.start_date + if self.end_date is not None: + stats["end_date"] = self.end_date + if self.aggregated_by is not None: + stats["aggregated_by"] = self.aggregated_by + if self.sort_by_metric is not None: + stats["sort_by_metric"] = self.sort_by_metric + if self.sort_by_direction is not None: + stats["sort_by_direction"] = self.sort_by_direction + if self.limit is not None: + stats["limit"] = self.limit + if self.offset is not None: + stats["offset"] = self.offset + return stats + + @property + def start_date(self): + return self._start_date + + @start_date.setter + def start_date(self, value): + self._start_date = value + + @property + def end_date(self): + return self._end_date + + @end_date.setter + def end_date(self, value): + self._end_date = value + + @property + def aggregated_by(self): + return self._aggregated_by + + @aggregated_by.setter + def aggregated_by(self, value): + self._aggregated_by = value + + @property + def sort_by_metric(self): + return self._sort_by_metric + + @sort_by_metric.setter + def sort_by_metric(self, value): + self._sort_by_metric = value + + @property + def sort_by_direction(self): + return self._sort_by_direction + + @sort_by_direction.setter + def sort_by_direction(self, value): + self._sort_by_direction = value + + @property + def limit(self): + return self._limit + + @limit.setter + def limit(self, value): + self._limit = value + + @property + def offset(self): + return self._offset + + @offset.setter + def offset(self, value): + self._offset = value From eb65f75e55c8bf5dc0d5ba076ab79f9bf01e4bd0 Mon Sep 17 00:00:00 2001 From: Aaron Mak Kang Sheng Date: Sun, 22 Oct 2017 12:52:30 +0800 Subject: [PATCH 05/82] Add child class CategoryStats --- examples/helpers/stats/stats_example.py | 44 +++++++++++++++-- sendgrid/helpers/stats/stats.py | 64 ++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 5 deletions(-) diff --git a/examples/helpers/stats/stats_example.py b/examples/helpers/stats/stats_example.py index 3d2846e11..8688440d4 100644 --- a/examples/helpers/stats/stats_example.py +++ b/examples/helpers/stats/stats_example.py @@ -5,6 +5,10 @@ # NOTE: you will need move this file to the root directory of this project to execute properly. +# 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(apikey=os.environ.get('SENDGRID_API_KEY')) + def build_global_stats(): global_stats = Stats() @@ -14,14 +18,46 @@ def build_global_stats(): return global_stats.get() +def build_category_stats(): + category_stats = CategoryStats() + 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 get_global_stats(): - # 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(apikey=os.environ.get('SENDGRID_API_KEY')) stats_params = build_global_stats() response = sg.client.stats.get(query_params=stats_params) + response_body = json.loads(response.body)[0]['date'] + print(response.status_code) + print(response.headers) + print(json.dumps(response_body, indent=4, sort_keys=True)) + + +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) + print(json.dumps(json.loads(response.body), indent=4, sort_keys=True)) + + +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) print(json.dumps(json.loads(response.body), indent=4, sort_keys=True)) -get_global_stats() \ No newline at end of file +get_global_stats() +get_category_stats() +get_category_stats_sums() diff --git a/sendgrid/helpers/stats/stats.py b/sendgrid/helpers/stats/stats.py index 398fe7583..8719a9f7d 100644 --- a/sendgrid/helpers/stats/stats.py +++ b/sendgrid/helpers/stats/stats.py @@ -1,7 +1,6 @@ import json import csv - class Stats(object): def __init__( self, start_date=None): @@ -96,3 +95,66 @@ def offset(self): @offset.setter def offset(self, value): self._offset = value + + +class CategoryStats(Stats): + def __init__(self, start_date=None, categories=None): + self._categories = None + super(CategoryStats, self).__init__() + + # Minimum required for category stats + if start_date and categories: + self.start_date = start_date + self.categories = categories + + def get(self): + """ + :return: response stats dict + """ + stats = {} + if self.start_date is not None: + stats["start_date"] = self.start_date + if self.end_date is not None: + stats["end_date"] = self.end_date + if self.aggregated_by is not None: + stats["aggregated_by"] = self.aggregated_by + if self.sort_by_metric is not None: + stats["sort_by_metric"] = self.sort_by_metric + if self.sort_by_direction is not None: + stats["sort_by_direction"] = self.sort_by_direction + if self.limit is not None: + stats["limit"] = self.limit + if self.offset is not None: + stats["offset"] = self.offset + if self.categories is not None: + stats['categories'] = [category.get() for category in + self.categories] + return stats + + @property + def categories(self): + return self._categories + + def add_category(self, category): + if self._categories is None: + self._categories = [] + self._categories.append(category) + + +class Category(object): + + def __init__(self, name=None): + self._name = None + if name is not None: + self._name = name + + @property + def name(self): + return self._name + + @name.setter + def name(self, value): + self._name = value + + def get(self): + return self.name \ No newline at end of file From a1fab6789e21932cf736d8550a474a95e26fb199 Mon Sep 17 00:00:00 2001 From: Aaron Mak Kang Sheng Date: Sun, 22 Oct 2017 12:53:10 +0800 Subject: [PATCH 06/82] fix typo --- examples/helpers/stats/stats_example.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/helpers/stats/stats_example.py b/examples/helpers/stats/stats_example.py index 8688440d4..3862b2097 100644 --- a/examples/helpers/stats/stats_example.py +++ b/examples/helpers/stats/stats_example.py @@ -37,10 +37,9 @@ def build_category_stats_sums(): def get_global_stats(): stats_params = build_global_stats() response = sg.client.stats.get(query_params=stats_params) - response_body = json.loads(response.body)[0]['date'] print(response.status_code) print(response.headers) - print(json.dumps(response_body, indent=4, sort_keys=True)) + print(json.dumps(json.loads(response.body), indent=4, sort_keys=True)) def get_category_stats(): From 67d0b634712d3b8c60f4a9c2a1e5ecf810016e07 Mon Sep 17 00:00:00 2001 From: Aaron Mak Kang Sheng Date: Sun, 22 Oct 2017 13:04:20 +0800 Subject: [PATCH 07/82] Clean up json and refine CategoryStats Class --- examples/helpers/stats/stats_example.py | 19 ++++++++++++------- sendgrid/helpers/stats/stats.py | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/helpers/stats/stats_example.py b/examples/helpers/stats/stats_example.py index 3862b2097..41f4b85ab 100644 --- a/examples/helpers/stats/stats_example.py +++ b/examples/helpers/stats/stats_example.py @@ -10,6 +10,10 @@ sg = SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +def pprint_json(json_raw): + print(json.dumps(json.loads(json_raw), indent=4, sort_keys=True)) + + def build_global_stats(): global_stats = Stats() global_stats.start_date = '2017-10-14' @@ -19,10 +23,10 @@ def build_global_stats(): def build_category_stats(): - category_stats = CategoryStats() - category_stats.start_date = '2017-10-15' - category_stats.add_category(Category("foo")) - category_stats.add_category(Category("bar")) + 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() @@ -39,15 +43,16 @@ def get_global_stats(): response = sg.client.stats.get(query_params=stats_params) print(response.status_code) print(response.headers) - print(json.dumps(json.loads(response.body), indent=4, sort_keys=True)) + pprint_json(response.body) def get_category_stats(): stats_params = build_category_stats() + print(stats_params) response = sg.client.categories.stats.get(query_params=stats_params) print(response.status_code) print(response.headers) - print(json.dumps(json.loads(response.body), indent=4, sort_keys=True)) + pprint_json(response.body) def get_category_stats_sums(): @@ -55,7 +60,7 @@ def get_category_stats_sums(): response = sg.client.categories.stats.sums.get(query_params=stats_params) print(response.status_code) print(response.headers) - print(json.dumps(json.loads(response.body), indent=4, sort_keys=True)) + pprint_json(response.body) get_global_stats() get_category_stats() diff --git a/sendgrid/helpers/stats/stats.py b/sendgrid/helpers/stats/stats.py index 8719a9f7d..b5ddebcc1 100644 --- a/sendgrid/helpers/stats/stats.py +++ b/sendgrid/helpers/stats/stats.py @@ -105,7 +105,8 @@ def __init__(self, start_date=None, categories=None): # Minimum required for category stats if start_date and categories: self.start_date = start_date - self.categories = categories + for cat in categories: + self.add_category(Category(cat)) def get(self): """ From f8183a689a0952445dec9b59bb00e8b35ec550ba Mon Sep 17 00:00:00 2001 From: Aaron Mak Kang Sheng Date: Sun, 22 Oct 2017 13:41:53 +0800 Subject: [PATCH 08/82] Add SubuserStats class --- examples/helpers/stats/stats_example.py | 42 +++++++++++++-- sendgrid/helpers/stats/stats.py | 70 +++++++++++++++++++++++-- 2 files changed, 102 insertions(+), 10 deletions(-) diff --git a/examples/helpers/stats/stats_example.py b/examples/helpers/stats/stats_example.py index 41f4b85ab..00a704c47 100644 --- a/examples/helpers/stats/stats_example.py +++ b/examples/helpers/stats/stats_example.py @@ -11,7 +11,7 @@ def pprint_json(json_raw): - print(json.dumps(json.loads(json_raw), indent=4, sort_keys=True)) + print(json.dumps(json.loads(json_raw), indent=2, sort_keys=True)) def build_global_stats(): @@ -38,6 +38,21 @@ def build_category_stats_sums(): 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) @@ -48,7 +63,6 @@ def get_global_stats(): def get_category_stats(): stats_params = build_category_stats() - print(stats_params) response = sg.client.categories.stats.get(query_params=stats_params) print(response.status_code) print(response.headers) @@ -62,6 +76,24 @@ def get_category_stats_sums(): print(response.headers) pprint_json(response.body) -get_global_stats() -get_category_stats() -get_category_stats_sums() + +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/sendgrid/helpers/stats/stats.py b/sendgrid/helpers/stats/stats.py index b5ddebcc1..550599138 100644 --- a/sendgrid/helpers/stats/stats.py +++ b/sendgrid/helpers/stats/stats.py @@ -1,6 +1,3 @@ -import json -import csv - class Stats(object): def __init__( self, start_date=None): @@ -105,8 +102,8 @@ def __init__(self, start_date=None, categories=None): # Minimum required for category stats if start_date and categories: self.start_date = start_date - for cat in categories: - self.add_category(Category(cat)) + for cat_name in categories: + self.add_category(Category(cat_name)) def get(self): """ @@ -142,8 +139,71 @@ def add_category(self, category): self._categories.append(category) +class SubuserStats(Stats): + def __init__(self, start_date=None, subusers=None): + self._subusers = None + super(SubuserStats, self).__init__() + + # Minimum required for subusers stats + if start_date and subusers: + self.start_date = start_date + for subuser_name in subusers: + self.add_subuser(Subuser(subuser_name)) + + def get(self): + """ + :return: response stats dict + """ + stats = {} + if self.start_date is not None: + stats["start_date"] = self.start_date + if self.end_date is not None: + stats["end_date"] = self.end_date + if self.aggregated_by is not None: + stats["aggregated_by"] = self.aggregated_by + if self.sort_by_metric is not None: + stats["sort_by_metric"] = self.sort_by_metric + if self.sort_by_direction is not None: + stats["sort_by_direction"] = self.sort_by_direction + if self.limit is not None: + stats["limit"] = self.limit + if self.offset is not None: + stats["offset"] = self.offset + if self.subusers is not None: + stats['subusers'] = [subuser.get() for subuser in + self.subusers] + return stats + + @property + def subusers(self): + return self._subusers + + def add_subuser(self, subuser): + if self._subusers is None: + self._subusers = [] + self._subusers.append(subuser) + + class Category(object): + def __init__(self, name=None): + self._name = None + if name is not None: + self._name = name + + @property + def name(self): + return self._name + + @name.setter + def name(self, value): + self._name = value + + def get(self): + return self.name + +class Subuser(object): + def __init__(self, name=None): self._name = None if name is not None: From 57439d976c5b3423f3797ee4c39b7006e394ba92 Mon Sep 17 00:00:00 2001 From: Aaron Mak Kang Sheng Date: Sun, 22 Oct 2017 13:54:56 +0800 Subject: [PATCH 09/82] Add to readme --- sendgrid/helpers/stats/README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sendgrid/helpers/stats/README.md b/sendgrid/helpers/stats/README.md index 2c062c3be..1fe31558b 100644 --- a/sendgrid/helpers/stats/README.md +++ b/sendgrid/helpers/stats/README.md @@ -1 +1,10 @@ -**This helper allows you to quickly and easily build a Stats object for sending your email stats to a database.** \ No newline at end of file +**This helper allows you to quickly and easily build a Stats object for sending your email stats to a database.** + +# Quick Start + +Run the [example](https://github.com/sendgrid/sendgrid-python/tree/master/examples/helpers/stats) (make sure you have set your environment variable to include your SENDGRID_API_KEY). + +## Usage + +- See the [examples](https://github.com/sendgrid/sendgrid-python/tree/master/examples/helpers/stats) for complete working examples. +- [Documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/Stats/index.html) \ No newline at end of file From 246efcc9ed1d525847fb73c4da874340358d48ce Mon Sep 17 00:00:00 2001 From: Aaron Mak Kang Sheng Date: Fri, 27 Oct 2017 08:15:56 +0800 Subject: [PATCH 10/82] add tests for stats helper --- examples/helpers/stats/stats_example.py | 10 ++-- sendgrid/helpers/stats/stats.py | 3 +- test/test_stats.py | 79 +++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 test/test_stats.py diff --git a/examples/helpers/stats/stats_example.py b/examples/helpers/stats/stats_example.py index 00a704c47..d48664c3f 100644 --- a/examples/helpers/stats/stats_example.py +++ b/examples/helpers/stats/stats_example.py @@ -92,8 +92,8 @@ def get_subuser_stats_sums(): print(response.headers) pprint_json(response.body) -# get_global_stats() -# get_category_stats() -# get_category_stats_sums() -# get_subuser_stats() -# get_subuser_stats_sums() +get_global_stats() +get_category_stats() +get_category_stats_sums() +get_subuser_stats() +get_subuser_stats_sums() diff --git a/sendgrid/helpers/stats/stats.py b/sendgrid/helpers/stats/stats.py index 550599138..8fe1399a2 100644 --- a/sendgrid/helpers/stats/stats.py +++ b/sendgrid/helpers/stats/stats.py @@ -202,6 +202,7 @@ def name(self, value): def get(self): return self.name + class Subuser(object): def __init__(self, name=None): @@ -218,4 +219,4 @@ def name(self, value): self._name = value def get(self): - return self.name \ No newline at end of file + return self.name diff --git a/test/test_stats.py b/test/test_stats.py new file mode 100644 index 000000000..eafd131db --- /dev/null +++ b/test/test_stats.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +import json +from sendgrid.helpers.stats import * + +try: + import unittest2 as unittest +except ImportError: + import unittest + + +class UnitTests(unittest.TestCase): + + def test_basicStats(self): + + """Minimum required for stats""" + global_stats = Stats(start_date='12-09-2017') + + self.assertEqual( + json.dumps( + global_stats.get(), + sort_keys=True), + '{"start_date": "12-09-2017"}' + ) + + self.assertTrue(isinstance(str(global_stats), str)) + + def test_Stats(self): + + all_stats = Stats(start_date='12-09-2017') + all_stats.end_date = '12-10-2017' + all_stats.aggregated_by = 'day' + all_stats._sort_by_direction = 'asc' + all_stats._limit = 100 + all_stats._offset = 2 + + self.assertEqual( + json.dumps( + all_stats.get(), + sort_keys=True), + '{"aggregated_by": "day", "end_date": "12-10-2017", ' + '"limit": 100, "offset": 2, "sort_by_direction": "asc", ' + '"start_date": "12-09-2017"}' + ) + + def test_categoryStats(self): + + category_stats = CategoryStats(start_date='12-09-2017', categories=['foo', 'bar']) + category_stats.end_date = '12-10-2017' + category_stats.aggregated_by = 'day' + category_stats._sort_by_direction = 'asc' + category_stats._limit = 100 + category_stats._offset = 2 + + self.assertEqual( + json.dumps( + category_stats.get(), + sort_keys=True), + '{"aggregated_by": "day", "categories": ["foo", "bar"], ' + '"end_date": "12-10-2017", "limit": 100, "offset": 2, ' + '"sort_by_direction": "asc", "start_date": "12-09-2017"}' + ) + + def test_subuserStats(self): + + subuser_stats = SubuserStats(start_date = '12-09-2017', subusers=['foo', 'bar']) + subuser_stats.end_date = '12-10-2017' + subuser_stats.aggregated_by = 'day' + subuser_stats._sort_by_direction = 'asc' + subuser_stats._limit = 100 + subuser_stats._offset = 2 + + self.assertEqual( + json.dumps( + subuser_stats.get(), + sort_keys=True), + '{"aggregated_by": "day", "end_date": "12-10-2017", ' + '"limit": 100, "offset": 2, "sort_by_direction": "asc", ' + '"start_date": "12-09-2017", "subusers": ["foo", "bar"]}' + ) From 760c5f105a76ebf4eeac32f002e5f4b68bf183e0 Mon Sep 17 00:00:00 2001 From: Aaron Mak Kang Sheng Date: Fri, 27 Oct 2017 08:43:37 +0800 Subject: [PATCH 11/82] Add more tests --- test/test_stats.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_stats.py b/test/test_stats.py index eafd131db..7da54b2e2 100644 --- a/test/test_stats.py +++ b/test/test_stats.py @@ -45,6 +45,7 @@ def test_Stats(self): def test_categoryStats(self): category_stats = CategoryStats(start_date='12-09-2017', categories=['foo', 'bar']) + category_stats.add_category(Category('woo')) category_stats.end_date = '12-10-2017' category_stats.aggregated_by = 'day' category_stats._sort_by_direction = 'asc' @@ -55,7 +56,7 @@ def test_categoryStats(self): json.dumps( category_stats.get(), sort_keys=True), - '{"aggregated_by": "day", "categories": ["foo", "bar"], ' + '{"aggregated_by": "day", "categories": ["foo", "bar", "woo"], ' '"end_date": "12-10-2017", "limit": 100, "offset": 2, ' '"sort_by_direction": "asc", "start_date": "12-09-2017"}' ) @@ -63,6 +64,7 @@ def test_categoryStats(self): def test_subuserStats(self): subuser_stats = SubuserStats(start_date = '12-09-2017', subusers=['foo', 'bar']) + subuser_stats.add_subuser(Subuser('blah')) subuser_stats.end_date = '12-10-2017' subuser_stats.aggregated_by = 'day' subuser_stats._sort_by_direction = 'asc' @@ -75,5 +77,5 @@ def test_subuserStats(self): sort_keys=True), '{"aggregated_by": "day", "end_date": "12-10-2017", ' '"limit": 100, "offset": 2, "sort_by_direction": "asc", ' - '"start_date": "12-09-2017", "subusers": ["foo", "bar"]}' + '"start_date": "12-09-2017", "subusers": ["foo", "bar", "blah"]}' ) From b12cb7bd464405598f9b43b1d43d418b38b1228e Mon Sep 17 00:00:00 2001 From: Aaron Mak Kang Sheng Date: Fri, 27 Oct 2017 22:47:18 +0800 Subject: [PATCH 12/82] add more tests --- test/test_stats.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/test_stats.py b/test/test_stats.py index 7da54b2e2..c71117397 100644 --- a/test/test_stats.py +++ b/test/test_stats.py @@ -30,6 +30,7 @@ def test_Stats(self): all_stats.end_date = '12-10-2017' all_stats.aggregated_by = 'day' all_stats._sort_by_direction = 'asc' + all_stats.sort_by_metric = 'clicks' all_stats._limit = 100 all_stats._offset = 2 @@ -39,7 +40,7 @@ def test_Stats(self): sort_keys=True), '{"aggregated_by": "day", "end_date": "12-10-2017", ' '"limit": 100, "offset": 2, "sort_by_direction": "asc", ' - '"start_date": "12-09-2017"}' + '"sort_by_metric": "clicks", "start_date": "12-09-2017"}' ) def test_categoryStats(self): @@ -49,6 +50,7 @@ def test_categoryStats(self): category_stats.end_date = '12-10-2017' category_stats.aggregated_by = 'day' category_stats._sort_by_direction = 'asc' + category_stats.sort_by_metric = 'clicks' category_stats._limit = 100 category_stats._offset = 2 @@ -58,7 +60,8 @@ def test_categoryStats(self): sort_keys=True), '{"aggregated_by": "day", "categories": ["foo", "bar", "woo"], ' '"end_date": "12-10-2017", "limit": 100, "offset": 2, ' - '"sort_by_direction": "asc", "start_date": "12-09-2017"}' + '"sort_by_direction": "asc", "sort_by_metric": "clicks", ' + '"start_date": "12-09-2017"}' ) def test_subuserStats(self): @@ -68,6 +71,7 @@ def test_subuserStats(self): subuser_stats.end_date = '12-10-2017' subuser_stats.aggregated_by = 'day' subuser_stats._sort_by_direction = 'asc' + subuser_stats.sort_by_metric = 'clicks' subuser_stats._limit = 100 subuser_stats._offset = 2 @@ -77,5 +81,6 @@ def test_subuserStats(self): sort_keys=True), '{"aggregated_by": "day", "end_date": "12-10-2017", ' '"limit": 100, "offset": 2, "sort_by_direction": "asc", ' - '"start_date": "12-09-2017", "subusers": ["foo", "bar", "blah"]}' + '"sort_by_metric": "clicks", "start_date": "12-09-2017", ' + '"subusers": ["foo", "bar", "blah"]}' ) From 1b9f336880b683e9c571185c8ba40da46d2c83d5 Mon Sep 17 00:00:00 2001 From: navinpai Date: Sun, 29 Oct 2017 00:28:24 +0530 Subject: [PATCH 13/82] Add slack event integration --- USE_CASES.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/USE_CASES.md b/USE_CASES.md index 810d345ca..b59981e19 100644 --- a/USE_CASES.md +++ b/USE_CASES.md @@ -7,6 +7,7 @@ This documentation provides examples for specific use cases. Please [open an iss * [How to Setup a Domain Whitelabel](#domain_whitelabel) * [How to View Email Statistics](#email_stats) * [Asynchronous Mail Send](#asynchronous-mail-send) +* [Slack Event API Integration](#slack_event_integration) # Transactional Templates @@ -272,3 +273,50 @@ if __name__ == "__main__": loop.run_until_complete(task) ``` + +# Integrate with Slack Events API + +It's fairly straightforward to integrate Sendgrid with Slack, to allow emails to be triggered by events happening on Slack. + +For this, we make use of the [Official Slack Events API](https://github.com/slackapi/python-slack-events-api), which can be installed using pip. + +To allow our application to get notifications of slack events, we first create a Slack App with Event Subscriptions as described [here](https://github.com/slackapi/python-slack-events-api#--development-workflow) + +Then, we set `SENDGRID_API_KEY` _(which you can create on the Sendgrid dashboard)_ and `SLACK_VERIFICATION_TOKEN` _(which you can get in the App Credentials section of the Slack App)_ as environment variables. + +Once this is done, we can subscribe to [events on Slack](https://api.slack.com/events) and trigger emails when an event occurs. In the example below, we trigger an email to `test@example.com` whenever someone posts a message on Slack that has the word "_help_" in it. + +``` +from slackeventsapi import SlackEventAdapter +from slackclient import SlackClient +import os +import sendgrid +from sendgrid.helpers.mail import * + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +SLACK_VERIFICATION_TOKEN = os.environ["SLACK_VERIFICATION_TOKEN"] +slack_events_adapter = SlackEventAdapter(SLACK_VERIFICATION_TOKEN, "/slack/events") + +@slack_events_adapter.on("message") +def handle_message(event_data): + message = event_data["event"] + # If the incoming message contains "help", then send an email using SendGrid + if message.get("subtype") is None and "help" in message.get('text').lower(): + message = "Someone needs your help: \n\n %s" % message["text"] + r = send_email(message) + print(r) + + +def send_email(message): + from_email = Email("slack_integration@example.com") + to_email = Email("test@example.com") + subject = "Psst... Someone needs help!" + content = Content("text/plain", message) + mail = Mail(from_email, subject, to_email, content) + response = sg.client.mail.send.post(request_body=mail.get()) + return response.status_code + +# Start the slack event listener server on port 3000 +slack_events_adapter.start(port=3000) +``` From 57c30401fab8c8883fd5bd5a7e6d9de7ff1bbcf8 Mon Sep 17 00:00:00 2001 From: heisendumb Date: Mon, 30 Oct 2017 00:26:08 -0200 Subject: [PATCH 14/82] docker-compose for issue #444 --- docker/Dockerfile | 4 +- docker/Makefile | 28 ++ docker/docker-compose.yml | 24 ++ .../examples/accesssettings/accesssettings.py | 84 ++++ docker/examples/alerts/alerts.py | 63 +++ docker/examples/apikeys/apikeys.py | 85 ++++ docker/examples/asm/asm.py | 174 ++++++++ docker/examples/browsers/browsers.py | 17 + docker/examples/campaigns/campaigns.py | 154 +++++++ docker/examples/categories/categories.py | 37 ++ docker/examples/clients/clients.py | 28 ++ docker/examples/contactdb/contactdb.py | 396 ++++++++++++++++++ docker/examples/devices/devices.py | 17 + docker/examples/geo/geo.py | 17 + docker/examples/helpers/mail/mail_example.py | 219 ++++++++++ docker/examples/ips/ips.py | 155 +++++++ docker/examples/mail/mail.py | 174 ++++++++ .../mailboxproviders/mailboxproviders.py | 17 + docker/examples/mailsettings/mailsettings.py | 220 ++++++++++ .../partnersettings/partnersettings.py | 40 ++ docker/examples/scopes/scopes.py | 16 + docker/examples/senders/senders.py | 99 +++++ docker/examples/stats/stats.py | 17 + docker/examples/subusers/subusers.py | 170 ++++++++ docker/examples/suppression/suppression.py | 202 +++++++++ .../trackingsettings/trackingsettings.py | 111 +++++ docker/examples/user/user.py | 294 +++++++++++++ docker/examples/whitelabel/whitelabel.py | 311 ++++++++++++++ 28 files changed, 3171 insertions(+), 2 deletions(-) create mode 100644 docker/Makefile create mode 100644 docker/docker-compose.yml create mode 100644 docker/examples/accesssettings/accesssettings.py create mode 100644 docker/examples/alerts/alerts.py create mode 100644 docker/examples/apikeys/apikeys.py create mode 100644 docker/examples/asm/asm.py create mode 100644 docker/examples/browsers/browsers.py create mode 100644 docker/examples/campaigns/campaigns.py create mode 100644 docker/examples/categories/categories.py create mode 100644 docker/examples/clients/clients.py create mode 100644 docker/examples/contactdb/contactdb.py create mode 100644 docker/examples/devices/devices.py create mode 100644 docker/examples/geo/geo.py create mode 100644 docker/examples/helpers/mail/mail_example.py create mode 100644 docker/examples/ips/ips.py create mode 100644 docker/examples/mail/mail.py create mode 100644 docker/examples/mailboxproviders/mailboxproviders.py create mode 100644 docker/examples/mailsettings/mailsettings.py create mode 100644 docker/examples/partnersettings/partnersettings.py create mode 100644 docker/examples/scopes/scopes.py create mode 100644 docker/examples/senders/senders.py create mode 100644 docker/examples/stats/stats.py create mode 100644 docker/examples/subusers/subusers.py create mode 100644 docker/examples/suppression/suppression.py create mode 100644 docker/examples/trackingsettings/trackingsettings.py create mode 100644 docker/examples/user/user.py create mode 100644 docker/examples/whitelabel/whitelabel.py diff --git a/docker/Dockerfile b/docker/Dockerfile index bc4ce8e79..393d91bfe 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -30,8 +30,8 @@ RUN python2.7 get-pip.py && \ # set up default sendgrid env WORKDIR /root/sources -RUN git clone https://github.com/sendgrid/sendgrid-python.git && \ - git clone https://github.com/sendgrid/python-http-client.git +RUN git clone https://github.com/sendgrid/sendgrid-python.git --branch && \ + git clone https://github.com/sendgrid/python-http-client.git --branch WORKDIR /root RUN ln -s /root/sources/sendgrid-python/sendgrid && \ ln -s /root/sources/python-http-client/python_http_client diff --git a/docker/Makefile b/docker/Makefile new file mode 100644 index 000000000..6ec47459d --- /dev/null +++ b/docker/Makefile @@ -0,0 +1,28 @@ +# import deploy config +deployfile=deploy.env +ifdef dpl +deployfile=$(dpl) +endif +include $(deployfile) +export $(shell sed 's/=.*//' $(deployfile)) + +stop: + docker-compose stop + +rm: stop + docker-compose stop -fvs + +clean: + docker rmi %(docker images -aq) + +clean_untagged: + docker rmi $(docker images --quiet --filter "dangling=true") 2>/dev/null + +build: + docker-compose up -d + +build-build: + docker-compose up --build -d + +up: rm clean build-build + echo "Sendgrid dev environment is alive :D" diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 000000000..d35772fd2 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,24 @@ +version: "3.3" + +services: + sendgrid: + image: sendgrid/sendgrid-python:${TAG} + restart: unless-stopped + container_name: sendgrid-prod + volumes: + - ${PATH_TO_SENDGRID-PYTHON_PROD}:/mnt/sendgrid-python + - ${PATH_TO_HTTP-CLIENT_PROD}:/mnt/python-http-client + env_file: .env + + sendgrid-dev: + build: + context: . + args: + - SENDGRID-PYTHON_VERSION: {SENDGRID-PYTHON_VERSION} + - HTTP-CLIENT_VERSION: {HTTP-CLIENT_VERSION} + restart: unless-stopped + container_name: sendgrid-dev + env_file: .env + volumes: + - ${PATH_TO_SENDGRID-PYTHON}:/mnt/sendgrid-python + - ${PATH_TO_HTTP-CLIENT}:/mnt/python-http-client diff --git a/docker/examples/accesssettings/accesssettings.py b/docker/examples/accesssettings/accesssettings.py new file mode 100644 index 000000000..aac0e4a54 --- /dev/null +++ b/docker/examples/accesssettings/accesssettings.py @@ -0,0 +1,84 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Retrieve all recent access attempts # +# GET /access_settings/activity # + +params = {'limit': 1} +response = sg.client.access_settings.activity.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Add one or more IPs to the whitelist # +# POST /access_settings/whitelist # + +data = { + "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) +print(response.body) +print(response.headers) + +################################################## +# Retrieve a list of currently whitelisted IPs # +# GET /access_settings/whitelist # + +response = sg.client.access_settings.whitelist.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Remove one or more IPs from the whitelist # +# DELETE /access_settings/whitelist # + +data = { + "ids": [ + 1, + 2, + 3 + ] +} +response = sg.client.access_settings.whitelist.delete(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve a specific whitelisted IP # +# GET /access_settings/whitelist/{rule_id} # + +rule_id = "test_url_param" +response = sg.client.access_settings.whitelist._(rule_id).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Remove a specific IP from the whitelist # +# DELETE /access_settings/whitelist/{rule_id} # + +rule_id = "test_url_param" +response = sg.client.access_settings.whitelist._(rule_id).delete() +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/alerts/alerts.py b/docker/examples/alerts/alerts.py new file mode 100644 index 000000000..e30d48748 --- /dev/null +++ b/docker/examples/alerts/alerts.py @@ -0,0 +1,63 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Create a new Alert # +# POST /alerts # + +data = { + "email_to": "example@example.com", + "frequency": "daily", + "type": "stats_notification" +} +response = sg.client.alerts.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all alerts # +# GET /alerts # + +response = sg.client.alerts.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update an alert # +# PATCH /alerts/{alert_id} # + +data = { + "email_to": "example@example.com" +} +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) + +################################################## +# Retrieve a specific alert # +# GET /alerts/{alert_id} # + +alert_id = "test_url_param" +response = sg.client.alerts._(alert_id).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete an alert # +# DELETE /alerts/{alert_id} # + +alert_id = "test_url_param" +response = sg.client.alerts._(alert_id).delete() +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/apikeys/apikeys.py b/docker/examples/apikeys/apikeys.py new file mode 100644 index 000000000..42c3afa10 --- /dev/null +++ b/docker/examples/apikeys/apikeys.py @@ -0,0 +1,85 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=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" + ] +} +response = sg.client.api_keys.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all API Keys belonging to the authenticated user # +# GET /api_keys # + +params = {'limit': 1} +response = sg.client.api_keys.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update the name & scopes of an API Key # +# PUT /api_keys/{api_key_id} # + +data = { + "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) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update API keys # +# PATCH /api_keys/{api_key_id} # + +data = { + "name": "A New Hope" +} +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) + +################################################## +# Retrieve an existing API Key # +# GET /api_keys/{api_key_id} # + +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) + +################################################## +# Delete API keys # +# DELETE /api_keys/{api_key_id} # + +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) + diff --git a/docker/examples/asm/asm.py b/docker/examples/asm/asm.py new file mode 100644 index 000000000..43130cf06 --- /dev/null +++ b/docker/examples/asm/asm.py @@ -0,0 +1,174 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=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" +} +response = sg.client.asm.groups.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve information about multiple suppression groups # +# GET /asm/groups # + +params = {'id': 1} +response = sg.client.asm.groups.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update a suppression group. # +# PATCH /asm/groups/{group_id} # + +data = { + "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) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Get information on a single suppression group. # +# GET /asm/groups/{group_id} # + +group_id = "test_url_param" +response = sg.client.asm.groups._(group_id).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete a suppression group. # +# DELETE /asm/groups/{group_id} # + +group_id = "test_url_param" +response = sg.client.asm.groups._(group_id).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Add suppressions to a suppression group # +# POST /asm/groups/{group_id}/suppressions # + +data = { + "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) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all suppressions for a suppression group # +# GET /asm/groups/{group_id}/suppressions # + +group_id = "test_url_param" +response = sg.client.asm.groups._(group_id).suppressions.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Search for suppressions within a group # +# POST /asm/groups/{group_id}/suppressions/search # + +data = { + "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) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete a suppression from a suppression group # +# DELETE /asm/groups/{group_id}/suppressions/{email} # + +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) + +################################################## +# Retrieve all suppressions # +# GET /asm/suppressions # + +response = sg.client.asm.suppressions.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Add recipient addresses to the global suppression group. # +# POST /asm/suppressions/global # + +data = { + "recipient_emails": [ + "test1@example.com", + "test2@example.com" + ] +} +response = sg.client.asm.suppressions._("global").post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve a Global Suppression # +# GET /asm/suppressions/global/{email} # + +email = "test_url_param" +response = sg.client.asm.suppressions._("global")._(email).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete a Global Suppression # +# DELETE /asm/suppressions/global/{email} # + +email = "test_url_param" +response = sg.client.asm.suppressions._("global")._(email).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all suppression groups for an email address # +# GET /asm/suppressions/{email} # + +email = "test_url_param" +response = sg.client.asm.suppressions._(email).get() +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/browsers/browsers.py b/docker/examples/browsers/browsers.py new file mode 100644 index 000000000..c123c12e5 --- /dev/null +++ b/docker/examples/browsers/browsers.py @@ -0,0 +1,17 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=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'} +response = sg.client.browsers.stats.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/campaigns/campaigns.py b/docker/examples/campaigns/campaigns.py new file mode 100644 index 000000000..c77fc878b --- /dev/null +++ b/docker/examples/campaigns/campaigns.py @@ -0,0 +1,154 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=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" +} +response = sg.client.campaigns.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all Campaigns # +# GET /campaigns # + +params = {'limit': 1, 'offset': 1} +response = sg.client.campaigns.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update a Campaign # +# 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" +} +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) + +################################################## +# Retrieve a single campaign # +# GET /campaigns/{campaign_id} # + +campaign_id = "test_url_param" +response = sg.client.campaigns._(campaign_id).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete a Campaign # +# DELETE /campaigns/{campaign_id} # + +campaign_id = "test_url_param" +response = sg.client.campaigns._(campaign_id).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update a Scheduled Campaign # +# PATCH /campaigns/{campaign_id}/schedules # + +data = { + "send_at": 1489451436 +} +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) + +################################################## +# Schedule a Campaign # +# POST /campaigns/{campaign_id}/schedules # + +data = { + "send_at": 1489771528 +} +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) + +################################################## +# View Scheduled Time of a Campaign # +# GET /campaigns/{campaign_id}/schedules # + +campaign_id = "test_url_param" +response = sg.client.campaigns._(campaign_id).schedules.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Unschedule a Scheduled Campaign # +# DELETE /campaigns/{campaign_id}/schedules # + +campaign_id = "test_url_param" +response = sg.client.campaigns._(campaign_id).schedules.delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Send a Campaign # +# POST /campaigns/{campaign_id}/schedules/now # + +campaign_id = "test_url_param" +response = sg.client.campaigns._(campaign_id).schedules.now.post() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Send a Test Campaign # +# POST /campaigns/{campaign_id}/schedules/test # + +data = { + "to": "your.email@example.com" +} +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) + diff --git a/docker/examples/categories/categories.py b/docker/examples/categories/categories.py new file mode 100644 index 000000000..7984f0fe0 --- /dev/null +++ b/docker/examples/categories/categories.py @@ -0,0 +1,37 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Retrieve all categories # +# GET /categories # + +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) + +################################################## +# 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'} +response = sg.client.categories.stats.get(query_params=params) +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?] # +# 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'} +response = sg.client.categories.stats.sums.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/clients/clients.py b/docker/examples/clients/clients.py new file mode 100644 index 000000000..7831ef78f --- /dev/null +++ b/docker/examples/clients/clients.py @@ -0,0 +1,28 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=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'} +response = sg.client.clients.stats.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# 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'} +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/docker/examples/contactdb/contactdb.py b/docker/examples/contactdb/contactdb.py new file mode 100644 index 000000000..c234d7724 --- /dev/null +++ b/docker/examples/contactdb/contactdb.py @@ -0,0 +1,396 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Create a Custom Field # +# POST /contactdb/custom_fields # + +data = { + "name": "pet", + "type": "text" +} +response = sg.client.contactdb.custom_fields.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all custom fields # +# GET /contactdb/custom_fields # + +response = sg.client.contactdb.custom_fields.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve a Custom Field # +# GET /contactdb/custom_fields/{custom_field_id} # + +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) + +################################################## +# Delete a Custom Field # +# DELETE /contactdb/custom_fields/{custom_field_id} # + +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) + +################################################## +# Create a List # +# POST /contactdb/lists # + +data = { + "name": "your list name" +} +response = sg.client.contactdb.lists.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all lists # +# GET /contactdb/lists # + +response = sg.client.contactdb.lists.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete Multiple lists # +# DELETE /contactdb/lists # + +data = [ + 1, + 2, + 3, + 4 +] +response = sg.client.contactdb.lists.delete(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update a List # +# PATCH /contactdb/lists/{list_id} # + +data = { + "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) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve a single list # +# GET /contactdb/lists/{list_id} # + +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) + +################################################## +# Delete a List # +# DELETE /contactdb/lists/{list_id} # + +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) + +################################################## +# Add Multiple Recipients to a List # +# POST /contactdb/lists/{list_id}/recipients # + +data = [ + "recipient_id1", + "recipient_id2" +] +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) + +################################################## +# Retrieve all recipients on a List # +# GET /contactdb/lists/{list_id}/recipients # + +params = {'page': 1, 'page_size': 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) + +################################################## +# Add a Single Recipient to a List # +# POST /contactdb/lists/{list_id}/recipients/{recipient_id} # + +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) + +################################################## +# Delete a Single Recipient from a Single List # +# DELETE /contactdb/lists/{list_id}/recipients/{recipient_id} # + +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) + +################################################## +# Update Recipient # +# PATCH /contactdb/recipients # + +data = [ + { + "email": "jones@example.com", + "first_name": "Guy", + "last_name": "Jones" + } +] +response = sg.client.contactdb.recipients.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Add recipients # +# 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" + } +] +response = sg.client.contactdb.recipients.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve recipients # +# GET /contactdb/recipients # + +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) + +################################################## +# Delete Recipient # +# DELETE /contactdb/recipients # + +data = [ + "recipient_id1", + "recipient_id2" +] +response = sg.client.contactdb.recipients.delete(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve the count of billable recipients # +# GET /contactdb/recipients/billable_count # + +response = sg.client.contactdb.recipients.billable_count.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve a Count of Recipients # +# GET /contactdb/recipients/count # + +response = sg.client.contactdb.recipients.count.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve recipients matching search criteria # +# GET /contactdb/recipients/search # + +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) + +################################################## +# Retrieve a single recipient # +# GET /contactdb/recipients/{recipient_id} # + +recipient_id = "test_url_param" +response = sg.client.contactdb.recipients._(recipient_id).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete a Recipient # +# DELETE /contactdb/recipients/{recipient_id} # + +recipient_id = "test_url_param" +response = sg.client.contactdb.recipients._(recipient_id).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve the lists that a recipient is on # +# GET /contactdb/recipients/{recipient_id}/lists # + +recipient_id = "test_url_param" +response = sg.client.contactdb.recipients._(recipient_id).lists.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve reserved fields # +# GET /contactdb/reserved_fields # + +response = sg.client.contactdb.reserved_fields.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Create a Segment # +# 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" +} +response = sg.client.contactdb.segments.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all segments # +# GET /contactdb/segments # + +response = sg.client.contactdb.segments.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update a segment # +# PATCH /contactdb/segments/{segment_id} # + +data = { + "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) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve a segment # +# GET /contactdb/segments/{segment_id} # + +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) + +################################################## +# Delete a segment # +# DELETE /contactdb/segments/{segment_id} # + +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) + +################################################## +# Retrieve recipients on a segment # +# GET /contactdb/segments/{segment_id}/recipients # + +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) + diff --git a/docker/examples/devices/devices.py b/docker/examples/devices/devices.py new file mode 100644 index 000000000..108e98452 --- /dev/null +++ b/docker/examples/devices/devices.py @@ -0,0 +1,17 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=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} +response = sg.client.devices.stats.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/geo/geo.py b/docker/examples/geo/geo.py new file mode 100644 index 000000000..7d58ec085 --- /dev/null +++ b/docker/examples/geo/geo.py @@ -0,0 +1,17 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=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'} +response = sg.client.geo.stats.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/helpers/mail/mail_example.py b/docker/examples/helpers/mail/mail_example.py new file mode 100644 index 000000000..bfd8ea718 --- /dev/null +++ b/docker/examples/helpers/mail/mail_example.py @@ -0,0 +1,219 @@ +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_personalization(personalization): + """Build personalization mock instance from a mock dict""" + mock_personalization = Personalization() + for to_addr in personalization['to_list']: + personalization.add_to(to_addr) + + for cc_addr in personalization['cc_list']: + personalization.add_to(cc_addr) + + for bcc_addr in personalization['bcc_list']: + personalization.add_bc(bcc_addr) + + for header in personalization['headers']: + personalization.add_header(header) + + for substitution in personalization['substitutions']: + personalization.add_substitution(substitution) + + for arg in personalization['custom_args']: + personalization.add_custom_arg(arg) + + personalization.subject = personalization['subject'] + personalization.send_at = personalization['send_at'] + return mock_personalization + + +def get_mock_personalization_dict(): + """Get a dict of personalization mock.""" + mock_pers = dict() + + mock_pers['to_list'] = [Email("test1@example.com", + "Example User"), + Email("test2@example.com", + "Example User")] + + mock_pers['cc_list'] = [Email("test3@example.com", + "Example User"), + Email("test4@example.com", + "Example User")] + + mock_pers['bcc_list'] = [Email("test5@example.com"), + Email("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_attachment1(): + """Build attachment mock.""" + attachment = Attachment() + attachment.content = ("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNl" + "Y3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12") + attachment.type = "application/pdf" + attachment.filename = "balance_001.pdf" + attachment.disposition = "attachment" + attachment.content_id = "Balance Sheet" + return attachment + + +def build_attachment2(): + """Build attachment mock.""" + attachment = Attachment() + attachment.content = "BwdW" + attachment.type = "image/png" + attachment.filename = "banner.png" + attachment.disposition = "inline" + attachment.content_id = "Banner" + return attachment + + +def build_mail_settings(): + """Build mail settings mock.""" + 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") + return mail_settings + + +def build_tracking_settings(): + """Build tracking settings mock.""" + 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")) + + subs_track = 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.subscription_tracking = subs_track + tracking_settings.ganalytics = Ganalytics(True, "some source", + "some medium", "some term", + "some_content", "some_campaign") + return tracking_settings + + +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 = get_mock_personalization_dict() + mail.add_personalization(build_personalization(personalization)) + mail.add_personalization(build_personalization(personalization)) + + mail.add_content(Content("text/plain", "some text here")) + mail.add_content(Content("text/html", ("some text " + "here"))) + + mail.add_attachment(build_attachment1()) + mail.add_attachment(build_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.mail_settings = build_mail_settings() + mail.tracking_settings = build_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) + + +# this will actually send an email +send_hello_email() + +# this will only send an email if you set SandBox Mode to False +send_kitchen_sink() diff --git a/docker/examples/ips/ips.py b/docker/examples/ips/ips.py new file mode 100644 index 000000000..6c48ae306 --- /dev/null +++ b/docker/examples/ips/ips.py @@ -0,0 +1,155 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=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} +response = sg.client.ips.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all assigned IPs # +# GET /ips/assigned # + +response = sg.client.ips.assigned.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Create an IP pool. # +# POST /ips/pools # + +data = { + "name": "marketing" +} +response = sg.client.ips.pools.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all IP pools. # +# GET /ips/pools # + +response = sg.client.ips.pools.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update an IP pools name. # +# PUT /ips/pools/{pool_name} # + +data = { + "name": "new_pool_name" +} +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) + +################################################## +# Retrieve all IPs in a specified pool. # +# GET /ips/pools/{pool_name} # + +pool_name = "test_url_param" +response = sg.client.ips.pools._(pool_name).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete an IP pool. # +# DELETE /ips/pools/{pool_name} # + +pool_name = "test_url_param" +response = sg.client.ips.pools._(pool_name).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Add an IP address to a pool # +# POST /ips/pools/{pool_name}/ips # + +data = { + "ip": "0.0.0.0" +} +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) + +################################################## +# Remove an IP address from a pool. # +# DELETE /ips/pools/{pool_name}/ips/{ip} # + +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) + +################################################## +# Add an IP to warmup # +# POST /ips/warmup # + +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) + +################################################## +# Retrieve all IPs currently in warmup # +# GET /ips/warmup # + +response = sg.client.ips.warmup.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve warmup status for a specific IP address # +# GET /ips/warmup/{ip_address} # + +ip_address = "test_url_param" +response = sg.client.ips.warmup._(ip_address).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Remove an IP from warmup # +# DELETE /ips/warmup/{ip_address} # + +ip_address = "test_url_param" +response = sg.client.ips.warmup._(ip_address).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all IP pools an IP address belongs to # +# GET /ips/{ip_address} # + +ip_address = "test_url_param" +response = sg.client.ips._(ip_address).get() +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/mail/mail.py b/docker/examples/mail/mail.py new file mode 100644 index 000000000..fef420e87 --- /dev/null +++ b/docker/examples/mail/mail.py @@ -0,0 +1,174 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Create a batch ID # +# POST /mail/batch # + +response = sg.client.mail.batch.post() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Validate batch ID # +# GET /mail/batch/{batch_id} # + +batch_id = "test_url_param" +response = sg.client.mail.batch._(batch_id).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# 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). + +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": "

Thanks
The 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": [ + { + "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 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/docker/examples/mailboxproviders/mailboxproviders.py b/docker/examples/mailboxproviders/mailboxproviders.py new file mode 100644 index 000000000..1b75ecac5 --- /dev/null +++ b/docker/examples/mailboxproviders/mailboxproviders.py @@ -0,0 +1,17 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=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'} +response = sg.client.mailbox_providers.stats.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/mailsettings/mailsettings.py b/docker/examples/mailsettings/mailsettings.py new file mode 100644 index 000000000..18c57b960 --- /dev/null +++ b/docker/examples/mailsettings/mailsettings.py @@ -0,0 +1,220 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Retrieve all mail settings # +# GET /mail_settings # + +params = {'limit': 1, 'offset': 1} +response = sg.client.mail_settings.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update address whitelist mail settings # +# PATCH /mail_settings/address_whitelist # + +data = { + "enabled": True, + "list": [ + "email1@example.com", + "example.com" + ] +} +response = sg.client.mail_settings.address_whitelist.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve address whitelist mail settings # +# GET /mail_settings/address_whitelist # + +response = sg.client.mail_settings.address_whitelist.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update BCC mail settings # +# PATCH /mail_settings/bcc # + +data = { + "email": "email@example.com", + "enabled": False +} +response = sg.client.mail_settings.bcc.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all BCC mail settings # +# GET /mail_settings/bcc # + +response = sg.client.mail_settings.bcc.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update bounce purge mail settings # +# PATCH /mail_settings/bounce_purge # + +data = { + "enabled": True, + "hard_bounces": 5, + "soft_bounces": 5 +} +response = sg.client.mail_settings.bounce_purge.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve bounce purge mail settings # +# GET /mail_settings/bounce_purge # + +response = sg.client.mail_settings.bounce_purge.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update footer mail settings # +# PATCH /mail_settings/footer # + +data = { + "enabled": True, + "html_content": "...", + "plain_content": "..." +} +response = sg.client.mail_settings.footer.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve footer mail settings # +# GET /mail_settings/footer # + +response = sg.client.mail_settings.footer.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update forward bounce mail settings # +# PATCH /mail_settings/forward_bounce # + +data = { + "email": "example@example.com", + "enabled": True +} +response = sg.client.mail_settings.forward_bounce.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve forward bounce mail settings # +# GET /mail_settings/forward_bounce # + +response = sg.client.mail_settings.forward_bounce.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update forward spam mail settings # +# PATCH /mail_settings/forward_spam # + +data = { + "email": "", + "enabled": False +} +response = sg.client.mail_settings.forward_spam.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve forward spam mail settings # +# GET /mail_settings/forward_spam # + +response = sg.client.mail_settings.forward_spam.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update plain content mail settings # +# PATCH /mail_settings/plain_content # + +data = { + "enabled": False +} +response = sg.client.mail_settings.plain_content.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve plain content mail settings # +# GET /mail_settings/plain_content # + +response = sg.client.mail_settings.plain_content.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update spam check mail settings # +# PATCH /mail_settings/spam_check # + +data = { + "enabled": True, + "max_score": 5, + "url": "url" +} +response = sg.client.mail_settings.spam_check.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve spam check mail settings # +# GET /mail_settings/spam_check # + +response = sg.client.mail_settings.spam_check.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update template mail settings # +# PATCH /mail_settings/template # + +data = { + "enabled": True, + "html_content": "<% body %>" +} +response = sg.client.mail_settings.template.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve legacy template mail settings # +# GET /mail_settings/template # + +response = sg.client.mail_settings.template.get() +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/partnersettings/partnersettings.py b/docker/examples/partnersettings/partnersettings.py new file mode 100644 index 000000000..37f77f4e6 --- /dev/null +++ b/docker/examples/partnersettings/partnersettings.py @@ -0,0 +1,40 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Returns a list of all partner settings. # +# GET /partner_settings # + +params = {'limit': 1, 'offset': 1} +response = sg.client.partner_settings.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Updates New Relic partner settings. # +# PATCH /partner_settings/new_relic # + +data = { + "enable_subuser_statistics": True, + "enabled": True, + "license_key": "" +} +response = sg.client.partner_settings.new_relic.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Returns all New Relic partner settings. # +# GET /partner_settings/new_relic # + +response = sg.client.partner_settings.new_relic.get() +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/scopes/scopes.py b/docker/examples/scopes/scopes.py new file mode 100644 index 000000000..124f77d39 --- /dev/null +++ b/docker/examples/scopes/scopes.py @@ -0,0 +1,16 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Retrieve a list of scopes for which this user has access. # +# GET /scopes # + +response = sg.client.scopes.get() +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/senders/senders.py b/docker/examples/senders/senders.py new file mode 100644 index 000000000..f21459b71 --- /dev/null +++ b/docker/examples/senders/senders.py @@ -0,0 +1,99 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=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" +} +response = sg.client.senders.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Get all Sender Identities # +# GET /senders # + +response = sg.client.senders.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update a Sender Identity # +# 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" +} +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) + +################################################## +# View a Sender Identity # +# GET /senders/{sender_id} # + +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete a Sender Identity # +# DELETE /senders/{sender_id} # + +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Resend Sender Identity Verification # +# POST /senders/{sender_id}/resend_verification # + +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).resend_verification.post() +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/stats/stats.py b/docker/examples/stats/stats.py new file mode 100644 index 000000000..a7bf3362e --- /dev/null +++ b/docker/examples/stats/stats.py @@ -0,0 +1,17 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=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} +response = sg.client.stats.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/subusers/subusers.py b/docker/examples/subusers/subusers.py new file mode 100644 index 000000000..6aa91e535 --- /dev/null +++ b/docker/examples/subusers/subusers.py @@ -0,0 +1,170 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=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" +} +response = sg.client.subusers.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# List all Subusers # +# GET /subusers # + +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 # +# GET /subusers/reputations # + +params = {'usernames': 'test_string'} +response = sg.client.subusers.reputations.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# 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'} +response = sg.client.subusers.stats.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# 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'} +response = sg.client.subusers.stats.monthly.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# 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'} +response = sg.client.subusers.stats.sums.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Enable/disable a subuser # +# PATCH /subusers/{subuser_name} # + +data = { + "disabled": 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) + +################################################## +# Delete a subuser # +# DELETE /subusers/{subuser_name} # + +subuser_name = "test_url_param" +response = sg.client.subusers._(subuser_name).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update IPs assigned to a subuser # +# PUT /subusers/{subuser_name}/ips # + +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) + +################################################## +# Update Monitor Settings for a subuser # +# PUT /subusers/{subuser_name}/monitor # + +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 # +# POST /subusers/{subuser_name}/monitor # + +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) + +################################################## +# Retrieve monitor settings for a subuser # +# GET /subusers/{subuser_name}/monitor # + +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 # +# DELETE /subusers/{subuser_name}/monitor # + +subuser_name = "test_url_param" +response = sg.client.subusers._(subuser_name).monitor.delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# 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} +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) + diff --git a/docker/examples/suppression/suppression.py b/docker/examples/suppression/suppression.py new file mode 100644 index 000000000..abdaef76d --- /dev/null +++ b/docker/examples/suppression/suppression.py @@ -0,0 +1,202 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Retrieve all blocks # +# GET /suppression/blocks # + +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) + +################################################## +# Delete blocks # +# DELETE /suppression/blocks # + +data = { + "delete_all": False, + "emails": [ + "example1@example.com", + "example2@example.com" + ] +} +response = sg.client.suppression.blocks.delete(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve a specific block # +# GET /suppression/blocks/{email} # + +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 # +# DELETE /suppression/blocks/{email} # + +email = "test_url_param" +response = sg.client.suppression.blocks._(email).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all bounces # +# GET /suppression/bounces # + +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 # +# DELETE /suppression/bounces # + +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) + +################################################## +# Retrieve a Bounce # +# GET /suppression/bounces/{email} # + +email = "test_url_param" +response = sg.client.suppression.bounces._(email).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete a bounce # +# DELETE /suppression/bounces/{email} # + +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 all invalid emails # +# GET /suppression/invalid_emails # + +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) + +################################################## +# Delete invalid emails # +# DELETE /suppression/invalid_emails # + +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 a specific invalid email # +# GET /suppression/invalid_emails/{email} # + +email = "test_url_param" +response = sg.client.suppression.invalid_emails._(email).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete a specific invalid email # +# DELETE /suppression/invalid_emails/{email} # + +email = "test_url_param" +response = sg.client.suppression.invalid_emails._(email).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve a specific spam report # +# GET /suppression/spam_report/{email} # + +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 # +# DELETE /suppression/spam_report/{email} # + +email = "test_url_param" +response = sg.client.suppression.spam_report._(email).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all spam reports # +# GET /suppression/spam_reports # + +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) + +################################################## +# Delete spam reports # +# DELETE /suppression/spam_reports # + +data = { + "delete_all": False, + "emails": [ + "example1@example.com", + "example2@example.com" + ] +} +response = sg.client.suppression.spam_reports.delete(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all global suppressions # +# GET /suppression/unsubscribes # + +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) + diff --git a/docker/examples/trackingsettings/trackingsettings.py b/docker/examples/trackingsettings/trackingsettings.py new file mode 100644 index 000000000..80dbe243a --- /dev/null +++ b/docker/examples/trackingsettings/trackingsettings.py @@ -0,0 +1,111 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Retrieve Tracking Settings # +# GET /tracking_settings # + +params = {'limit': 1, 'offset': 1} +response = sg.client.tracking_settings.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update Click Tracking Settings # +# PATCH /tracking_settings/click # + +data = { + "enabled": True +} +response = sg.client.tracking_settings.click.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve Click Track Settings # +# GET /tracking_settings/click # + +response = sg.client.tracking_settings.click.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update Google Analytics Settings # +# PATCH /tracking_settings/google_analytics # + +data = { + "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) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve Google Analytics Settings # +# GET /tracking_settings/google_analytics # + +response = sg.client.tracking_settings.google_analytics.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update Open Tracking Settings # +# PATCH /tracking_settings/open # + +data = { + "enabled": True +} +response = sg.client.tracking_settings.open.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Get Open Tracking Settings # +# GET /tracking_settings/open # + +response = sg.client.tracking_settings.open.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update Subscription Tracking Settings # +# PATCH /tracking_settings/subscription # + +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) + +################################################## +# Retrieve Subscription Tracking Settings # +# GET /tracking_settings/subscription # + +response = sg.client.tracking_settings.subscription.get() +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/user/user.py b/docker/examples/user/user.py new file mode 100644 index 000000000..9e3f24766 --- /dev/null +++ b/docker/examples/user/user.py @@ -0,0 +1,294 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Get a user's account information. # +# GET /user/account # + +response = sg.client.user.account.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve your credit balance # +# GET /user/credits # + +response = sg.client.user.credits.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update your account email address # +# PUT /user/email # + +data = { + "email": "example@example.com" +} +response = sg.client.user.email.put(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve your account email address # +# GET /user/email # + +response = sg.client.user.email.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update your password # +# PUT /user/password # + +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) + +################################################## +# Update a user's profile # +# PATCH /user/profile # + +data = { + "city": "Orange", + "first_name": "Example", + "last_name": "User" +} +response = sg.client.user.profile.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Get a user's profile # +# GET /user/profile # + +response = sg.client.user.profile.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Cancel or pause a scheduled send # +# POST /user/scheduled_sends # + +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) + +################################################## +# Retrieve all scheduled sends # +# GET /user/scheduled_sends # + +response = sg.client.user.scheduled_sends.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update user scheduled send information # +# PATCH /user/scheduled_sends/{batch_id} # + +data = { + "status": "pause" +} +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 scheduled send # +# GET /user/scheduled_sends/{batch_id} # + +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 # +# DELETE /user/scheduled_sends/{batch_id} # + +batch_id = "test_url_param" +response = sg.client.user.scheduled_sends._(batch_id).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update Enforced TLS settings # +# PATCH /user/settings/enforced_tls # + +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) + +################################################## +# Retrieve current Enforced TLS settings. # +# GET /user/settings/enforced_tls # + +response = sg.client.user.settings.enforced_tls.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update your username # +# PUT /user/username # + +data = { + "username": "test_username" +} +response = sg.client.user.username.put(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve your username # +# GET /user/username # + +response = sg.client.user.username.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update Event Notification Settings # +# 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" +} +response = sg.client.user.webhooks.event.settings.patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve Event Webhook settings # +# GET /user/webhooks/event/settings # + +response = sg.client.user.webhooks.event.settings.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Test Event Notification Settings # +# POST /user/webhooks/event/test # + +data = { + "url": "url" +} +response = sg.client.user.webhooks.event.test.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Create a parse setting # +# POST /user/webhooks/parse/settings # + +data = { + "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) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all parse settings # +# GET /user/webhooks/parse/settings # + +response = sg.client.user.webhooks.parse.settings.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update a parse setting # +# PATCH /user/webhooks/parse/settings/{hostname} # + +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) + +################################################## +# Retrieve a specific parse setting # +# GET /user/webhooks/parse/settings/{hostname} # + +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 # +# DELETE /user/webhooks/parse/settings/{hostname} # + +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. # +# 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'} +response = sg.client.user.webhooks.parse.stats.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/docker/examples/whitelabel/whitelabel.py b/docker/examples/whitelabel/whitelabel.py new file mode 100644 index 000000000..f529d3ed2 --- /dev/null +++ b/docker/examples/whitelabel/whitelabel.py @@ -0,0 +1,311 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Create a domain whitelabel. # +# 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" +} +response = sg.client.whitelabel.domains.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# List all domain whitelabels. # +# GET /whitelabel/domains # + +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 /whitelabel/domains/default # + +response = sg.client.whitelabel.domains.default.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# List the domain whitelabel associated with the given user. # +# GET /whitelabel/domains/subuser # + +response = sg.client.whitelabel.domains.subuser.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Disassociate a domain whitelabel from a given user. # +# DELETE /whitelabel/domains/subuser # + +response = sg.client.whitelabel.domains.subuser.delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update a domain whitelabel. # +# PATCH /whitelabel/domains/{domain_id} # + +data = { + "custom_spf": True, + "default": False +} +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) + +################################################## +# Retrieve a domain whitelabel. # +# GET /whitelabel/domains/{domain_id} # + +domain_id = "test_url_param" +response = sg.client.whitelabel.domains._(domain_id).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete a domain whitelabel. # +# DELETE /whitelabel/domains/{domain_id} # + +domain_id = "test_url_param" +response = sg.client.whitelabel.domains._(domain_id).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Associate a domain whitelabel with a given user. # +# POST /whitelabel/domains/{domain_id}/subuser # + +data = { + "username": "jane@example.com" +} +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) + +################################################## +# Add an IP to a domain whitelabel. # +# POST /whitelabel/domains/{id}/ips # + +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) + +################################################## +# Remove an IP from a domain whitelabel. # +# DELETE /whitelabel/domains/{id}/ips/{ip} # + +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) + +################################################## +# Validate a domain whitelabel. # +# POST /whitelabel/domains/{id}/validate # + +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 # +# POST /whitelabel/ips # + +data = { + "domain": "example.com", + "ip": "192.168.1.1", + "subdomain": "email" +} +response = sg.client.whitelabel.ips.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all IP whitelabels # +# GET /whitelabel/ips # + +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) + +################################################## +# Retrieve an IP whitelabel # +# GET /whitelabel/ips/{id} # + +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 /whitelabel/ips/{id} # + +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 # +# POST /whitelabel/ips/{id}/validate # + +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 # +# POST /whitelabel/links # + +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) + +################################################## +# Retrieve all link whitelabels # +# GET /whitelabel/links # + +params = {'limit': 1} +response = sg.client.whitelabel.links.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve a Default Link Whitelabel # +# GET /whitelabel/links/default # + +params = {'domain': 'test_string'} +response = sg.client.whitelabel.links.default.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve Associated Link Whitelabel # +# GET /whitelabel/links/subuser # + +params = {'username': 'test_string'} +response = sg.client.whitelabel.links.subuser.get(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Disassociate a Link Whitelabel # +# DELETE /whitelabel/links/subuser # + +params = {'username': 'test_string'} +response = sg.client.whitelabel.links.subuser.delete(query_params=params) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update a Link Whitelabel # +# PATCH /whitelabel/links/{id} # + +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 Link Whitelabel # +# GET /whitelabel/links/{id} # + +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 /whitelabel/links/{id} # + +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 # +# POST /whitelabel/links/{id}/validate # + +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 # +# POST /whitelabel/links/{link_id}/subuser # + +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) + From b916a6daf669a5c4f68e5133d4a150abcc15d4b3 Mon Sep 17 00:00:00 2001 From: heisendumb Date: Mon, 30 Oct 2017 00:31:16 -0200 Subject: [PATCH 15/82] added args to Dockerfile --- docker/Dockerfile | 7 +++++-- docker/Makefile | 8 -------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 393d91bfe..a0e5f4885 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,6 +2,9 @@ FROM ubuntu:xenial ENV PYTHON_VERSIONS='python2.6 python2.7 python3.4 python3.5 python3.6' \ OAI_SPEC_URL="https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json" +ARG SENDGRID-PYTHON_VERSION +ARG BRANCH_HTTP_CLIENT + # install testing versions of python, including old versions, from deadsnakes RUN set -x \ && apt-get update \ @@ -30,8 +33,8 @@ RUN python2.7 get-pip.py && \ # set up default sendgrid env WORKDIR /root/sources -RUN git clone https://github.com/sendgrid/sendgrid-python.git --branch && \ - git clone https://github.com/sendgrid/python-http-client.git --branch +RUN git clone https://github.com/sendgrid/sendgrid-python.git --branch $SENDGRID-PYTHON_VERSION && \ + git clone https://github.com/sendgrid/python-http-client.git --branch $HTTP-CLIENT_VERSION WORKDIR /root RUN ln -s /root/sources/sendgrid-python/sendgrid && \ ln -s /root/sources/python-http-client/python_http_client diff --git a/docker/Makefile b/docker/Makefile index 6ec47459d..1afc31189 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -1,11 +1,3 @@ -# import deploy config -deployfile=deploy.env -ifdef dpl -deployfile=$(dpl) -endif -include $(deployfile) -export $(shell sed 's/=.*//' $(deployfile)) - stop: docker-compose stop From af559cfbcc532048eba35468e9c494b9c05c8a1d Mon Sep 17 00:00:00 2001 From: heisendumb Date: Mon, 30 Oct 2017 00:44:00 -0200 Subject: [PATCH 16/82] edit USAGE.md --- docker/USAGE.md | 18 ++++++++++++++++++ docker/docker-compose.yml | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docker/USAGE.md b/docker/USAGE.md index cd543c402..3c6ff700f 100644 --- a/docker/USAGE.md +++ b/docker/USAGE.md @@ -70,6 +70,24 @@ $ docker run -it -v /path/to/cool-sendgrid-python:/mnt/sendgrid-python sendgrid/ Note that the paths you specify in `-v` must be absolute. +# Docker Compose + +## Using tag's for versions - DockerHub + +### Edit variable TAG on .env/env_sample file + +```sh-session +$ sed -ie 's/TAG=latest/TAG=choice_a_version/g' +``` +### Run service using tags + +```sh-session +$ cd /path/to/sendgrid-python/docker +$ docker-compose up -d +``` + +# Specifying specific versions + # Testing Testing is easy! Run the container, `cd sendgrid`, and run `tox`. diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index d35772fd2..ed78e91ec 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -20,5 +20,5 @@ services: container_name: sendgrid-dev env_file: .env volumes: - - ${PATH_TO_SENDGRID-PYTHON}:/mnt/sendgrid-python - - ${PATH_TO_HTTP-CLIENT}:/mnt/python-http-client + - ${PATH_TO_SENDGRID-PYTHON_DEV}:/mnt/sendgrid-python + - ${PATH_TO_HTTP-CLIENT_DEV}:/mnt/python-http-client From 3c2724c73b62fe2c86a707531794011d619b842b Mon Sep 17 00:00:00 2001 From: heisendumb Date: Mon, 30 Oct 2017 02:11:14 -0200 Subject: [PATCH 17/82] issue #444 done --- docker/Makefile | 2 +- docker/USAGE.md | 45 ++++++++- docker/docker-compose.yml | 29 ++++-- docker/env/python-dev/sendgrid-python | 1 + docker/examples/templates/templates.py | 130 +++++++++++++++++++++++++ docker/sendgrid.env | 8 ++ 6 files changed, 202 insertions(+), 13 deletions(-) create mode 160000 docker/env/python-dev/sendgrid-python create mode 100644 docker/examples/templates/templates.py create mode 100644 docker/sendgrid.env diff --git a/docker/Makefile b/docker/Makefile index 1afc31189..76ccb73af 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -17,4 +17,4 @@ build-build: docker-compose up --build -d up: rm clean build-build - echo "Sendgrid dev environment is alive :D" + echo "Sendgrid-python environment is alive :D" diff --git a/docker/USAGE.md b/docker/USAGE.md index 3c6ff700f..d869a77ce 100644 --- a/docker/USAGE.md +++ b/docker/USAGE.md @@ -72,7 +72,16 @@ Note that the paths you specify in `-v` must be absolute. # Docker Compose -## Using tag's for versions - DockerHub + +# Quickstart + +1. Install docker-compose on your machine. +2. Must copy sendgrid.env to .env file. +3. Edit .env file for yours versions and paths. +4. Must create env folder for clone yours repo. +5. Have fun! :D + +## Using tag's for versions - DockerHub: ### Edit variable TAG on .env/env_sample file @@ -83,10 +92,40 @@ $ sed -ie 's/TAG=latest/TAG=choice_a_version/g' ```sh-session $ cd /path/to/sendgrid-python/docker -$ docker-compose up -d +$ docker-compose up -d sendgrid +``` + +## Specifying specific versions: + +### Edit variable TAG on .env/env_sample file + +```sh-session +$ sed -ie 's/SENDGRID_PYTHON_VERSION=vy.x.z/SENDGRID_PYTHON_VERSION=vx.y.z/g' +$ sed -ie 's/HTTP_CLIENT_VERSION=vy.x.z/HTTP_CLIENT_VERSION=vx.y.z/g' ``` -# Specifying specific versions +### Run service + +```sh-session +$ cd /path/to/sendgrid-python/docker +$ docker-compose up -d sendgrid-dev +``` + +## Specifying your own fork: + +### Edit variable TAG on .env/env_sample file + +```sh-session +$ sed -ie 's/TAG=latest/TAG=choice_a_version/g' +$ sed -ie 's/SENDGRID_PYTHON_VERSION=vy.x.z/SENDGRID_PYTHON_VERSION=vx.y.z/g' +``` + +### Run service + +```sh-session +$ cd /path/to/sendgrid-python/docker +$ docker-compose up -d sendgrid-beta +``` # Testing diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index ed78e91ec..2a435b39f 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -5,20 +5,31 @@ services: image: sendgrid/sendgrid-python:${TAG} restart: unless-stopped container_name: sendgrid-prod - volumes: - - ${PATH_TO_SENDGRID-PYTHON_PROD}:/mnt/sendgrid-python - - ${PATH_TO_HTTP-CLIENT_PROD}:/mnt/python-http-client - env_file: .env + tty: true + env_file: + - .env sendgrid-dev: build: context: . args: - - SENDGRID-PYTHON_VERSION: {SENDGRID-PYTHON_VERSION} - - HTTP-CLIENT_VERSION: {HTTP-CLIENT_VERSION} + - SENDGRID-PYTHON_VERSION=${SENDGRID_PYTHON_VERSION} + - HTTP-CLIENT_VERSION=${HTTP_CLIENT_VERSION} restart: unless-stopped container_name: sendgrid-dev - env_file: .env + tty: true + env_file: + - .env volumes: - - ${PATH_TO_SENDGRID-PYTHON_DEV}:/mnt/sendgrid-python - - ${PATH_TO_HTTP-CLIENT_DEV}:/mnt/python-http-client + - ${PATH_TO_SENDGRID_PYTHON_DEV}:/mnt/sendgrid-python + - ${PATH_TO_HTTP_CLIENT_DEV}:/mnt/python-http-client + + sendgrid-beta: + image: sendgrid/sendgrid-python:${TAG} + restart: unless-stopped + container_name: sendgrid-beta + tty: true + env_file: + - .env + volumes: + - ${PATH_TO_SENDGRID_PYTHON_FORK}:/root/sources/sendgrid-python/sendgrid diff --git a/docker/env/python-dev/sendgrid-python b/docker/env/python-dev/sendgrid-python new file mode 160000 index 000000000..28cf42f6d --- /dev/null +++ b/docker/env/python-dev/sendgrid-python @@ -0,0 +1 @@ +Subproject commit 28cf42f6d590695de7e7ecdedcb67e9d8d4729ac diff --git a/docker/examples/templates/templates.py b/docker/examples/templates/templates.py new file mode 100644 index 000000000..9d3d5dd4b --- /dev/null +++ b/docker/examples/templates/templates.py @@ -0,0 +1,130 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Create a transactional template. # +# POST /templates # + +data = { + "name": "example_name" +} +response = sg.client.templates.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve all transactional templates. # +# GET /templates # + +response = sg.client.templates.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Edit a transactional template. # +# PATCH /templates/{template_id} # + +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) + +################################################## +# Retrieve a single transactional template. # +# GET /templates/{template_id} # + +template_id = "test_url_param" +response = sg.client.templates._(template_id).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete a template. # +# DELETE /templates/{template_id} # + +template_id = "test_url_param" +response = sg.client.templates._(template_id).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Create a new transactional template version. # +# 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" +} +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) + +################################################## +# Edit a transactional template version. # +# PATCH /templates/{template_id}/versions/{version_id} # + +data = { + "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) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Retrieve a specific transactional template version. # +# GET /templates/{template_id}/versions/{version_id} # + +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) + +################################################## +# Delete a transactional template version. # +# DELETE /templates/{template_id}/versions/{version_id} # + +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) + +################################################## +# Activate a transactional template version. # +# POST /templates/{template_id}/versions/{version_id}/activate # + +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) + diff --git a/docker/sendgrid.env b/docker/sendgrid.env new file mode 100644 index 000000000..ace58fafa --- /dev/null +++ b/docker/sendgrid.env @@ -0,0 +1,8 @@ +TAG=latest +SENDGRID_PYTHON_VERSION="v3.6.1" +HTTP_CLIENT_VERSION="v1.2.4" +PATH_TO_SENDGRID_PYTHON_DEV=../env/python-dev/sendgrid-python +PATH_TO_HTTP_CLIENT_DEV=../env/python-dev/python-http-client +PATH_TO_SENDGRID_PYTHON_PROD=../env/python-prod/sendgrid-python +PATH_TO_HTTP_CLIENT_PROD=../env/python-prod/python-http-client +PATH_TO_SENDGRID_PYTHON_FORK=../env/python-fork/sendgrid-python From 2a9b4040ba8ac41c7cf48f3e1e995d85f40d5256 Mon Sep 17 00:00:00 2001 From: d grossman Date: Fri, 3 Nov 2017 14:55:02 -0700 Subject: [PATCH 18/82] moved file, updated import --- {sendgrid/helpers/endpoints/ip => test}/test_unassigned.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename {sendgrid/helpers/endpoints/ip => test}/test_unassigned.py (96%) diff --git a/sendgrid/helpers/endpoints/ip/test_unassigned.py b/test/test_unassigned.py similarity index 96% rename from sendgrid/helpers/endpoints/ip/test_unassigned.py rename to test/test_unassigned.py index be5904018..d13451277 100644 --- a/sendgrid/helpers/endpoints/ip/test_unassigned.py +++ b/test/test_unassigned.py @@ -1,7 +1,8 @@ import json import pytest -from .unassigned import unassigned +from sendgrid.helpers.endpoints.ip.unassigned import unassigned + ret_json = '''[ { "ip": "167.89.21.3", From 955cac6889c6d7e113f48a3f6a9286cc215cb114 Mon Sep 17 00:00:00 2001 From: mbernier Date: Tue, 12 Dec 2017 08:20:58 -0700 Subject: [PATCH 19/82] removed extra examples dir --- .../examples/accesssettings/accesssettings.py | 84 ---- docker/examples/alerts/alerts.py | 63 --- docker/examples/apikeys/apikeys.py | 85 ---- docker/examples/asm/asm.py | 174 -------- docker/examples/browsers/browsers.py | 17 - docker/examples/campaigns/campaigns.py | 154 ------- docker/examples/categories/categories.py | 37 -- docker/examples/clients/clients.py | 28 -- docker/examples/contactdb/contactdb.py | 396 ------------------ docker/examples/devices/devices.py | 17 - docker/examples/geo/geo.py | 17 - docker/examples/helpers/mail/mail_example.py | 219 ---------- docker/examples/ips/ips.py | 155 ------- docker/examples/mail/mail.py | 174 -------- .../mailboxproviders/mailboxproviders.py | 17 - docker/examples/mailsettings/mailsettings.py | 220 ---------- .../partnersettings/partnersettings.py | 40 -- docker/examples/scopes/scopes.py | 16 - docker/examples/senders/senders.py | 99 ----- docker/examples/stats/stats.py | 17 - docker/examples/subusers/subusers.py | 170 -------- docker/examples/suppression/suppression.py | 202 --------- docker/examples/templates/templates.py | 130 ------ .../trackingsettings/trackingsettings.py | 111 ----- docker/examples/user/user.py | 294 ------------- docker/examples/whitelabel/whitelabel.py | 311 -------------- 26 files changed, 3247 deletions(-) delete mode 100644 docker/examples/accesssettings/accesssettings.py delete mode 100644 docker/examples/alerts/alerts.py delete mode 100644 docker/examples/apikeys/apikeys.py delete mode 100644 docker/examples/asm/asm.py delete mode 100644 docker/examples/browsers/browsers.py delete mode 100644 docker/examples/campaigns/campaigns.py delete mode 100644 docker/examples/categories/categories.py delete mode 100644 docker/examples/clients/clients.py delete mode 100644 docker/examples/contactdb/contactdb.py delete mode 100644 docker/examples/devices/devices.py delete mode 100644 docker/examples/geo/geo.py delete mode 100644 docker/examples/helpers/mail/mail_example.py delete mode 100644 docker/examples/ips/ips.py delete mode 100644 docker/examples/mail/mail.py delete mode 100644 docker/examples/mailboxproviders/mailboxproviders.py delete mode 100644 docker/examples/mailsettings/mailsettings.py delete mode 100644 docker/examples/partnersettings/partnersettings.py delete mode 100644 docker/examples/scopes/scopes.py delete mode 100644 docker/examples/senders/senders.py delete mode 100644 docker/examples/stats/stats.py delete mode 100644 docker/examples/subusers/subusers.py delete mode 100644 docker/examples/suppression/suppression.py delete mode 100644 docker/examples/templates/templates.py delete mode 100644 docker/examples/trackingsettings/trackingsettings.py delete mode 100644 docker/examples/user/user.py delete mode 100644 docker/examples/whitelabel/whitelabel.py diff --git a/docker/examples/accesssettings/accesssettings.py b/docker/examples/accesssettings/accesssettings.py deleted file mode 100644 index aac0e4a54..000000000 --- a/docker/examples/accesssettings/accesssettings.py +++ /dev/null @@ -1,84 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Retrieve all recent access attempts # -# GET /access_settings/activity # - -params = {'limit': 1} -response = sg.client.access_settings.activity.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Add one or more IPs to the whitelist # -# POST /access_settings/whitelist # - -data = { - "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) -print(response.body) -print(response.headers) - -################################################## -# Retrieve a list of currently whitelisted IPs # -# GET /access_settings/whitelist # - -response = sg.client.access_settings.whitelist.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Remove one or more IPs from the whitelist # -# DELETE /access_settings/whitelist # - -data = { - "ids": [ - 1, - 2, - 3 - ] -} -response = sg.client.access_settings.whitelist.delete(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve a specific whitelisted IP # -# GET /access_settings/whitelist/{rule_id} # - -rule_id = "test_url_param" -response = sg.client.access_settings.whitelist._(rule_id).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Remove a specific IP from the whitelist # -# DELETE /access_settings/whitelist/{rule_id} # - -rule_id = "test_url_param" -response = sg.client.access_settings.whitelist._(rule_id).delete() -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/alerts/alerts.py b/docker/examples/alerts/alerts.py deleted file mode 100644 index e30d48748..000000000 --- a/docker/examples/alerts/alerts.py +++ /dev/null @@ -1,63 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Create a new Alert # -# POST /alerts # - -data = { - "email_to": "example@example.com", - "frequency": "daily", - "type": "stats_notification" -} -response = sg.client.alerts.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all alerts # -# GET /alerts # - -response = sg.client.alerts.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update an alert # -# PATCH /alerts/{alert_id} # - -data = { - "email_to": "example@example.com" -} -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) - -################################################## -# Retrieve a specific alert # -# GET /alerts/{alert_id} # - -alert_id = "test_url_param" -response = sg.client.alerts._(alert_id).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete an alert # -# DELETE /alerts/{alert_id} # - -alert_id = "test_url_param" -response = sg.client.alerts._(alert_id).delete() -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/apikeys/apikeys.py b/docker/examples/apikeys/apikeys.py deleted file mode 100644 index 42c3afa10..000000000 --- a/docker/examples/apikeys/apikeys.py +++ /dev/null @@ -1,85 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=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" - ] -} -response = sg.client.api_keys.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all API Keys belonging to the authenticated user # -# GET /api_keys # - -params = {'limit': 1} -response = sg.client.api_keys.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update the name & scopes of an API Key # -# PUT /api_keys/{api_key_id} # - -data = { - "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) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update API keys # -# PATCH /api_keys/{api_key_id} # - -data = { - "name": "A New Hope" -} -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) - -################################################## -# Retrieve an existing API Key # -# GET /api_keys/{api_key_id} # - -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) - -################################################## -# Delete API keys # -# DELETE /api_keys/{api_key_id} # - -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) - diff --git a/docker/examples/asm/asm.py b/docker/examples/asm/asm.py deleted file mode 100644 index 43130cf06..000000000 --- a/docker/examples/asm/asm.py +++ /dev/null @@ -1,174 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=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" -} -response = sg.client.asm.groups.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve information about multiple suppression groups # -# GET /asm/groups # - -params = {'id': 1} -response = sg.client.asm.groups.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update a suppression group. # -# PATCH /asm/groups/{group_id} # - -data = { - "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) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Get information on a single suppression group. # -# GET /asm/groups/{group_id} # - -group_id = "test_url_param" -response = sg.client.asm.groups._(group_id).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete a suppression group. # -# DELETE /asm/groups/{group_id} # - -group_id = "test_url_param" -response = sg.client.asm.groups._(group_id).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Add suppressions to a suppression group # -# POST /asm/groups/{group_id}/suppressions # - -data = { - "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) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all suppressions for a suppression group # -# GET /asm/groups/{group_id}/suppressions # - -group_id = "test_url_param" -response = sg.client.asm.groups._(group_id).suppressions.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Search for suppressions within a group # -# POST /asm/groups/{group_id}/suppressions/search # - -data = { - "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) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete a suppression from a suppression group # -# DELETE /asm/groups/{group_id}/suppressions/{email} # - -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) - -################################################## -# Retrieve all suppressions # -# GET /asm/suppressions # - -response = sg.client.asm.suppressions.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Add recipient addresses to the global suppression group. # -# POST /asm/suppressions/global # - -data = { - "recipient_emails": [ - "test1@example.com", - "test2@example.com" - ] -} -response = sg.client.asm.suppressions._("global").post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve a Global Suppression # -# GET /asm/suppressions/global/{email} # - -email = "test_url_param" -response = sg.client.asm.suppressions._("global")._(email).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete a Global Suppression # -# DELETE /asm/suppressions/global/{email} # - -email = "test_url_param" -response = sg.client.asm.suppressions._("global")._(email).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all suppression groups for an email address # -# GET /asm/suppressions/{email} # - -email = "test_url_param" -response = sg.client.asm.suppressions._(email).get() -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/browsers/browsers.py b/docker/examples/browsers/browsers.py deleted file mode 100644 index c123c12e5..000000000 --- a/docker/examples/browsers/browsers.py +++ /dev/null @@ -1,17 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=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'} -response = sg.client.browsers.stats.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/campaigns/campaigns.py b/docker/examples/campaigns/campaigns.py deleted file mode 100644 index c77fc878b..000000000 --- a/docker/examples/campaigns/campaigns.py +++ /dev/null @@ -1,154 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=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" -} -response = sg.client.campaigns.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all Campaigns # -# GET /campaigns # - -params = {'limit': 1, 'offset': 1} -response = sg.client.campaigns.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update a Campaign # -# 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" -} -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) - -################################################## -# Retrieve a single campaign # -# GET /campaigns/{campaign_id} # - -campaign_id = "test_url_param" -response = sg.client.campaigns._(campaign_id).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete a Campaign # -# DELETE /campaigns/{campaign_id} # - -campaign_id = "test_url_param" -response = sg.client.campaigns._(campaign_id).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update a Scheduled Campaign # -# PATCH /campaigns/{campaign_id}/schedules # - -data = { - "send_at": 1489451436 -} -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) - -################################################## -# Schedule a Campaign # -# POST /campaigns/{campaign_id}/schedules # - -data = { - "send_at": 1489771528 -} -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) - -################################################## -# View Scheduled Time of a Campaign # -# GET /campaigns/{campaign_id}/schedules # - -campaign_id = "test_url_param" -response = sg.client.campaigns._(campaign_id).schedules.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Unschedule a Scheduled Campaign # -# DELETE /campaigns/{campaign_id}/schedules # - -campaign_id = "test_url_param" -response = sg.client.campaigns._(campaign_id).schedules.delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Send a Campaign # -# POST /campaigns/{campaign_id}/schedules/now # - -campaign_id = "test_url_param" -response = sg.client.campaigns._(campaign_id).schedules.now.post() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Send a Test Campaign # -# POST /campaigns/{campaign_id}/schedules/test # - -data = { - "to": "your.email@example.com" -} -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) - diff --git a/docker/examples/categories/categories.py b/docker/examples/categories/categories.py deleted file mode 100644 index 7984f0fe0..000000000 --- a/docker/examples/categories/categories.py +++ /dev/null @@ -1,37 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Retrieve all categories # -# GET /categories # - -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) - -################################################## -# 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'} -response = sg.client.categories.stats.get(query_params=params) -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?] # -# 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'} -response = sg.client.categories.stats.sums.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/clients/clients.py b/docker/examples/clients/clients.py deleted file mode 100644 index 7831ef78f..000000000 --- a/docker/examples/clients/clients.py +++ /dev/null @@ -1,28 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=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'} -response = sg.client.clients.stats.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# 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'} -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/docker/examples/contactdb/contactdb.py b/docker/examples/contactdb/contactdb.py deleted file mode 100644 index c234d7724..000000000 --- a/docker/examples/contactdb/contactdb.py +++ /dev/null @@ -1,396 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Create a Custom Field # -# POST /contactdb/custom_fields # - -data = { - "name": "pet", - "type": "text" -} -response = sg.client.contactdb.custom_fields.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all custom fields # -# GET /contactdb/custom_fields # - -response = sg.client.contactdb.custom_fields.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve a Custom Field # -# GET /contactdb/custom_fields/{custom_field_id} # - -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) - -################################################## -# Delete a Custom Field # -# DELETE /contactdb/custom_fields/{custom_field_id} # - -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) - -################################################## -# Create a List # -# POST /contactdb/lists # - -data = { - "name": "your list name" -} -response = sg.client.contactdb.lists.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all lists # -# GET /contactdb/lists # - -response = sg.client.contactdb.lists.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete Multiple lists # -# DELETE /contactdb/lists # - -data = [ - 1, - 2, - 3, - 4 -] -response = sg.client.contactdb.lists.delete(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update a List # -# PATCH /contactdb/lists/{list_id} # - -data = { - "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) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve a single list # -# GET /contactdb/lists/{list_id} # - -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) - -################################################## -# Delete a List # -# DELETE /contactdb/lists/{list_id} # - -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) - -################################################## -# Add Multiple Recipients to a List # -# POST /contactdb/lists/{list_id}/recipients # - -data = [ - "recipient_id1", - "recipient_id2" -] -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) - -################################################## -# Retrieve all recipients on a List # -# GET /contactdb/lists/{list_id}/recipients # - -params = {'page': 1, 'page_size': 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) - -################################################## -# Add a Single Recipient to a List # -# POST /contactdb/lists/{list_id}/recipients/{recipient_id} # - -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) - -################################################## -# Delete a Single Recipient from a Single List # -# DELETE /contactdb/lists/{list_id}/recipients/{recipient_id} # - -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) - -################################################## -# Update Recipient # -# PATCH /contactdb/recipients # - -data = [ - { - "email": "jones@example.com", - "first_name": "Guy", - "last_name": "Jones" - } -] -response = sg.client.contactdb.recipients.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Add recipients # -# 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" - } -] -response = sg.client.contactdb.recipients.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve recipients # -# GET /contactdb/recipients # - -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) - -################################################## -# Delete Recipient # -# DELETE /contactdb/recipients # - -data = [ - "recipient_id1", - "recipient_id2" -] -response = sg.client.contactdb.recipients.delete(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve the count of billable recipients # -# GET /contactdb/recipients/billable_count # - -response = sg.client.contactdb.recipients.billable_count.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve a Count of Recipients # -# GET /contactdb/recipients/count # - -response = sg.client.contactdb.recipients.count.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve recipients matching search criteria # -# GET /contactdb/recipients/search # - -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) - -################################################## -# Retrieve a single recipient # -# GET /contactdb/recipients/{recipient_id} # - -recipient_id = "test_url_param" -response = sg.client.contactdb.recipients._(recipient_id).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete a Recipient # -# DELETE /contactdb/recipients/{recipient_id} # - -recipient_id = "test_url_param" -response = sg.client.contactdb.recipients._(recipient_id).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve the lists that a recipient is on # -# GET /contactdb/recipients/{recipient_id}/lists # - -recipient_id = "test_url_param" -response = sg.client.contactdb.recipients._(recipient_id).lists.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve reserved fields # -# GET /contactdb/reserved_fields # - -response = sg.client.contactdb.reserved_fields.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Create a Segment # -# 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" -} -response = sg.client.contactdb.segments.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all segments # -# GET /contactdb/segments # - -response = sg.client.contactdb.segments.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update a segment # -# PATCH /contactdb/segments/{segment_id} # - -data = { - "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) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve a segment # -# GET /contactdb/segments/{segment_id} # - -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) - -################################################## -# Delete a segment # -# DELETE /contactdb/segments/{segment_id} # - -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) - -################################################## -# Retrieve recipients on a segment # -# GET /contactdb/segments/{segment_id}/recipients # - -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) - diff --git a/docker/examples/devices/devices.py b/docker/examples/devices/devices.py deleted file mode 100644 index 108e98452..000000000 --- a/docker/examples/devices/devices.py +++ /dev/null @@ -1,17 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=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} -response = sg.client.devices.stats.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/geo/geo.py b/docker/examples/geo/geo.py deleted file mode 100644 index 7d58ec085..000000000 --- a/docker/examples/geo/geo.py +++ /dev/null @@ -1,17 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=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'} -response = sg.client.geo.stats.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/helpers/mail/mail_example.py b/docker/examples/helpers/mail/mail_example.py deleted file mode 100644 index bfd8ea718..000000000 --- a/docker/examples/helpers/mail/mail_example.py +++ /dev/null @@ -1,219 +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_personalization(personalization): - """Build personalization mock instance from a mock dict""" - mock_personalization = Personalization() - for to_addr in personalization['to_list']: - personalization.add_to(to_addr) - - for cc_addr in personalization['cc_list']: - personalization.add_to(cc_addr) - - for bcc_addr in personalization['bcc_list']: - personalization.add_bc(bcc_addr) - - for header in personalization['headers']: - personalization.add_header(header) - - for substitution in personalization['substitutions']: - personalization.add_substitution(substitution) - - for arg in personalization['custom_args']: - personalization.add_custom_arg(arg) - - personalization.subject = personalization['subject'] - personalization.send_at = personalization['send_at'] - return mock_personalization - - -def get_mock_personalization_dict(): - """Get a dict of personalization mock.""" - mock_pers = dict() - - mock_pers['to_list'] = [Email("test1@example.com", - "Example User"), - Email("test2@example.com", - "Example User")] - - mock_pers['cc_list'] = [Email("test3@example.com", - "Example User"), - Email("test4@example.com", - "Example User")] - - mock_pers['bcc_list'] = [Email("test5@example.com"), - Email("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_attachment1(): - """Build attachment mock.""" - attachment = Attachment() - attachment.content = ("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNl" - "Y3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12") - attachment.type = "application/pdf" - attachment.filename = "balance_001.pdf" - attachment.disposition = "attachment" - attachment.content_id = "Balance Sheet" - return attachment - - -def build_attachment2(): - """Build attachment mock.""" - attachment = Attachment() - attachment.content = "BwdW" - attachment.type = "image/png" - attachment.filename = "banner.png" - attachment.disposition = "inline" - attachment.content_id = "Banner" - return attachment - - -def build_mail_settings(): - """Build mail settings mock.""" - 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") - return mail_settings - - -def build_tracking_settings(): - """Build tracking settings mock.""" - 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")) - - subs_track = 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.subscription_tracking = subs_track - tracking_settings.ganalytics = Ganalytics(True, "some source", - "some medium", "some term", - "some_content", "some_campaign") - return tracking_settings - - -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 = get_mock_personalization_dict() - mail.add_personalization(build_personalization(personalization)) - mail.add_personalization(build_personalization(personalization)) - - mail.add_content(Content("text/plain", "some text here")) - mail.add_content(Content("text/html", ("some text " - "here"))) - - mail.add_attachment(build_attachment1()) - mail.add_attachment(build_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.mail_settings = build_mail_settings() - mail.tracking_settings = build_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) - - -# this will actually send an email -send_hello_email() - -# this will only send an email if you set SandBox Mode to False -send_kitchen_sink() diff --git a/docker/examples/ips/ips.py b/docker/examples/ips/ips.py deleted file mode 100644 index 6c48ae306..000000000 --- a/docker/examples/ips/ips.py +++ /dev/null @@ -1,155 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=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} -response = sg.client.ips.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all assigned IPs # -# GET /ips/assigned # - -response = sg.client.ips.assigned.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Create an IP pool. # -# POST /ips/pools # - -data = { - "name": "marketing" -} -response = sg.client.ips.pools.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all IP pools. # -# GET /ips/pools # - -response = sg.client.ips.pools.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update an IP pools name. # -# PUT /ips/pools/{pool_name} # - -data = { - "name": "new_pool_name" -} -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) - -################################################## -# Retrieve all IPs in a specified pool. # -# GET /ips/pools/{pool_name} # - -pool_name = "test_url_param" -response = sg.client.ips.pools._(pool_name).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete an IP pool. # -# DELETE /ips/pools/{pool_name} # - -pool_name = "test_url_param" -response = sg.client.ips.pools._(pool_name).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Add an IP address to a pool # -# POST /ips/pools/{pool_name}/ips # - -data = { - "ip": "0.0.0.0" -} -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) - -################################################## -# Remove an IP address from a pool. # -# DELETE /ips/pools/{pool_name}/ips/{ip} # - -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) - -################################################## -# Add an IP to warmup # -# POST /ips/warmup # - -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) - -################################################## -# Retrieve all IPs currently in warmup # -# GET /ips/warmup # - -response = sg.client.ips.warmup.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve warmup status for a specific IP address # -# GET /ips/warmup/{ip_address} # - -ip_address = "test_url_param" -response = sg.client.ips.warmup._(ip_address).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Remove an IP from warmup # -# DELETE /ips/warmup/{ip_address} # - -ip_address = "test_url_param" -response = sg.client.ips.warmup._(ip_address).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all IP pools an IP address belongs to # -# GET /ips/{ip_address} # - -ip_address = "test_url_param" -response = sg.client.ips._(ip_address).get() -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/mail/mail.py b/docker/examples/mail/mail.py deleted file mode 100644 index fef420e87..000000000 --- a/docker/examples/mail/mail.py +++ /dev/null @@ -1,174 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Create a batch ID # -# POST /mail/batch # - -response = sg.client.mail.batch.post() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Validate batch ID # -# GET /mail/batch/{batch_id} # - -batch_id = "test_url_param" -response = sg.client.mail.batch._(batch_id).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# 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). - -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": "

Thanks
The 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": [ - { - "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 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/docker/examples/mailboxproviders/mailboxproviders.py b/docker/examples/mailboxproviders/mailboxproviders.py deleted file mode 100644 index 1b75ecac5..000000000 --- a/docker/examples/mailboxproviders/mailboxproviders.py +++ /dev/null @@ -1,17 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=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'} -response = sg.client.mailbox_providers.stats.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/mailsettings/mailsettings.py b/docker/examples/mailsettings/mailsettings.py deleted file mode 100644 index 18c57b960..000000000 --- a/docker/examples/mailsettings/mailsettings.py +++ /dev/null @@ -1,220 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Retrieve all mail settings # -# GET /mail_settings # - -params = {'limit': 1, 'offset': 1} -response = sg.client.mail_settings.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update address whitelist mail settings # -# PATCH /mail_settings/address_whitelist # - -data = { - "enabled": True, - "list": [ - "email1@example.com", - "example.com" - ] -} -response = sg.client.mail_settings.address_whitelist.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve address whitelist mail settings # -# GET /mail_settings/address_whitelist # - -response = sg.client.mail_settings.address_whitelist.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update BCC mail settings # -# PATCH /mail_settings/bcc # - -data = { - "email": "email@example.com", - "enabled": False -} -response = sg.client.mail_settings.bcc.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all BCC mail settings # -# GET /mail_settings/bcc # - -response = sg.client.mail_settings.bcc.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update bounce purge mail settings # -# PATCH /mail_settings/bounce_purge # - -data = { - "enabled": True, - "hard_bounces": 5, - "soft_bounces": 5 -} -response = sg.client.mail_settings.bounce_purge.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve bounce purge mail settings # -# GET /mail_settings/bounce_purge # - -response = sg.client.mail_settings.bounce_purge.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update footer mail settings # -# PATCH /mail_settings/footer # - -data = { - "enabled": True, - "html_content": "...", - "plain_content": "..." -} -response = sg.client.mail_settings.footer.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve footer mail settings # -# GET /mail_settings/footer # - -response = sg.client.mail_settings.footer.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update forward bounce mail settings # -# PATCH /mail_settings/forward_bounce # - -data = { - "email": "example@example.com", - "enabled": True -} -response = sg.client.mail_settings.forward_bounce.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve forward bounce mail settings # -# GET /mail_settings/forward_bounce # - -response = sg.client.mail_settings.forward_bounce.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update forward spam mail settings # -# PATCH /mail_settings/forward_spam # - -data = { - "email": "", - "enabled": False -} -response = sg.client.mail_settings.forward_spam.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve forward spam mail settings # -# GET /mail_settings/forward_spam # - -response = sg.client.mail_settings.forward_spam.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update plain content mail settings # -# PATCH /mail_settings/plain_content # - -data = { - "enabled": False -} -response = sg.client.mail_settings.plain_content.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve plain content mail settings # -# GET /mail_settings/plain_content # - -response = sg.client.mail_settings.plain_content.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update spam check mail settings # -# PATCH /mail_settings/spam_check # - -data = { - "enabled": True, - "max_score": 5, - "url": "url" -} -response = sg.client.mail_settings.spam_check.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve spam check mail settings # -# GET /mail_settings/spam_check # - -response = sg.client.mail_settings.spam_check.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update template mail settings # -# PATCH /mail_settings/template # - -data = { - "enabled": True, - "html_content": "<% body %>" -} -response = sg.client.mail_settings.template.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve legacy template mail settings # -# GET /mail_settings/template # - -response = sg.client.mail_settings.template.get() -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/partnersettings/partnersettings.py b/docker/examples/partnersettings/partnersettings.py deleted file mode 100644 index 37f77f4e6..000000000 --- a/docker/examples/partnersettings/partnersettings.py +++ /dev/null @@ -1,40 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Returns a list of all partner settings. # -# GET /partner_settings # - -params = {'limit': 1, 'offset': 1} -response = sg.client.partner_settings.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Updates New Relic partner settings. # -# PATCH /partner_settings/new_relic # - -data = { - "enable_subuser_statistics": True, - "enabled": True, - "license_key": "" -} -response = sg.client.partner_settings.new_relic.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Returns all New Relic partner settings. # -# GET /partner_settings/new_relic # - -response = sg.client.partner_settings.new_relic.get() -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/scopes/scopes.py b/docker/examples/scopes/scopes.py deleted file mode 100644 index 124f77d39..000000000 --- a/docker/examples/scopes/scopes.py +++ /dev/null @@ -1,16 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Retrieve a list of scopes for which this user has access. # -# GET /scopes # - -response = sg.client.scopes.get() -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/senders/senders.py b/docker/examples/senders/senders.py deleted file mode 100644 index f21459b71..000000000 --- a/docker/examples/senders/senders.py +++ /dev/null @@ -1,99 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=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" -} -response = sg.client.senders.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Get all Sender Identities # -# GET /senders # - -response = sg.client.senders.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update a Sender Identity # -# 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" -} -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) - -################################################## -# View a Sender Identity # -# GET /senders/{sender_id} # - -sender_id = "test_url_param" -response = sg.client.senders._(sender_id).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete a Sender Identity # -# DELETE /senders/{sender_id} # - -sender_id = "test_url_param" -response = sg.client.senders._(sender_id).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Resend Sender Identity Verification # -# POST /senders/{sender_id}/resend_verification # - -sender_id = "test_url_param" -response = sg.client.senders._(sender_id).resend_verification.post() -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/stats/stats.py b/docker/examples/stats/stats.py deleted file mode 100644 index a7bf3362e..000000000 --- a/docker/examples/stats/stats.py +++ /dev/null @@ -1,17 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=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} -response = sg.client.stats.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/subusers/subusers.py b/docker/examples/subusers/subusers.py deleted file mode 100644 index 6aa91e535..000000000 --- a/docker/examples/subusers/subusers.py +++ /dev/null @@ -1,170 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=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" -} -response = sg.client.subusers.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# List all Subusers # -# GET /subusers # - -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 # -# GET /subusers/reputations # - -params = {'usernames': 'test_string'} -response = sg.client.subusers.reputations.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# 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'} -response = sg.client.subusers.stats.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# 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'} -response = sg.client.subusers.stats.monthly.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# 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'} -response = sg.client.subusers.stats.sums.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Enable/disable a subuser # -# PATCH /subusers/{subuser_name} # - -data = { - "disabled": 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) - -################################################## -# Delete a subuser # -# DELETE /subusers/{subuser_name} # - -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update IPs assigned to a subuser # -# PUT /subusers/{subuser_name}/ips # - -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) - -################################################## -# Update Monitor Settings for a subuser # -# PUT /subusers/{subuser_name}/monitor # - -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 # -# POST /subusers/{subuser_name}/monitor # - -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) - -################################################## -# Retrieve monitor settings for a subuser # -# GET /subusers/{subuser_name}/monitor # - -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 # -# DELETE /subusers/{subuser_name}/monitor # - -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).monitor.delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# 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} -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) - diff --git a/docker/examples/suppression/suppression.py b/docker/examples/suppression/suppression.py deleted file mode 100644 index abdaef76d..000000000 --- a/docker/examples/suppression/suppression.py +++ /dev/null @@ -1,202 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Retrieve all blocks # -# GET /suppression/blocks # - -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) - -################################################## -# Delete blocks # -# DELETE /suppression/blocks # - -data = { - "delete_all": False, - "emails": [ - "example1@example.com", - "example2@example.com" - ] -} -response = sg.client.suppression.blocks.delete(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve a specific block # -# GET /suppression/blocks/{email} # - -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 # -# DELETE /suppression/blocks/{email} # - -email = "test_url_param" -response = sg.client.suppression.blocks._(email).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all bounces # -# GET /suppression/bounces # - -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 # -# DELETE /suppression/bounces # - -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) - -################################################## -# Retrieve a Bounce # -# GET /suppression/bounces/{email} # - -email = "test_url_param" -response = sg.client.suppression.bounces._(email).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete a bounce # -# DELETE /suppression/bounces/{email} # - -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 all invalid emails # -# GET /suppression/invalid_emails # - -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) - -################################################## -# Delete invalid emails # -# DELETE /suppression/invalid_emails # - -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 a specific invalid email # -# GET /suppression/invalid_emails/{email} # - -email = "test_url_param" -response = sg.client.suppression.invalid_emails._(email).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete a specific invalid email # -# DELETE /suppression/invalid_emails/{email} # - -email = "test_url_param" -response = sg.client.suppression.invalid_emails._(email).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve a specific spam report # -# GET /suppression/spam_report/{email} # - -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 # -# DELETE /suppression/spam_report/{email} # - -email = "test_url_param" -response = sg.client.suppression.spam_report._(email).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all spam reports # -# GET /suppression/spam_reports # - -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) - -################################################## -# Delete spam reports # -# DELETE /suppression/spam_reports # - -data = { - "delete_all": False, - "emails": [ - "example1@example.com", - "example2@example.com" - ] -} -response = sg.client.suppression.spam_reports.delete(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all global suppressions # -# GET /suppression/unsubscribes # - -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) - diff --git a/docker/examples/templates/templates.py b/docker/examples/templates/templates.py deleted file mode 100644 index 9d3d5dd4b..000000000 --- a/docker/examples/templates/templates.py +++ /dev/null @@ -1,130 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Create a transactional template. # -# POST /templates # - -data = { - "name": "example_name" -} -response = sg.client.templates.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all transactional templates. # -# GET /templates # - -response = sg.client.templates.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Edit a transactional template. # -# PATCH /templates/{template_id} # - -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) - -################################################## -# Retrieve a single transactional template. # -# GET /templates/{template_id} # - -template_id = "test_url_param" -response = sg.client.templates._(template_id).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete a template. # -# DELETE /templates/{template_id} # - -template_id = "test_url_param" -response = sg.client.templates._(template_id).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Create a new transactional template version. # -# 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" -} -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) - -################################################## -# Edit a transactional template version. # -# PATCH /templates/{template_id}/versions/{version_id} # - -data = { - "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) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve a specific transactional template version. # -# GET /templates/{template_id}/versions/{version_id} # - -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) - -################################################## -# Delete a transactional template version. # -# DELETE /templates/{template_id}/versions/{version_id} # - -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) - -################################################## -# Activate a transactional template version. # -# POST /templates/{template_id}/versions/{version_id}/activate # - -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) - diff --git a/docker/examples/trackingsettings/trackingsettings.py b/docker/examples/trackingsettings/trackingsettings.py deleted file mode 100644 index 80dbe243a..000000000 --- a/docker/examples/trackingsettings/trackingsettings.py +++ /dev/null @@ -1,111 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Retrieve Tracking Settings # -# GET /tracking_settings # - -params = {'limit': 1, 'offset': 1} -response = sg.client.tracking_settings.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update Click Tracking Settings # -# PATCH /tracking_settings/click # - -data = { - "enabled": True -} -response = sg.client.tracking_settings.click.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve Click Track Settings # -# GET /tracking_settings/click # - -response = sg.client.tracking_settings.click.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update Google Analytics Settings # -# PATCH /tracking_settings/google_analytics # - -data = { - "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) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve Google Analytics Settings # -# GET /tracking_settings/google_analytics # - -response = sg.client.tracking_settings.google_analytics.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update Open Tracking Settings # -# PATCH /tracking_settings/open # - -data = { - "enabled": True -} -response = sg.client.tracking_settings.open.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Get Open Tracking Settings # -# GET /tracking_settings/open # - -response = sg.client.tracking_settings.open.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update Subscription Tracking Settings # -# PATCH /tracking_settings/subscription # - -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) - -################################################## -# Retrieve Subscription Tracking Settings # -# GET /tracking_settings/subscription # - -response = sg.client.tracking_settings.subscription.get() -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/user/user.py b/docker/examples/user/user.py deleted file mode 100644 index 9e3f24766..000000000 --- a/docker/examples/user/user.py +++ /dev/null @@ -1,294 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Get a user's account information. # -# GET /user/account # - -response = sg.client.user.account.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve your credit balance # -# GET /user/credits # - -response = sg.client.user.credits.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update your account email address # -# PUT /user/email # - -data = { - "email": "example@example.com" -} -response = sg.client.user.email.put(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve your account email address # -# GET /user/email # - -response = sg.client.user.email.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update your password # -# PUT /user/password # - -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) - -################################################## -# Update a user's profile # -# PATCH /user/profile # - -data = { - "city": "Orange", - "first_name": "Example", - "last_name": "User" -} -response = sg.client.user.profile.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Get a user's profile # -# GET /user/profile # - -response = sg.client.user.profile.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Cancel or pause a scheduled send # -# POST /user/scheduled_sends # - -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) - -################################################## -# Retrieve all scheduled sends # -# GET /user/scheduled_sends # - -response = sg.client.user.scheduled_sends.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update user scheduled send information # -# PATCH /user/scheduled_sends/{batch_id} # - -data = { - "status": "pause" -} -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 scheduled send # -# GET /user/scheduled_sends/{batch_id} # - -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 # -# DELETE /user/scheduled_sends/{batch_id} # - -batch_id = "test_url_param" -response = sg.client.user.scheduled_sends._(batch_id).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update Enforced TLS settings # -# PATCH /user/settings/enforced_tls # - -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) - -################################################## -# Retrieve current Enforced TLS settings. # -# GET /user/settings/enforced_tls # - -response = sg.client.user.settings.enforced_tls.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update your username # -# PUT /user/username # - -data = { - "username": "test_username" -} -response = sg.client.user.username.put(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve your username # -# GET /user/username # - -response = sg.client.user.username.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update Event Notification Settings # -# 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" -} -response = sg.client.user.webhooks.event.settings.patch(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve Event Webhook settings # -# GET /user/webhooks/event/settings # - -response = sg.client.user.webhooks.event.settings.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Test Event Notification Settings # -# POST /user/webhooks/event/test # - -data = { - "url": "url" -} -response = sg.client.user.webhooks.event.test.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Create a parse setting # -# POST /user/webhooks/parse/settings # - -data = { - "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) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all parse settings # -# GET /user/webhooks/parse/settings # - -response = sg.client.user.webhooks.parse.settings.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update a parse setting # -# PATCH /user/webhooks/parse/settings/{hostname} # - -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) - -################################################## -# Retrieve a specific parse setting # -# GET /user/webhooks/parse/settings/{hostname} # - -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 # -# DELETE /user/webhooks/parse/settings/{hostname} # - -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. # -# 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'} -response = sg.client.user.webhooks.parse.stats.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - diff --git a/docker/examples/whitelabel/whitelabel.py b/docker/examples/whitelabel/whitelabel.py deleted file mode 100644 index f529d3ed2..000000000 --- a/docker/examples/whitelabel/whitelabel.py +++ /dev/null @@ -1,311 +0,0 @@ -import sendgrid -import json -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) - -################################################## -# Create a domain whitelabel. # -# 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" -} -response = sg.client.whitelabel.domains.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# List all domain whitelabels. # -# GET /whitelabel/domains # - -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 /whitelabel/domains/default # - -response = sg.client.whitelabel.domains.default.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# List the domain whitelabel associated with the given user. # -# GET /whitelabel/domains/subuser # - -response = sg.client.whitelabel.domains.subuser.get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Disassociate a domain whitelabel from a given user. # -# DELETE /whitelabel/domains/subuser # - -response = sg.client.whitelabel.domains.subuser.delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update a domain whitelabel. # -# PATCH /whitelabel/domains/{domain_id} # - -data = { - "custom_spf": True, - "default": False -} -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) - -################################################## -# Retrieve a domain whitelabel. # -# GET /whitelabel/domains/{domain_id} # - -domain_id = "test_url_param" -response = sg.client.whitelabel.domains._(domain_id).get() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Delete a domain whitelabel. # -# DELETE /whitelabel/domains/{domain_id} # - -domain_id = "test_url_param" -response = sg.client.whitelabel.domains._(domain_id).delete() -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Associate a domain whitelabel with a given user. # -# POST /whitelabel/domains/{domain_id}/subuser # - -data = { - "username": "jane@example.com" -} -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) - -################################################## -# Add an IP to a domain whitelabel. # -# POST /whitelabel/domains/{id}/ips # - -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) - -################################################## -# Remove an IP from a domain whitelabel. # -# DELETE /whitelabel/domains/{id}/ips/{ip} # - -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) - -################################################## -# Validate a domain whitelabel. # -# POST /whitelabel/domains/{id}/validate # - -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 # -# POST /whitelabel/ips # - -data = { - "domain": "example.com", - "ip": "192.168.1.1", - "subdomain": "email" -} -response = sg.client.whitelabel.ips.post(request_body=data) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve all IP whitelabels # -# GET /whitelabel/ips # - -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) - -################################################## -# Retrieve an IP whitelabel # -# GET /whitelabel/ips/{id} # - -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 /whitelabel/ips/{id} # - -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 # -# POST /whitelabel/ips/{id}/validate # - -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 # -# POST /whitelabel/links # - -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) - -################################################## -# Retrieve all link whitelabels # -# GET /whitelabel/links # - -params = {'limit': 1} -response = sg.client.whitelabel.links.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve a Default Link Whitelabel # -# GET /whitelabel/links/default # - -params = {'domain': 'test_string'} -response = sg.client.whitelabel.links.default.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Retrieve Associated Link Whitelabel # -# GET /whitelabel/links/subuser # - -params = {'username': 'test_string'} -response = sg.client.whitelabel.links.subuser.get(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Disassociate a Link Whitelabel # -# DELETE /whitelabel/links/subuser # - -params = {'username': 'test_string'} -response = sg.client.whitelabel.links.subuser.delete(query_params=params) -print(response.status_code) -print(response.body) -print(response.headers) - -################################################## -# Update a Link Whitelabel # -# PATCH /whitelabel/links/{id} # - -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 Link Whitelabel # -# GET /whitelabel/links/{id} # - -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 /whitelabel/links/{id} # - -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 # -# POST /whitelabel/links/{id}/validate # - -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 # -# POST /whitelabel/links/{link_id}/subuser # - -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) - From 7bde27aed7845908bb2b6a799aa366d4f0c64a32 Mon Sep 17 00:00:00 2001 From: mbernier Date: Thu, 21 Dec 2017 14:14:38 -0700 Subject: [PATCH 20/82] fixed tests for docker files --- test/test_project.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_project.py b/test/test_project.py index 861f1ffe0..e5f05de36 100644 --- a/test/test_project.py +++ b/test/test_project.py @@ -13,11 +13,11 @@ def test_docker_dir(self): # ./docker-compose.yml or ./docker/docker-compose.yml def test_docker_compose(self): - self.assertTrue(os.path.isfile('docker-compose.yml')) + self.assertTrue(os.path.isfile('./docker/docker-compose.yml')) # ./.env_sample def test_env(self): - self.assertTrue(os.path.isfile('./env_sample')) + self.assertTrue(os.path.isfile('./.env_sample')) # ./.gitignore def test_gitignore(self): From 7ccbf5d4097878c77bf6a9f8731e9bc3c7bd3488 Mon Sep 17 00:00:00 2001 From: Bhargav Chandaka Date: Sun, 8 Jul 2018 18:57:21 -0500 Subject: [PATCH 21/82] Update Readme Added windows environment variable setup --- README.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dbcebafdc..0b6a3b483 100644 --- a/README.md +++ b/README.md @@ -46,19 +46,26 @@ We appreciate your continued support, thank you! - The SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-python) ## Setup Environment Variables - Update the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example: - +### Mac ```bash echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env echo "sendgrid.env" >> .gitignore source ./sendgrid.env ``` - Sendgrid also supports local environment file `.env`. Copy or rename `.env_sample` into `.env` and update [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys) with your key. -## Install Package +### Windows +Temporarily set the environment variable(accesible only during the current cli session): +```bash +set SENDGRID_API_KEY=YOUR_API_KEY +``` +Permanently set the environment variable: +```bash +setx SENDGRID_API_KEY "YOUR_API_KEY" +``` +## Install Package ```bash pip install sendgrid ``` From 2da51c238fd6ecc1caaa343cf061437ff8bb2a2a Mon Sep 17 00:00:00 2001 From: Bhargav Chandaka Date: Sun, 8 Jul 2018 18:59:56 -0500 Subject: [PATCH 22/82] Update README.md Added environmental variable setup in windows --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0b6a3b483..f34a46235 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Temporarily set the environment variable(accesible only during the current cli s ```bash set SENDGRID_API_KEY=YOUR_API_KEY ``` -Permanently set the environment variable: +Permanently set the environment variable(accessible in all subsequent cli sessions): ```bash setx SENDGRID_API_KEY "YOUR_API_KEY" ``` From 6d5e9908cd074dbcb9dd6ac24df8de25245e318d Mon Sep 17 00:00:00 2001 From: Swapnil Agarwal Date: Fri, 27 Oct 2017 00:42:03 +0530 Subject: [PATCH 23/82] Add a tutorial to deploy a simple 'Hello Email' app on Heroku See #356 --- use_cases/README.md | 1 + use_cases/flask_heroku.md | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 use_cases/flask_heroku.md diff --git a/use_cases/README.md b/use_cases/README.md index 188464d09..4e0fc24d6 100644 --- a/use_cases/README.md +++ b/use_cases/README.md @@ -8,6 +8,7 @@ This directory provides examples for specific use cases of this library. Please * [How to Create a Django app, Deployed on Heroku, to Send Email with SendGrid](django.md) * [How to Deploy A Simple Hello Email App on AWS](aws.md) +* [How to Deploy a simple Flask app, to send Email with SendGrid, on Heroku](flask_heroku.md) * [How to Setup a Domain Whitelabel](domain_whitelabel.md) * [How to View Email Statistics](email_stats.md) diff --git a/use_cases/flask_heroku.md b/use_cases/flask_heroku.md new file mode 100644 index 000000000..ef0fa599a --- /dev/null +++ b/use_cases/flask_heroku.md @@ -0,0 +1,9 @@ +# Create a Flask app to send email with SendGrid + +This tutorial explains how to deploy a simple Flask app, to send an email using the SendGrid Python SDK, on Heroku. + +1. Create a SendGrid API key at https://app.sendgrid.com/settings/api_keys +1. Go to https://github.com/swapagarwal/sendgrid-flask-heroku +1. Click on `Deploy to Heroku` button, and follow the instructions. + +That's all. You'll be sending your first email within seconds! From b00219775f23d7d934e0bc6787482aa7d7e74679 Mon Sep 17 00:00:00 2001 From: Slam <3lnc.slam@gmail.com> Date: Wed, 1 Aug 2018 20:16:35 +0300 Subject: [PATCH 24/82] Adds support for dynamic template data in personalizations --- examples/helpers/{mail => }/mail_example.py | 26 +++++++++++++++++---- sendgrid/helpers/mail/personalization.py | 9 +++++++ test/test_mail.py | 14 +++++++++-- 3 files changed, 43 insertions(+), 6 deletions(-) rename examples/helpers/{mail => }/mail_example.py (91%) diff --git a/examples/helpers/mail/mail_example.py b/examples/helpers/mail_example.py similarity index 91% rename from examples/helpers/mail/mail_example.py rename to examples/helpers/mail_example.py index b2de7f0a0..e227b22cc 100644 --- a/examples/helpers/mail/mail_example.py +++ b/examples/helpers/mail_example.py @@ -1,8 +1,6 @@ -import json -import os -import urllib2 +from sendgrid import SendGridAPIClient 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. @@ -217,3 +215,23 @@ def send_kitchen_sink(): # this will only send an email if you set SandBox Mode to False send_kitchen_sink() + + +def dynamic_template_usage(): + """ + Sample usage of dynamic (handlebars) transactional templates. + To make this work, you should have dynamic template created within your + SendGrid account. For this particular example, template may be like:: + +

Hello, {{name}}! Your current balance is {{balance}}

+ + """ + mail = Mail(from_email='templates@sendgrid.com') + mail.template_id = 'd-your-dynamic-template-uid' + p = Personalization() + p.add_to(Email('user@example.com')) + p.dynamic_template_data = {'name': 'Bob', 'balance': 42} + mail.add_personalization(p) + + sg = SendGridAPIClient(apikey='SG.your-api-key') + sg.client.mail.send.post(request_body=mail.get()) diff --git a/sendgrid/helpers/mail/personalization.py b/sendgrid/helpers/mail/personalization.py index 8bb4bed0b..8032af958 100644 --- a/sendgrid/helpers/mail/personalization.py +++ b/sendgrid/helpers/mail/personalization.py @@ -1,6 +1,10 @@ class Personalization(object): """A Personalization defines who should receive an individual message and how that message should be handled. + + :var dynamic_template_data: data for dynamic transactional template. + Should be JSON-serializeable structure. No pre-processing sill be done + prior to sending this via http client. """ def __init__(self): @@ -13,6 +17,7 @@ def __init__(self): self._substitutions = [] self._custom_args = [] self._send_at = None + self.dynamic_template_data = None @property def tos(self): @@ -198,4 +203,8 @@ def get(self): if self.send_at is not None: personalization["send_at"] = self.send_at + + if self.dynamic_template_data is not None: + personalization['dynamic_template_data'] = self.dynamic_template_data + return personalization diff --git a/test/test_mail.py b/test/test_mail.py index 7721b5205..fb46d34c2 100644 --- a/test/test_mail.py +++ b/test/test_mail.py @@ -80,7 +80,6 @@ def test_sendgridAPIKey(self): else: self.fail("Should have failed as SendGrid API key included") - def test_helloEmail(self): self.max_diff = None @@ -130,7 +129,7 @@ def test_helloEmailAdditionalContent(self): personalization = Personalization() personalization.add_to(Email("test@example.com")) mail.add_personalization(personalization) - + mail.add_content(Content("text/html", "some text here")) mail.add_content(Content("text/plain", "some text here")) @@ -562,3 +561,14 @@ def test_disable_tracking(self): def test_directly_setting_substitutions(self): personalization = Personalization() personalization.substitutions = [{'a': 0}] + + def test_dynamic_template_data(self): + p = Personalization() + p.add_to(Email('test@sendgrid.com')) + p.dynamic_template_data = {'customer': {'name': 'Bob', 'returning': True}, 'total': 42} + + expected = { + 'to': [{'email': 'test@sendgrid.com'}], + 'dynamic_template_data': {'customer': {'name': 'Bob', 'returning': True}, 'total': 42} + } + self.assertDictEqual(p.get(), expected) From 210a4fa63a10ad88a2b09ae716344155a180d73a Mon Sep 17 00:00:00 2001 From: Slam <3lnc.slam@gmail.com> Date: Wed, 1 Aug 2018 20:30:30 +0300 Subject: [PATCH 25/82] Example for .md usecase --- use_cases/transational_templates.md | 32 ++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/use_cases/transational_templates.md b/use_cases/transational_templates.md index d3e3a005d..1e89e08a9 100644 --- a/use_cases/transational_templates.md +++ b/use_cases/transational_templates.md @@ -66,6 +66,36 @@ print(response.body) print(response.headers) ``` +### With dynamic templates + +Sendgrid dynamic templates let you leverage power of [handlebars](https://handlebarsjs.com/) +syntax to easily manage complex dynamic content in transactional emails. + +To check this example snippet, create transactional email with code like +```html +

Hello, {{name}}! Your current balance is {{balance}}

+``` + +Than send email based on it, providing context for substitutions: +```python +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import Email, Personalization + + +sg = SendGridAPIClient(apikey='SG.your-api-key') + +mail = Mail(from_email='templates@example.com') +mail.template_id = 'd-your-dynamic-template-uid' +p = Personalization() +p.add_to(Email('user@example.com')) +p.dynamic_template_data = {'name': 'Bob', 'balance': 42} +mail.add_personalization(p) + +sg.client.mail.send.post(request_body=mail.get()) +``` + +Read more about dynamic templates in [docs](https://sendgrid.com/docs/User_Guide/Transactional_Templates/how_to_send_an_email_with_transactional_templates.html) + ## Without Mail Helper Class ```python @@ -113,4 +143,4 @@ except urllib.HTTPError as e: print(response.status_code) print(response.body) print(response.headers) -``` \ No newline at end of file +``` From 8ff82a83abe14c2d5910b56fad8ccc3cbf53bc74 Mon Sep 17 00:00:00 2001 From: Slam <3lnc.slam@gmail.com> Date: Wed, 1 Aug 2018 20:35:15 +0300 Subject: [PATCH 26/82] Linking SG dashboard --- use_cases/transational_templates.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/use_cases/transational_templates.md b/use_cases/transational_templates.md index 1e89e08a9..d88ffae76 100644 --- a/use_cases/transational_templates.md +++ b/use_cases/transational_templates.md @@ -71,7 +71,8 @@ print(response.headers) Sendgrid dynamic templates let you leverage power of [handlebars](https://handlebarsjs.com/) syntax to easily manage complex dynamic content in transactional emails. -To check this example snippet, create transactional email with code like +To check this example snippet, create +[transactional email template](https://sendgrid.com/dynamic_templates) with code like ```html

Hello, {{name}}! Your current balance is {{balance}}

``` From 65f4857a800c379620f216426f0417c9e78d440c Mon Sep 17 00:00:00 2001 From: lifez Date: Fri, 3 Aug 2018 17:56:12 +0700 Subject: [PATCH 27/82] Change type of category in Mail.add_category from string to Category --- sendgrid/helpers/mail/mail.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sendgrid/helpers/mail/mail.py b/sendgrid/helpers/mail/mail.py index 6554d4508..22a3fad66 100644 --- a/sendgrid/helpers/mail/mail.py +++ b/sendgrid/helpers/mail/mail.py @@ -8,10 +8,10 @@ class Mail(object): Use get() to get the request body. """ - def __init__(self, - from_email=None, - subject=None, - to_email=None, + def __init__(self, + from_email=None, + subject=None, + to_email=None, content=None): """Create a Mail object. @@ -73,7 +73,7 @@ def get(self): if self.from_email is not None: mail["from"] = self.from_email.get() - + if self.subject is not None: mail["subject"] = self.subject @@ -306,7 +306,7 @@ def add_content(self, content): """ if self._contents is None: self._contents = [] - + # Text content should be before HTML content if content._type == "text/plain": self._contents.insert(0, content) @@ -376,9 +376,9 @@ def categories(self): return self._categories def add_category(self, category): - """Add a Category to this Mail. Must be less than 255 characters. + """Add a Category to this Mail. - :type category: string + :type category: Category """ self._categories.append(category) From 0ca2578c19b5626d1a60964e1d347b173f9ee65e Mon Sep 17 00:00:00 2001 From: lifez Date: Fri, 3 Aug 2018 18:18:34 +0700 Subject: [PATCH 28/82] Install pip for python3.6 --- docker/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index e891e497c..cd36ea199 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -25,14 +25,15 @@ RUN chmod +x ./install.sh && sync && \ # install pip, tox ADD https://bootstrap.pypa.io/get-pip.py get-pip.py RUN python2.7 get-pip.py && \ + python3.6 get-pip.py && \ pip install tox && \ rm get-pip.py #install pyyaml, six, werkzeug RUN python3.6 -m pip install pyyaml RUN python3.6 -m pip install six -RUN Python3.6 -m pip install werkzeug -RUN Python3.6 -m pip install flask +RUN python3.6 -m pip install werkzeug +RUN python3.6 -m pip install flask # set up default sendgrid env WORKDIR /root/sources From 382b5e87d53865ffce702e9bbf4d3a05a3d3d2c6 Mon Sep 17 00:00:00 2001 From: Ryan Jarvis Date: Fri, 3 Aug 2018 16:30:39 -0700 Subject: [PATCH 29/82] Update TROUBLESHOOTING.md --- TROUBLESHOOTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index 29c0c8e89..331aee8e7 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -50,7 +50,7 @@ import urllib try: response = sg.client.mail.send.post(request_body=mail.get()) except urllib.error.HTTPError as e: - print e.read() + print(e.read()) ``` From 6adc94886d389c00dafb005cb56ec292b1bd6af1 Mon Sep 17 00:00:00 2001 From: af4ro <1997ansul@gmail.com> Date: Mon, 6 Aug 2018 16:23:41 -0700 Subject: [PATCH 30/82] fixed assertion error --- test/test_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_project.py b/test/test_project.py index e5f05de36..a9edc8195 100644 --- a/test/test_project.py +++ b/test/test_project.py @@ -9,7 +9,7 @@ class ProjectTests(unittest.TestCase): # ./Docker or docker/Docker def test_docker_dir(self): - self.assertTrue(os.path.isdir("./docker/Dockerfile")) + self.assertTrue(os.path.isfile("./docker/Dockerfile")) # ./docker-compose.yml or ./docker/docker-compose.yml def test_docker_compose(self): From e1cc25685ffc8ea0d5c7ebc22c083f62cf0169ab Mon Sep 17 00:00:00 2001 From: af4ro <1997anshul@gmail.com> Date: Thu, 9 Aug 2018 09:39:27 -0700 Subject: [PATCH 31/82] minor formatting --- examples/helpers/mail_example.py | 8 ++++++-- test/test_mail.py | 16 ++++++++++++++-- use_cases/transational_templates.md | 3 ++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/examples/helpers/mail_example.py b/examples/helpers/mail_example.py index e227b22cc..0a5b868bc 100644 --- a/examples/helpers/mail_example.py +++ b/examples/helpers/mail_example.py @@ -226,11 +226,15 @@ def dynamic_template_usage():

Hello, {{name}}! Your current balance is {{balance}}

""" - mail = Mail(from_email='templates@sendgrid.com') + mail = Mail() + mail.from_email = 'templates@sendgrid.com' mail.template_id = 'd-your-dynamic-template-uid' p = Personalization() p.add_to(Email('user@example.com')) - p.dynamic_template_data = {'name': 'Bob', 'balance': 42} + p.dynamic_template_data = { + 'name': 'Bob', + 'balance': 42 + } mail.add_personalization(p) sg = SendGridAPIClient(apikey='SG.your-api-key') diff --git a/test/test_mail.py b/test/test_mail.py index fb46d34c2..08d0feb8e 100644 --- a/test/test_mail.py +++ b/test/test_mail.py @@ -565,10 +565,22 @@ def test_directly_setting_substitutions(self): def test_dynamic_template_data(self): p = Personalization() p.add_to(Email('test@sendgrid.com')) - p.dynamic_template_data = {'customer': {'name': 'Bob', 'returning': True}, 'total': 42} + p.dynamic_template_data = { + 'customer': { + 'name': 'Bob', + 'returning': True + }, + 'total': 42 + } expected = { 'to': [{'email': 'test@sendgrid.com'}], - 'dynamic_template_data': {'customer': {'name': 'Bob', 'returning': True}, 'total': 42} + 'dynamic_template_data': { + 'customer': { + 'name': 'Bob', + 'returning': True + }, + 'total': 42 + } } self.assertDictEqual(p.get(), expected) diff --git a/use_cases/transational_templates.md b/use_cases/transational_templates.md index d88ffae76..2d74f92a5 100644 --- a/use_cases/transational_templates.md +++ b/use_cases/transational_templates.md @@ -85,7 +85,8 @@ from sendgrid.helpers.mail import Email, Personalization sg = SendGridAPIClient(apikey='SG.your-api-key') -mail = Mail(from_email='templates@example.com') +mail = Mail() +mail.from_email='templates@example.com' mail.template_id = 'd-your-dynamic-template-uid' p = Personalization() p.add_to(Email('user@example.com')) From 54aa6ec05ced0c9c5577abef118f5a2ecb1ed711 Mon Sep 17 00:00:00 2001 From: Anshul Singhal <1997anshul@gmail.com> Date: Fri, 10 Aug 2018 16:03:54 -0700 Subject: [PATCH 32/82] Minor readability update --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b38f1c1c4..882e52164 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -191,8 +191,10 @@ Please run your code through: ```bash # Clone your fork of the repo into the current directory git clone https://github.com/sendgrid/sendgrid-python + # Navigate to the newly cloned directory cd sendgrid-python + # Assign the original repo to a remote called "upstream" git remote add upstream https://github.com/sendgrid/sendgrid-python ``` From 0c2163c3f545e7e7a91d05b6b2fcb037768d83af Mon Sep 17 00:00:00 2001 From: Navin Pai Date: Tue, 14 Aug 2018 03:00:04 +0530 Subject: [PATCH 33/82] Add slack API integration to use_cases --- use_cases/README.md | 1 + use_cases/slack_event_api_integration.md | 46 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 use_cases/slack_event_api_integration.md diff --git a/use_cases/README.md b/use_cases/README.md index 188464d09..ea8156533 100644 --- a/use_cases/README.md +++ b/use_cases/README.md @@ -15,6 +15,7 @@ This directory provides examples for specific use cases of this library. Please * [Asynchronous Mail Send](asynchronous_mail_send.md) * [Attachment](attachment.md) * [Transactional Templates](transational_templates.md) +* [Integrate with Slack Events API](slack_event_api_integration.md) ### Library Features * [Error Handling](error_handling.md) \ No newline at end of file diff --git a/use_cases/slack_event_api_integration.md b/use_cases/slack_event_api_integration.md new file mode 100644 index 000000000..d0e0f6140 --- /dev/null +++ b/use_cases/slack_event_api_integration.md @@ -0,0 +1,46 @@ +# Integrate with Slack Events API + +It's fairly straightforward to integrate Sendgrid with Slack, to allow emails to be triggered by events happening on Slack. + +For this, we make use of the [Official Slack Events API](https://github.com/slackapi/python-slack-events-api), which can be installed using pip. + +To allow our application to get notifications of slack events, we first create a Slack App with Event Subscriptions as described [here](https://github.com/slackapi/python-slack-events-api#--development-workflow) + +Then, we set `SENDGRID_API_KEY` _(which you can create on the Sendgrid dashboard)_ and `SLACK_VERIFICATION_TOKEN` _(which you can get in the App Credentials section of the Slack App)_ as environment variables. + +Once this is done, we can subscribe to [events on Slack](https://api.slack.com/events) and trigger emails when an event occurs. In the example below, we trigger an email to `test@example.com` whenever someone posts a message on Slack that has the word "_help_" in it. + +``` +from slackeventsapi import SlackEventAdapter +from slackclient import SlackClient +import os +import sendgrid +from sendgrid.helpers.mail import * + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +SLACK_VERIFICATION_TOKEN = os.environ["SLACK_VERIFICATION_TOKEN"] +slack_events_adapter = SlackEventAdapter(SLACK_VERIFICATION_TOKEN, "/slack/events") + +@slack_events_adapter.on("message") +def handle_message(event_data): + message = event_data["event"] + # If the incoming message contains "help", then send an email using SendGrid + if message.get("subtype") is None and "help" in message.get('text').lower(): + message = "Someone needs your help: \n\n %s" % message["text"] + r = send_email(message) + print(r) + + +def send_email(message): + from_email = Email("slack_integration@example.com") + to_email = Email("test@example.com") + subject = "Psst... Someone needs help!" + content = Content("text/plain", message) + mail = Mail(from_email, subject, to_email, content) + response = sg.client.mail.send.post(request_body=mail.get()) + return response.status_code + +# Start the slack event listener server on port 3000 +slack_events_adapter.start(port=3000) +``` \ No newline at end of file From 5364bf9872b76bc496759b5d8f740e22059e7c43 Mon Sep 17 00:00:00 2001 From: James Purpura Date: Mon, 13 Aug 2018 15:01:44 -0700 Subject: [PATCH 34/82] update TROUBLESHOOTING.md editted "our use cases" link --- TROUBLESHOOTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index 29c0c8e89..a2332ae1b 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -111,4 +111,4 @@ print mail.get() # Error Handling -Please review [our use_cases](https://github.com/sendgrid/sendgrid-python/use_cases/README.md) for examples of error handling. +Please review [our use_cases](https://github.com/sendgrid/sendgrid-python/blob/master/use_cases/README.md#use-cases) for examples of error handling. From 07ed3228313eb4379877867fa81ce3fac18c612b Mon Sep 17 00:00:00 2001 From: Agnes Jang Date: Tue, 14 Aug 2018 13:45:04 -0700 Subject: [PATCH 35/82] Added comment for attachments to be base64 encoded --- examples/helpers/mail/mail_example.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/helpers/mail/mail_example.py b/examples/helpers/mail/mail_example.py index b2de7f0a0..3a4a350a8 100644 --- a/examples/helpers/mail/mail_example.py +++ b/examples/helpers/mail/mail_example.py @@ -80,7 +80,8 @@ def get_mock_personalization_dict(): def build_attachment1(): - """Build attachment mock.""" + """Build attachment mock. Make sure your content is base64 encoded before passing into attachment.content. + Another example: https://github.com/sendgrid/sendgrid-python/blob/master/use_cases/attachment.md""" attachment = Attachment() attachment.content = ("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNl" "Y3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12") From 3ec8e6535baf9a75814aae4cc7f7c539c1af577a Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Thu, 16 Aug 2018 09:22:35 -0700 Subject: [PATCH 36/82] Add missing dependencies --- docker-test/entrypoint.sh | 2 +- requirements.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-test/entrypoint.sh b/docker-test/entrypoint.sh index f64d0cccb..abb55b9f2 100644 --- a/docker-test/entrypoint.sh +++ b/docker-test/entrypoint.sh @@ -13,5 +13,5 @@ fi cd sendgrid-python python3.6 setup.py install -pip install pyyaml six werkzeug flask +pip install pyyaml six werkzeug flask python-http-client exec $SHELL diff --git a/requirements.txt b/requirements.txt index 34d770b5b..ceae6cf62 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ Flask==0.10.1 PyYAML==3.11 python-http-client==2.2.1 six==1.10.0 +pytest=3.7.1 \ No newline at end of file From 793aad7c3e520e18b391de4a1333d9ec463abd2f Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Thu, 16 Aug 2018 12:03:10 -0700 Subject: [PATCH 37/82] Version Bump v5.5.0: Pre-Dynamic Template Roll Up Release --- CHANGELOG.md | 16 +++++++++++++++- docker/README.md | 3 ++- sendgrid/version.py | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c1869666..69c0a5211 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,24 @@ # Change Log All notable changes to this project will be documented in this file. +## [5.5.1] - 2018-08-16 ## +### Added +- [PR #588](https://github.com/sendgrid/sendgrid-python/pull/588): Updates the Readme to include environment variable setup in windows. Big thanks to [Bhargav Chandaka](https://github.com/bchandaka) for the PR! +- [PR #599](https://github.com/sendgrid/sendgrid-python/pull/599): Updates the Readme to include additional API Key instruction. Big thanks to [Anshul Singhal](https://github.com/af4ro) for the PR! +- [PR #600](https://github.com/sendgrid/sendgrid-python/pull/600): Add CodeTriage Badge. Big thanks to [Anshul Singhal](https://github.com/af4ro) for the PR! +- [PR #601](https://github.com/sendgrid/sendgrid-python/pull/601): Readability improvements to CONTRIBUTING.md. Big thanks to [Anshul Singhal](https://github.com/af4ro) for the PR! +- [PR #604](https://github.com/sendgrid/sendgrid-python/pull/604): Readability improvements to CONTRIBUTING.md. Big thanks to [agnesjang98](https://github.com/agnesjang98) for the PR! + +### Fixed +- [PR #595](https://github.com/sendgrid/sendgrid-python/pull/595): Change type of category in Mail.add_category from string to Category. Big thanks to [Phawin Khongkhasawan](https://github.com/lifez) for the PR! +- [PR #596](https://github.com/sendgrid/sendgrid-python/pull/596): Fix Docker build. Big thanks to [Phawin Khongkhasawan](https://github.com/lifez) for the PR! +- [PR #598](https://github.com/sendgrid/sendgrid-python/pull/598): Fix python3 print example in TROUBLESHOOTING.md. Big thanks to [Ryan Jarvis](https://github.com/Cabalist) for the PR! +- [PR #603](https://github.com/sendgrid/sendgrid-python/pull/603): Update TROUBLESHOOTING.md to link to correct use cases page. Big thanks to [James Purpura](https://github.com/jpurpura) for the PR! + ## [5.4.1] - 2018-06-26 ## ### Fixed - [PR #585](https://github.com/sendgrid/sendgrid-python/pull/585): Fix typo in `mail_example.py`. Big thanks to [Anurag Anand](https://github.com/theanuraganand) for the PR! -- [PR #583](https://github.com/sendgrid/sendgrid-python/pull/585): Fix `Personalization.substitutions` setter. Trying to set substitutions directly rather than with add_substitution was causing an infinite regress. Big thanks to [Richard Nias](https://github.com/richardnias) for the PR! +- [PR #583](https://github.com/sendgrid/sendgrid-python/pull/583): Fix `Personalization.substitutions` setter. Trying to set substitutions directly rather than with add_substitution was causing an infinite regress. Big thanks to [Richard Nias](https://github.com/richardnias) for the PR! ## [5.4.0] - 2018-06-07 ## ### Added diff --git a/docker/README.md b/docker/README.md index a523dc93d..41c235fcc 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,5 +1,6 @@ # Supported tags and respective `Dockerfile` links - - `v5.4.1`, `latest` [(Dockerfile)](https://github.com/sendgrid/sendgrid-python/blob/master/docker/Dockerfile) + - `v5.5.0`, `latest` [(Dockerfile)](https://github.com/sendgrid/sendgrid-python/blob/master/docker/Dockerfile) + - `v5.4.1` - `v5.4.0` - `v5.3.0` - `v5.2.1` diff --git a/sendgrid/version.py b/sendgrid/version.py index c191754f8..30415fcbd 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1,2 +1,2 @@ -version_info = (5, 4, 1) +version_info = (5, 5, 0) __version__ = '.'.join(str(v) for v in version_info) From 28bd2a5d91c0130ffd832bec4cc95356e0b37ce7 Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Mon, 20 Aug 2018 17:05:50 -0700 Subject: [PATCH 38/82] Merge #593 --- docker-test/entrypoint.sh | 2 +- examples/helpers/mail_example.py | 14 ++- sendgrid/helpers/mail/mail.py | 3 + sendgrid/helpers/mail/personalization.py | 14 ++- use_cases/transational_templates.md | 103 +++++++++++++++-------- 5 files changed, 95 insertions(+), 41 deletions(-) diff --git a/docker-test/entrypoint.sh b/docker-test/entrypoint.sh index abb55b9f2..6749e8cf3 100644 --- a/docker-test/entrypoint.sh +++ b/docker-test/entrypoint.sh @@ -13,5 +13,5 @@ fi cd sendgrid-python python3.6 setup.py install -pip install pyyaml six werkzeug flask python-http-client +pip install pyyaml six werkzeug flask python-http-client pytest exec $SHELL diff --git a/examples/helpers/mail_example.py b/examples/helpers/mail_example.py index 65176a6ca..c1cd166ad 100644 --- a/examples/helpers/mail_example.py +++ b/examples/helpers/mail_example.py @@ -218,7 +218,10 @@ def send_kitchen_sink(): send_kitchen_sink() -def dynamic_template_usage(): +def transactional_template_usage(): + # Assumes you set your environment variable: + # https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key + """ Sample usage of dynamic (handlebars) transactional templates. To make this work, you should have dynamic template created within your @@ -228,7 +231,7 @@ def dynamic_template_usage(): """ mail = Mail() - mail.from_email = 'templates@sendgrid.com' + mail.from_email = Email('templates@sendgrid.com') mail.template_id = 'd-your-dynamic-template-uid' p = Personalization() p.add_to(Email('user@example.com')) @@ -238,5 +241,8 @@ def dynamic_template_usage(): } mail.add_personalization(p) - sg = SendGridAPIClient(apikey='SG.your-api-key') - sg.client.mail.send.post(request_body=mail.get()) + sg = SendGridAPIClient() + response = sg.client.mail.send.post(request_body=mail.get()) + print(response.status_code) + print(response.headers) + print(response.body) diff --git a/sendgrid/helpers/mail/mail.py b/sendgrid/helpers/mail/mail.py index 22a3fad66..fd606fd18 100644 --- a/sendgrid/helpers/mail/mail.py +++ b/sendgrid/helpers/mail/mail.py @@ -1,6 +1,7 @@ """v3/mail/send response body builder""" from .personalization import Personalization from .header import Header +from .email import Email class Mail(object): @@ -147,6 +148,8 @@ def from_email(self): @from_email.setter def from_email(self, value): + if isinstance(value, str): + value = Email(value) self._from_email = value @property diff --git a/sendgrid/helpers/mail/personalization.py b/sendgrid/helpers/mail/personalization.py index 8032af958..c42694fe9 100644 --- a/sendgrid/helpers/mail/personalization.py +++ b/sendgrid/helpers/mail/personalization.py @@ -17,7 +17,7 @@ def __init__(self): self._substitutions = [] self._custom_args = [] self._send_at = None - self.dynamic_template_data = None + self._dynamic_template_data = None @property def tos(self): @@ -163,6 +163,18 @@ def send_at(self): def send_at(self, value): self._send_at = value + @property + def dynamic_template_data(self): + """Data for dynamic transactional template. + + :rtype: JSON-serializeable structure + """ + return self._dynamic_template_data + + @dynamic_template_data.setter + def dynamic_template_data(self, json): + self._dynamic_template_data = json + def get(self): """ Get a JSON-ready representation of this Personalization. diff --git a/use_cases/transational_templates.md b/use_cases/transational_templates.md index 2d74f92a5..d3d587bc0 100644 --- a/use_cases/transational_templates.md +++ b/use_cases/transational_templates.md @@ -1,6 +1,71 @@ -# Transactional Templates +### Transactional Templates -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. +Sendgrid transactional templates let you leverage power of [handlebars](https://handlebarsjs.com/) +syntax to easily manage complex dynamic content in transactional emails. + +For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/create_and_edit_transactional_templates.html). Following is the template content we used for testing. + +This example also assumes you [set your environment variable](https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key) with your SendGrid API Key. + +Template ID (replace with your own): + +```text +d-13b8f94fbcae4ec6b75270d6cb59f932 +``` + +Email Subject: + +```text +{{ subject }} +``` + +Template Body: + +```html + + + + + +Hello {{ name }}, +

+I'm glad you are trying out the template feature! +

+I hope you are having a great day in {{ city }} :) +

+ + +``` + +```python +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import Mail, Email, Personalization + + +sg = SendGridAPIClient() +mail = Mail() +mail.from_email = Email('templates@example.com') +mail.template_id = 'd-your-dynamic-template-uid' +p = Personalization() +p.add_to(Email('user@example.com')) +p.dynamic_template_data = { + 'subject': 'Dynamic Templates in Python', + 'name': 'Example User', + 'city': 'Denver' +} +mail.add_personalization(p) + +response = sg.client.mail.send.post(request_body=mail.get()) +print(response.status_code) +print(response.headers) +print(response.body) +``` + +Read more about dynamic templates [here](https://sendgrid.com/docs/User_Guide/Transactional_Templates/how_to_send_an_email_with_transactional_templates.html). + +# Legacy Templates + +For this example, we assume you have created a [Legacy Template](https://sendgrid.com/templates). Following is the template content we used for testing. Template ID (replace with your own): @@ -66,38 +131,6 @@ print(response.body) print(response.headers) ``` -### With dynamic templates - -Sendgrid dynamic templates let you leverage power of [handlebars](https://handlebarsjs.com/) -syntax to easily manage complex dynamic content in transactional emails. - -To check this example snippet, create -[transactional email template](https://sendgrid.com/dynamic_templates) with code like -```html -

Hello, {{name}}! Your current balance is {{balance}}

-``` - -Than send email based on it, providing context for substitutions: -```python -from sendgrid import SendGridAPIClient -from sendgrid.helpers.mail import Email, Personalization - - -sg = SendGridAPIClient(apikey='SG.your-api-key') - -mail = Mail() -mail.from_email='templates@example.com' -mail.template_id = 'd-your-dynamic-template-uid' -p = Personalization() -p.add_to(Email('user@example.com')) -p.dynamic_template_data = {'name': 'Bob', 'balance': 42} -mail.add_personalization(p) - -sg.client.mail.send.post(request_body=mail.get()) -``` - -Read more about dynamic templates in [docs](https://sendgrid.com/docs/User_Guide/Transactional_Templates/how_to_send_an_email_with_transactional_templates.html) - ## Without Mail Helper Class ```python @@ -145,4 +178,4 @@ except urllib.HTTPError as e: print(response.status_code) print(response.body) print(response.headers) -``` +``` \ No newline at end of file From 7438ae17406f6f25cab58f9e807576c94a785d3d Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Mon, 20 Aug 2018 17:12:59 -0700 Subject: [PATCH 39/82] Version Bump v5.6.0: Dynamic Template support --- CHANGELOG.md | 6 +++++- docker/README.md | 3 ++- sendgrid/version.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69c0a5211..cde406f18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ # Change Log All notable changes to this project will be documented in this file. -## [5.5.1] - 2018-08-16 ## +## [5.6.0] - 2018-08-20 ## +### Added +- [PR #593](https://github.com/sendgrid/sendgrid-python/pull/593): Adds support for dynamic template data. Big thanks to [Wojciech Bartosiak](https://github.com/wojtek-fliposports) for the PR! Also, big thanks to []() for [PR #597](https://github.com/sendgrid/sendgrid-python/pull/597)! + +## [5.5.0] - 2018-08-16 ## ### Added - [PR #588](https://github.com/sendgrid/sendgrid-python/pull/588): Updates the Readme to include environment variable setup in windows. Big thanks to [Bhargav Chandaka](https://github.com/bchandaka) for the PR! - [PR #599](https://github.com/sendgrid/sendgrid-python/pull/599): Updates the Readme to include additional API Key instruction. Big thanks to [Anshul Singhal](https://github.com/af4ro) for the PR! diff --git a/docker/README.md b/docker/README.md index 41c235fcc..b439fe892 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,5 +1,6 @@ # Supported tags and respective `Dockerfile` links - - `v5.5.0`, `latest` [(Dockerfile)](https://github.com/sendgrid/sendgrid-python/blob/master/docker/Dockerfile) + - `v5.6.0`, `latest` [(Dockerfile)](https://github.com/sendgrid/sendgrid-python/blob/master/docker/Dockerfile) + - `v5.5.0` - `v5.4.1` - `v5.4.0` - `v5.3.0` diff --git a/sendgrid/version.py b/sendgrid/version.py index 30415fcbd..fffe2c469 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1,2 +1,2 @@ -version_info = (5, 5, 0) +version_info = (5, 6, 0) __version__ = '.'.join(str(v) for v in version_info) From fe61c16513c968b2c33ef034f9cbe4759d6d4614 Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Mon, 20 Aug 2018 17:15:55 -0700 Subject: [PATCH 40/82] Fix CHANGELOG attribution --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cde406f18..dd2334ba4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. ## [5.6.0] - 2018-08-20 ## ### Added -- [PR #593](https://github.com/sendgrid/sendgrid-python/pull/593): Adds support for dynamic template data. Big thanks to [Wojciech Bartosiak](https://github.com/wojtek-fliposports) for the PR! Also, big thanks to []() for [PR #597](https://github.com/sendgrid/sendgrid-python/pull/597)! +- [PR #593](https://github.com/sendgrid/sendgrid-python/pull/593): Adds support for dynamic template data. Big thanks to [Slam](https://github.com/3lnc) for the PR! Also, big thanks to [Wojciech Bartosiak](https://github.com/wojtek-fliposports) for [PR #597](https://github.com/sendgrid/sendgrid-python/pull/597)! ## [5.5.0] - 2018-08-16 ## ### Added From 84f7cf258f77f179dce0ef3bee8dc3b90f4af2f3 Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Wed, 22 Aug 2018 13:08:57 -0700 Subject: [PATCH 41/82] Typo in comments --- sendgrid/helpers/mail/personalization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/helpers/mail/personalization.py b/sendgrid/helpers/mail/personalization.py index c42694fe9..1ecbb8678 100644 --- a/sendgrid/helpers/mail/personalization.py +++ b/sendgrid/helpers/mail/personalization.py @@ -3,7 +3,7 @@ class Personalization(object): how that message should be handled. :var dynamic_template_data: data for dynamic transactional template. - Should be JSON-serializeable structure. No pre-processing sill be done + Should be JSON-serializeable structure. No pre-processing will be done prior to sending this via http client. """ From 27b302f05d187d1926cfb08b6b365d544eaa8feb Mon Sep 17 00:00:00 2001 From: Corey McCandless Date: Thu, 13 Sep 2018 11:49:12 -0400 Subject: [PATCH 42/82] Fix format of dependency `pytest` --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ceae6cf62..9756ebf8c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ Flask==0.10.1 PyYAML==3.11 python-http-client==2.2.1 six==1.10.0 -pytest=3.7.1 \ No newline at end of file +pytest==3.7.1 \ No newline at end of file From aba7f0449ca22d21be0ae32957e061c6ca64f6f7 Mon Sep 17 00:00:00 2001 From: themousepotato Date: Fri, 28 Sep 2018 09:41:51 +0530 Subject: [PATCH 43/82] fixes #610 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b2b6a1dbd..20bdfbc9b 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ print(response.body) print(response.headers) ``` -The `Mail` constructor creates a [personalization object](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html) for you. [Here](https://github.com/sendgrid/sendgrid-python/blob/master/examples/helpers/mail/mail_example.py#L16) is an example of how to add it. +The `Mail` constructor creates a [personalization object](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html) for you. [Here](https://github.com/sendgrid/sendgrid-python/blob/master/examples/helpers/mail_example.py#L16) is an example of how to add it. ### Without Mail Helper Class From 29fa10d3aaf8363ae51d3be49be0e77199fbe169 Mon Sep 17 00:00:00 2001 From: Bharat Raghunathan Date: Mon, 1 Oct 2018 09:41:45 +0530 Subject: [PATCH 44/82] Update README.md by including email Make it clear that the link is a redirect to an email and not to any members page or developer team page --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b2b6a1dbd..295582eb5 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,8 @@ Please see our [troubleshooting guide](https://github.com/sendgrid/sendgrid-pyth # About -sendgrid-python is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com). +sendgrid-python is guided and supported by the SendGrid Developer Experience Team. +Email the Developer Experience Team [here](mailto:dx@sendgrid.com) in case of any queries. sendgrid-python is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-python are trademarks of SendGrid, Inc. From a8907d8a68bc05455b874d58c69393d29c08fb31 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 1 Oct 2018 11:14:04 +0300 Subject: [PATCH 45/82] Fix typos --- .github/PULL_REQUEST_TEMPLATE | 2 +- CONTRIBUTING.md | 4 ++-- README.md | 6 +++--- sendgrid/__init__.py | 2 +- sendgrid/helpers/endpoints/ip/unassigned.py | 2 +- sendgrid/sendgrid.py | 2 +- use_cases/aws.md | 10 +++++----- use_cases/slack_event_api_integration.md | 4 ++-- use_cases/transational_templates.md | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE index 7ad590b42..b3b7a4446 100644 --- a/.github/PULL_REQUEST_TEMPLATE +++ b/.github/PULL_REQUEST_TEMPLATE @@ -21,4 +21,4 @@ Closes #2 - - -If you have questions, please send an email to [Sendgrid](mailto:dx@sendgrid.com), or file a Github Issue in this repository. +If you have questions, please send an email to [SendGrid](mailto:dx@sendgrid.com), or file a GitHub Issue in this repository. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 882e52164..a875bf9c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,7 +46,7 @@ A software bug is a demonstrable issue in the code base. In order for us to diag Before you decide to create a new issue, please try the following: -1. Check the Github issues tab if the identified issue has already been reported, if so, please add a +1 to the existing post. +1. Check the GitHub issues tab if the identified issue has already been reported, if so, please add a +1 to the existing post. 2. Update to the latest version of this code and check if issue has already been fixed 3. Copy and fill in the Bug Report Template we have provided below @@ -242,4 +242,4 @@ If you have any additional questions, please feel free to [email](mailto:dx@send ## Code Reviews -If you can, please look at open PRs and review them. Give feedback and help us merge these PRs much faster! If you don't know how, Github has some great [information on how to review a Pull Request](https://help.github.com/articles/about-pull-request-reviews/). +If you can, please look at open PRs and review them. Give feedback and help us merge these PRs much faster! If you don't know how, GitHub has some great [information on how to review a Pull Request](https://help.github.com/articles/about-pull-request-reviews/). diff --git a/README.md b/README.md index b2b6a1dbd..a4aa8c343 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,10 @@ echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env echo "sendgrid.env" >> .gitignore source ./sendgrid.env ``` -Sendgrid also supports local environment file `.env`. Copy or rename `.env_sample` into `.env` and update [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys) with your key. +SendGrid also supports local environment file `.env`. Copy or rename `.env_sample` into `.env` and update [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys) with your key. -### Windows -Temporarily set the environment variable(accesible only during the current cli session): +### Windows +Temporarily set the environment variable(accessible only during the current cli session): ```bash set SENDGRID_API_KEY=YOUR_API_KEY ``` diff --git a/sendgrid/__init__.py b/sendgrid/__init__.py index 2bbd38b59..1b5100c01 100644 --- a/sendgrid/__init__.py +++ b/sendgrid/__init__.py @@ -2,7 +2,7 @@ This library allows you to quickly and easily use the SendGrid Web API v3 via Python. -For more information on this library, see the README on Github. +For more information on this library, see the README on GitHub. http://github.com/sendgrid/sendgrid-python For more information on the SendGrid v3 API, see the v3 docs: http://sendgrid.com/docs/API_Reference/api_v3.html diff --git a/sendgrid/helpers/endpoints/ip/unassigned.py b/sendgrid/helpers/endpoints/ip/unassigned.py index 075f19857..ff5edbd73 100644 --- a/sendgrid/helpers/endpoints/ip/unassigned.py +++ b/sendgrid/helpers/endpoints/ip/unassigned.py @@ -21,7 +21,7 @@ def unassigned(data, as_json=False): and the usernames assigned to an IP unassigned returns a listing of the IP addresses that are allocated - but have 0 usera assigned + but have 0 users assigned data (response.body from sg.client.ips.get()) diff --git a/sendgrid/sendgrid.py b/sendgrid/sendgrid.py index 0f09bd542..cc3450091 100644 --- a/sendgrid/sendgrid.py +++ b/sendgrid/sendgrid.py @@ -2,7 +2,7 @@ This library allows you to quickly and easily use the SendGrid Web API v3 via Python. -For more information on this library, see the README on Github. +For more information on this library, see the README on GitHub. http://github.com/sendgrid/sendgrid-python For more information on the SendGrid v3 API, see the v3 docs: http://sendgrid.com/docs/API_Reference/api_v3.html diff --git a/use_cases/aws.md b/use_cases/aws.md index 2ff04bd1f..d07d5769c 100644 --- a/use_cases/aws.md +++ b/use_cases/aws.md @@ -13,7 +13,7 @@ Python 2.6, 2.7, 3.4, or 3.5 are supported by the sendgrid Python library, howev Before starting this tutorial, you will need to have access to an AWS account in which you are allowed to provision resources. This tutorial also assumes you've already created a SendGrid account with free-tier access. Finally, it is highly recommended you utilize [virtualenv](https://virtualenv.pypa.io/en/stable/). -*DISCLAIMER*: Any resources provisioned here may result in charges being incurred to your account. Sendgrid is in no way responsible for any billing charges. +*DISCLAIMER*: Any resources provisioned here may result in charges being incurred to your account. SendGrid is in no way responsible for any billing charges. ## Getting Started @@ -36,15 +36,15 @@ On the next menu, you have the option to choose what programming language you'll Follow the steps on the next screen. Choose a name for your API key, such as "hello-email". Follow the remaining steps to create an environment variable, install the sendgrid module, and copy the test code. Once that is complete, check the "I've integrated the code above" box, and click the "Next: Verify Integration" button. -Assuming all the steps were completed correctly, you should be greeted with a success message. If not, go back and verify that everything is correct, including your API key environment varible, and Python code. +Assuming all the steps were completed correctly, you should be greeted with a success message. If not, go back and verify that everything is correct, including your API key environment variable, and Python code. ## Deploy hello-world app using CodeStar -For the rest of the tutorial, we'll be working out of the git repository we cloned from AWS earlier: +For the rest of the tutorial, we'll be working out of the Git repository we cloned from AWS earlier: ``` $ cd hello-email ``` -note: this assumes you cloned the git repo inside your current directory. My directory is: +note: this assumes you cloned the Git repo inside your current directory. My directory is: ``` ~/projects/hello-email @@ -139,7 +139,7 @@ def handler(event, context): 'headers': {'Content-Type': 'application/json'}} ``` -Note that for the most part, we've simply copied the intial code from the API verification with SendGrid. Some slight modifications were needed to allow it to run as a lambda function, and for the output to be passed cleanly from the API endpoint. +Note that for the most part, we've simply copied the initial code from the API verification with SendGrid. Some slight modifications were needed to allow it to run as a lambda function, and for the output to be passed cleanly from the API endpoint. Change the `test@example.com` emails appropriately so that you may receive the test email. diff --git a/use_cases/slack_event_api_integration.md b/use_cases/slack_event_api_integration.md index d0e0f6140..ecce40695 100644 --- a/use_cases/slack_event_api_integration.md +++ b/use_cases/slack_event_api_integration.md @@ -1,12 +1,12 @@ # Integrate with Slack Events API -It's fairly straightforward to integrate Sendgrid with Slack, to allow emails to be triggered by events happening on Slack. +It's fairly straightforward to integrate SendGrid with Slack, to allow emails to be triggered by events happening on Slack. For this, we make use of the [Official Slack Events API](https://github.com/slackapi/python-slack-events-api), which can be installed using pip. To allow our application to get notifications of slack events, we first create a Slack App with Event Subscriptions as described [here](https://github.com/slackapi/python-slack-events-api#--development-workflow) -Then, we set `SENDGRID_API_KEY` _(which you can create on the Sendgrid dashboard)_ and `SLACK_VERIFICATION_TOKEN` _(which you can get in the App Credentials section of the Slack App)_ as environment variables. +Then, we set `SENDGRID_API_KEY` _(which you can create on the SendGrid dashboard)_ and `SLACK_VERIFICATION_TOKEN` _(which you can get in the App Credentials section of the Slack App)_ as environment variables. Once this is done, we can subscribe to [events on Slack](https://api.slack.com/events) and trigger emails when an event occurs. In the example below, we trigger an email to `test@example.com` whenever someone posts a message on Slack that has the word "_help_" in it. diff --git a/use_cases/transational_templates.md b/use_cases/transational_templates.md index d3d587bc0..491d528bd 100644 --- a/use_cases/transational_templates.md +++ b/use_cases/transational_templates.md @@ -1,6 +1,6 @@ ### Transactional Templates -Sendgrid transactional templates let you leverage power of [handlebars](https://handlebarsjs.com/) +SendGrid transactional templates let you leverage power of [handlebars](https://handlebarsjs.com/) syntax to easily manage complex dynamic content in transactional emails. For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/create_and_edit_transactional_templates.html). Following is the template content we used for testing. From 1a1d3a50e326f66222ac6e193cfa84b02e7fd365 Mon Sep 17 00:00:00 2001 From: Bharat123Rox Date: Wed, 3 Oct 2018 13:06:39 +0530 Subject: [PATCH 46/82] Update README.md for Email and fix alphabetical order --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f019c1ce3..c08e417fc 100644 --- a/README.md +++ b/README.md @@ -212,9 +212,9 @@ Quick links: - [Feature Request](https://github.com/sendgrid/sendgrid-python/blob/master/CONTRIBUTING.md#feature-request) - [Bug Reports](https://github.com/sendgrid/sendgrid-python/blob/master/CONTRIBUTING.md#submit-a-bug-report) -- [Sign the CLA to Create a Pull Request](https://cla.sendgrid.com/sendgrid/sendgrid-python) - [Improvements to the Codebase](https://github.com/sendgrid/sendgrid-python/blob/master/CONTRIBUTING.md#improvements-to-the-codebase) - [Review Pull Requests](https://github.com/sendgrid/sendgrid-python/blob/master/CONTRIBUTING.md#code-reviews) +- [Sign the CLA to Create a Pull Request](https://cla.sendgrid.com/sendgrid/sendgrid-python) # Troubleshooting @@ -224,7 +224,9 @@ Please see our [troubleshooting guide](https://github.com/sendgrid/sendgrid-pyth # About -sendgrid-python is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com). +sendgrid-python is guided and supported by the SendGrid Developer Experience Team. + +Email the team [here](mailto:dx@sendgrid.com) in case of any queries. sendgrid-python is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-python are trademarks of SendGrid, Inc. From 80788ede975a874673ad412b1113f83c771ab027 Mon Sep 17 00:00:00 2001 From: Jeremy Yang Date: Wed, 3 Oct 2018 07:37:24 -0700 Subject: [PATCH 47/82] Update README Remove link to a position not found and replaced with general link to the careers page. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f019c1ce3..c70ef1f26 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ Please see [our helper](https://github.com/sendgrid/sendgrid-python/tree/master/ # Announcements -Join an experienced and passionate team that focuses on making an impact. Opportunities abound to grow the product - and grow your career! Check out our [Data Platform Engineer role](http://grnh.se/wbx1701) +Join an experienced and passionate team that focuses on making an impact. [Opportunities abound](https://sendgrid.com/careers) to grow the product - and grow your career! Please see our announcement regarding [breaking changes](https://github.com/sendgrid/sendgrid-python/issues/217). Your support is appreciated! From ce152d814e942b7876cdbece3fac091f3bb944dc Mon Sep 17 00:00:00 2001 From: Matthew Egan Date: Fri, 5 Oct 2018 11:04:50 +1000 Subject: [PATCH 48/82] Fix broken link for mail example --- sendgrid/helpers/mail/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sendgrid/helpers/mail/README.md b/sendgrid/helpers/mail/README.md index 09e3e2035..1d39fa1a6 100644 --- a/sendgrid/helpers/mail/README.md +++ b/sendgrid/helpers/mail/README.md @@ -11,5 +11,5 @@ python mail_settings.py ## Usage -- See the [examples](https://github.com/sendgrid/sendgrid-python/tree/master/examples/helpers/mail) for complete working examples. -- [Documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/overview.html) \ No newline at end of file +- See the [examples](https://github.com/sendgrid/sendgrid-python/blob/master/examples/mail/mail.py) for complete working examples. +- [Documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/overview.html) From bf610ae83ab694dd51dbf3a24146f0606d02b012 Mon Sep 17 00:00:00 2001 From: Matthew Egan Date: Fri, 5 Oct 2018 11:18:08 +1000 Subject: [PATCH 49/82] Fix link to actual helper examples --- sendgrid/helpers/mail/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/helpers/mail/README.md b/sendgrid/helpers/mail/README.md index 1d39fa1a6..c065f5b98 100644 --- a/sendgrid/helpers/mail/README.md +++ b/sendgrid/helpers/mail/README.md @@ -11,5 +11,5 @@ python mail_settings.py ## Usage -- See the [examples](https://github.com/sendgrid/sendgrid-python/blob/master/examples/mail/mail.py) for complete working examples. +- See the [examples](https://github.com/sendgrid/sendgrid-python/blob/master/examples/helpers/mail_example.py) for complete working examples. - [Documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/overview.html) From f7732dddb17447f573007171c856c7ee18c041f3 Mon Sep 17 00:00:00 2001 From: vinuthegr8 Date: Fri, 5 Oct 2018 18:34:32 +0530 Subject: [PATCH 50/82] Fixed syntax errors in Kitchen sink Python example code --- proposals/mail-helper-refactor.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proposals/mail-helper-refactor.md b/proposals/mail-helper-refactor.md index 5a0127fd6..4f21eb5f7 100644 --- a/proposals/mail-helper-refactor.md +++ b/proposals/mail-helper-refactor.md @@ -191,7 +191,7 @@ 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) + CustomArg('transactional4', 'true', p=1) ] msg.send_at = SendAt(1461775052, p=1) @@ -230,13 +230,13 @@ 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') + 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') + Section('%section3%', 'Substitution for Section 3 Tag') ] try: From a25435e4fbf961e22bb16bf8cdbc38478b6e6d3e Mon Sep 17 00:00:00 2001 From: vinuthegr8 Date: Fri, 5 Oct 2018 18:54:49 +0530 Subject: [PATCH 51/82] Fixed ModuleNotFoundError --- sendgrid/__init__.py | 6 +++--- sendgrid/sendgrid.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sendgrid/__init__.py b/sendgrid/__init__.py index 1b5100c01..4d8324235 100644 --- a/sendgrid/__init__.py +++ b/sendgrid/__init__.py @@ -15,7 +15,7 @@ Modules to help with common tasks. """ -from .version import __version__ # noqa +from version import __version__ # noqa # v3 API -from .sendgrid import SendGridAPIClient # noqa -from .helpers.mail import Email # noqa +from sendgrid import SendGridAPIClient # noqa +from helpers.mail import Email # noqa diff --git a/sendgrid/sendgrid.py b/sendgrid/sendgrid.py index cc3450091..85478b6fd 100644 --- a/sendgrid/sendgrid.py +++ b/sendgrid/sendgrid.py @@ -18,7 +18,7 @@ import python_http_client -from .version import __version__ +from version import __version__ class SendGridAPIClient(object): From 5fc6178a70b9f8928577ea02a919d48667a01634 Mon Sep 17 00:00:00 2001 From: vinuthegr8 Date: Fri, 5 Oct 2018 19:37:25 +0530 Subject: [PATCH 52/82] Reverted changes to files in /sendgrid --- sendgrid/__init__.py | 6 +++--- sendgrid/sendgrid.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sendgrid/__init__.py b/sendgrid/__init__.py index 4d8324235..1b5100c01 100644 --- a/sendgrid/__init__.py +++ b/sendgrid/__init__.py @@ -15,7 +15,7 @@ Modules to help with common tasks. """ -from version import __version__ # noqa +from .version import __version__ # noqa # v3 API -from sendgrid import SendGridAPIClient # noqa -from helpers.mail import Email # noqa +from .sendgrid import SendGridAPIClient # noqa +from .helpers.mail import Email # noqa diff --git a/sendgrid/sendgrid.py b/sendgrid/sendgrid.py index 85478b6fd..cc3450091 100644 --- a/sendgrid/sendgrid.py +++ b/sendgrid/sendgrid.py @@ -18,7 +18,7 @@ import python_http_client -from version import __version__ +from .version import __version__ class SendGridAPIClient(object): From 88ddc58b5c036b1cbd9befa5c8d2856c1512a1a0 Mon Sep 17 00:00:00 2001 From: Xeon Zolt Date: Fri, 5 Oct 2018 23:04:02 +0530 Subject: [PATCH 53/82] fixed changes suggested by grammerly --- CHANGELOG.md | 10 +- CODE_OF_CONDUCT.md | 32 +- CONTRIBUTING.md | 14 +- TROUBLESHOOTING.md | 4 +- USAGE.md | 4623 ++++++++++++++++++++++++++- docker-test/README.md | 2 +- docker/USAGE.md | 2 +- proposals/mail-helper-refactor.md | 2 +- sendgrid/helpers/inbound/README.md | 2 +- use_cases/asynchronous_mail_send.md | 2 +- use_cases/aws.md | 24 +- use_cases/django.md | 8 +- use_cases/flask_heroku.md | 2 +- 13 files changed, 4674 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd2334ba4..78b7fa26f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,7 +48,7 @@ All notable changes to this project will be documented in this file. - [PR #365](https://github.com/sendgrid/sendgrid-python/pull/365): Write tutorial to deploy simple Django app on Heroku. Big thanks to [Kan Ouivirach](https://github.com/zkan) for the PR! - [PR #526](https://github.com/sendgrid/sendgrid-python/pull/526): Include code reviews section. Big thanks to [Jared Scott](https://github.com/jlax47) for the PR! - [PR #414](https://github.com/sendgrid/sendgrid-python/pull/414): Provide utf-8 as encoding explicitly when opening text files. Big thanks to [Ruslan Shestopalyuk](https://github.com/rshest) for the PR! -- [PR #537](https://github.com/sendgrid/sendgrid-python/pull/537): Add unittesting support to .codeclimate.yml. Big thanks to [Prashu Chaudhary](https://github.com/prashuchaudhary) for the PR! +- [PR #537](https://github.com/sendgrid/sendgrid-python/pull/537): Add unit testing support to .codeclimate.yml. Big thanks to [Prashu Chaudhary](https://github.com/prashuchaudhary) for the PR! - [PR #554](https://github.com/sendgrid/sendgrid-python/pull/554): Ensure params are applied independently. Big thanks to [Nino Milenovic](https://github.com/rubyengineer) for the PR! - [PR #557](https://github.com/sendgrid/sendgrid-python/pull/557): Client cleanup. Big thanks to [Slam](https://github.com/3lnc) for the PR! - [PR #569](https://github.com/sendgrid/sendgrid-python/pull/569): Make Mail helper parameters truly optional. Big thanks to [Ian Beck](https://github.com/onecrayon) for the PR! @@ -58,13 +58,13 @@ All notable changes to this project will be documented in this file. - [PR #421](https://github.com/sendgrid/sendgrid-python/pull/421): Typos. Big thanks to [Abhishek Bhatt](https://github.com/ab-bh) for the PR! - [PR #432](https://github.com/sendgrid/sendgrid-python/pull/432): Typos. Big thanks to [Gaurav Arora](https://github.com/gaurav61) for the PR! - [PR #431](https://github.com/sendgrid/sendgrid-python/pull/431): Typos. Big thanks to [Gaurav Arora](https://github.com/gaurav61) for the PR! -- [PR #430](https://github.com/sendgrid/sendgrid-python/pull/430): Attempt to sync before executing shell command. Big thanks to [Aditya Narayan](https://github.com/aditnryn) for the PR! +- [PR #430](https://github.com/sendgrid/sendgrid-python/pull/430): Attempt to sync before executing the shell command. Big thanks to [Aditya Narayan](https://github.com/aditnryn) for the PR! - [PR #429](https://github.com/sendgrid/sendgrid-python/pull/429): Typos. Big thanks to [daluntw](https://github.com/daluntw) for the PR! - [PR #492](https://github.com/sendgrid/sendgrid-python/pull/492): -Updated date-range in LICENSE file. Big thanks to [Dhruv Srivastava](https://github.com/dhruvhacks) for the PR! +Updated date-range in the LICENSE file. Big thanks to [Dhruv Srivastava](https://github.com/dhruvhacks) for the PR! - [PR #482](https://github.com/sendgrid/sendgrid-python/pull/482): Typos. Big thanks to [Karan Samani](https://github.com/Kimi450) for the PR! - [PR #504](https://github.com/sendgrid/sendgrid-python/pull/504): Fix .codeclimate.yml. Big thanks to [Matt Bernier](https://github.com/mbernier) for the PR! -- [PR #505](https://github.com/sendgrid/sendgrid-python/pull/505): Remove unnecessary github PR templates. Big thanks to [Alex](https://github.com/pushkyn) for the PR! +- [PR #505](https://github.com/sendgrid/sendgrid-python/pull/505): Remove unnecessary GitHub PR templates. Big thanks to [Alex](https://github.com/pushkyn) for the PR! - [PR #494](https://github.com/sendgrid/sendgrid-python/pull/494): Remove unused import in register.py. Big thanks to [Alexis Rivera De La Torre](https://github.com/gardlt) for the PR! - [PR #469](https://github.com/sendgrid/sendgrid-python/pull/469): Removed the trailing white spaces. Big thanks to [Siddaram Halli](https://github.com/SidduH) for the PR! @@ -72,7 +72,7 @@ Removed the trailing white spaces. Big thanks to [Siddaram Halli](https://github - [PR #508](https://github.com/sendgrid/sendgrid-python/pull/508): Typos. Big thanks to [Saksham Gupta](https://github.com/shucon) for the PR! - [PR #353](https://github.com/sendgrid/sendgrid-python/pull/353): Typos. Big thanks to [Yothin M](https://github.com/yothinix) for the PR! - [PR #564](https://github.com/sendgrid/sendgrid-python/pull/564): Typos. Big thanks to [Chao](https://github.com/chaoranxie) for the PR! -- [PR #424](https://github.com/sendgrid/sendgrid-python/pull/424): Updating version 2.7.8 to 2.7.11 to match version in pyenv install instruction. Big thanks to [Krista LaFentres](https://github.com/lafentres) for the PR! +- [PR #424](https://github.com/sendgrid/sendgrid-python/pull/424): Updating version 2.7.8 to 2.7.11 to match the version in pyenv install instruction. Big thanks to [Krista LaFentres](https://github.com/lafentres) for the PR! - [PR #454](https://github.com/sendgrid/sendgrid-python/pull/454): Requests to send mail with both plain text and HTML content fail if the HTML content is specified first. Big thanks to [Ryan D'souza](https://github.com/dsouzarc) for the PR! - [PR #466](https://github.com/sendgrid/sendgrid-python/pull/466): Fixed PEP8 issues. Big thanks to [Piotr Szwarc](https://github.com/blackpioter) for the PR! - [PR #522](https://github.com/sendgrid/sendgrid-python/pull/522): Typos. Big thanks to [Abhishek J](https://github.com/slashstar) for the PR! diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 39ed18bf7..670a82f62 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,41 +1,41 @@ # SendGrid Community Code of Conduct - + The SendGrid open source community is made up of members from around the globe with a diverse set of skills, personalities, and experiences. It is through these differences that our community experiences successes and continued growth. When you're working with members of the community, we encourage you to follow these guidelines, which help steer our interactions and strive to maintain a positive, successful and growing community. - + ### Be Open Members of the community are open to collaboration, whether it's on pull requests, code reviews, approvals, issues or otherwise. We're receptive to constructive comments and criticism, as the experiences and skill sets of all members contribute to the whole of our efforts. We're accepting of all who wish to take part in our activities, fostering an environment where anyone can participate, and everyone can make a difference. - + ### Be Considerate Members of the community are considerate of their peers, which include other contributors and users of SendGrid. We're thoughtful when addressing the efforts of others, keeping in mind that often the labor was completed with the intent of the good of the community. We're attentive in our communications, whether in person or online, and we're tactful when approaching differing views. - + ### Be Respectful - Members of the community are respectful. We're respectful of others, their positions, their skills, their commitments and their efforts. We're respectful of the volunteer efforts that permeate the SendGrid community. We're respectful of the processes outlined in the community, and we work within them. When we disagree, we are courteous in raising our issues. Overall, we're good to each other. We contribute to this community not because we have to, but because we want to. If we remember that, these guidelines will come naturally. - + Members of the community are respectful. We're respectful of others, their positions, their skills, their commitments ,and their efforts. We're respectful of the volunteer efforts that permeate the SendGrid community. We're respectful of the processes outlined in the community, and we work within them. When we disagree, we are courteous in raising our issues. Overall, we're good with each other. We contribute to this community not because we have to, but because we want to. If we remember that, these guidelines will come naturally. + ## Additional Guidance - + ### Disclose Potential Conflicts of Interest Community discussions often involve interested parties. We expect participants to be aware when they are conflicted due to employment or other projects they are involved in and disclose those interests to other project members. When in doubt, over-disclose. Perceived conflicts of interest are important to address so that the community’s decisions are credible even when unpopular, difficult or favorable to the interests of one group over another. - + ### Interpretation This Code is not exhaustive or complete. It is not a rulebook; it serves to distill our common understanding of a collaborative, shared environment and goals. We expect it to be followed in spirit as much as in the letter. When in doubt, try to abide by [SendGrid’s cultural values](https://sendgrid.com/blog/employee-engagement-the-4h-way) defined by our “4H’s”: Happy, Hungry, Humble and Honest. - + ### Enforcement Most members of the SendGrid community always comply with this Code, not because of the existence of this Code, but because they have long experience participating in open source communities where the conduct described above is normal and expected. However, failure to observe this Code may be grounds for suspension, reporting the user for abuse or changing permissions for outside contributors. - + ## If you have concerns about someone’s conduct **Initiate Direct Contact** - It is always appropriate to email a community member (if contact information is available), mention that you think their behavior was out of line, and (if necessary) point them to this Code. - + **Discuss Publicly** - Discussing publicly is always acceptable. Note, though, that approaching the person directly may be better, as it tends to make them less defensive, and it respects the time of other community members, so you probably want to try direct contact first. - + **Contact the Moderators** - You can reach the SendGrid moderators by emailing dx@sendgrid.com. - + ## Submission to SendGrid Repositories Finally, just a reminder, changes to the SendGrid repositories will only be accepted upon completion of the [SendGrid Contributor Agreement](https://cla.sendgrid.com). - + ## Attribution - + SendGrid thanks the following, on which it draws for content and inspiration: - + [Python Community Code of Conduct](https://www.python.org/psf/codeofconduct/) [Open Source Initiative General Code of Conduct](https://opensource.org/codeofconduct) [Apache Code of Conduct](https://www.apache.org/foundation/policies/conduct.html) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a875bf9c1..90f8a1f42 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,14 +12,14 @@ Hello! Thank you for choosing to help contribute to one of the SendGrid open sou - [Code Reviews](#code-reviews) -We use [Milestones](https://github.com/sendgrid/sendgrid-python/milestones) to help define current roadmaps, please feel free to grab an issue from the current milestone. Please indicate that you have begun work on it to avoid collisions. Once a PR is made, community reviews, comments, suggestions and additional PRs are welcomed and encouraged. +We use [Milestones](https://github.com/sendgrid/sendgrid-python/milestones) to help define current roadmaps, please feel free to grab an issue from the current milestone. Please indicate that you have begun work on it to avoid collisions. Once a PR is made, community reviews, comments, suggestions, and additional PRs are welcomed and encouraged. ## CLAs and CCLAs Before you get started, SendGrid requires that a SendGrid Contributor License Agreement (CLA) be filled out by every contributor to a SendGrid open source project. -Our goal with the CLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way the CLA encourages broad participation by our open source community and helps us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution. +Our goal with the CLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way, the CLA encourages broad participation by our open source community and helps us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution. SendGrid does not merge a pull request made against a SendGrid open source project until that pull request is associated with a signed CLA. Copies of the CLA are available [here](https://gist.github.com/SendGridDX/98b42c0a5d500058357b80278fde3be8#file-sendgrid_cla). @@ -47,7 +47,7 @@ A software bug is a demonstrable issue in the code base. In order for us to diag Before you decide to create a new issue, please try the following: 1. Check the GitHub issues tab if the identified issue has already been reported, if so, please add a +1 to the existing post. -2. Update to the latest version of this code and check if issue has already been fixed +2. Update to the latest version of this code and check if the issue has already been fixed 3. Copy and fill in the Bug Report Template we have provided below ### Please use our Bug Report Template @@ -107,7 +107,7 @@ Working examples that demonstrate usage. **/tests** -Currently we have unit and profiling tests. +Currently, we have unit and profiling tests. **/sendgrid** @@ -206,14 +206,14 @@ Please run your code through: git pull upstream ``` -3. Create a new topic branch (off the main project development branch) to +3. Create a new topic branch (of the main project development branch) to contain your feature, change, or fix: ```bash git checkout -b ``` -4. Commit your changes in logical chunks. Please adhere to these [git commit +4. Commit your changes in logical chunks. Please adhere to these [git commits message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) or your code is unlikely to be merged into the main project. Use Git's [interactive rebase](https://help.github.com/articles/interactive-rebase) @@ -242,4 +242,4 @@ If you have any additional questions, please feel free to [email](mailto:dx@send ## Code Reviews -If you can, please look at open PRs and review them. Give feedback and help us merge these PRs much faster! If you don't know how, GitHub has some great [information on how to review a Pull Request](https://help.github.com/articles/about-pull-request-reviews/). +If you can, please look at open PRs and review them. Give feedback and help us merge these PRs much faster! If you don't know how GitHub has some great [information on how to review a Pull Request](https://help.github.com/articles/about-pull-request-reviews/). diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index 1298ab7d1..a33919a26 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -27,7 +27,7 @@ becomes `apikey='SENDGRID_API_KEY'` -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. +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. ## Error Messages @@ -95,7 +95,7 @@ If you are using a [requirements file](https://pip.readthedocs.io/en/1.1/require ## 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](https://github.com/sendgrid/sendgrid-python/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-python/releases) section. +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 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](https://github.com/sendgrid/sendgrid-python/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-python/releases) section. ## Viewing the Request Body diff --git a/USAGE.md b/USAGE.md index 09b78609a..ea2beae39 100644 --- a/USAGE.md +++ b/USAGE.md @@ -70,7 +70,4628 @@ IP Access Management allows you to control which IP addresses can be used to acc For more information, please see our [User Guide](http://sendgrid.com/docs/User_Guide/Settings/ip_access_management.html). -### POST /access_settings/whitelist +This documentation is based on our OAI specification. + +INITIALIZATION + + +import sendgrid +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) +Table of Contents + +ACCESS SETTINGS + +ALERTS + +API KEYS + +ASM + +BROWSERS + +CAMPAIGNS + +CATEGORIES + +CLIENTS + +CONTACTDB + +DEVICES + +GEO + +IPS + +MAIL + +MAIL SETTINGS + +MAILBOX PROVIDERS + +PARTNER SETTINGS + +SCOPES + +SENDERS + +STATS + +SUBUSERS + +SUPPRESSION + +TEMPLATES + +TRACKING SETTINGS + +USER + +WHITELABEL + + + +ACCESS SETTINGS + +Retrieve all recent access attempts + +This endpoint allows you to retrieve a list of all of the IP addresses that recently attempted to access your account either through the User Interface or the API. + +IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account. + +For more information, please see our User Guide. + +GET /access_settings/activity + + +params = {'limit': 1} +response = sg.client.access_settings.activity.get(query_params=params) +print response.status_code +print response.body +print response.headers +Add one or more IPs to the whitelist + +This endpoint allows you to add one or more IP addresses to your IP whitelist. + +When adding an IP to your whitelist, include the IP address in an array. You can whitelist one IP at a time, or you can whitelist multiple IPs at once. + +IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account. + +For more information, please see our User Guide. + +POST /access_settings/whitelist + + +data = { + "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 +print response.body +print response.headers +Retrieve a list of currently whitelisted IPs + +This endpoint allows you to retrieve a list of IP addresses that are currently whitelisted. + +IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account. + +For more information, please see our User Guide. + +GET /access_settings/whitelist + + +response = sg.client.access_settings.whitelist.get() +print response.status_code +print response.body +print response.headers +Remove one or more IPs from the whitelist + +This endpoint allows you to remove one or more IPs from your IP whitelist. + +You can remove one IP at a time, or you can remove multiple IP addresses. + +IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account. + +For more information, please see our User Guide. + +DELETE /access_settings/whitelist + + +data = { + "ids": [ +​ 1, +​ 2, +​ 3 + ] +} +response = sg.client.access_settings.whitelist.delete(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve a specific whitelisted IP + +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. + +IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account. + +For more information, please see our User Guide. + +GET /access_settings/whitelist/{rule_id} + + +rule_id = "test_url_param" +response = sg.client.access_settings.whitelist._(rule_id).get() +print response.status_code +print response.body +print response.headers +Remove a specific IP from the whitelist + +This endpoint allows you to remove a specific IP address from your IP whitelist. + +When removing a specific IP address from your whitelist, you must include the ID in your call. + +IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account. + +For more information, please see our User Guide. + +DELETE /access_settings/whitelist/{rule_id} + + +rule_id = "test_url_param" +response = sg.client.access_settings.whitelist._(rule_id).delete() +print response.status_code +print response.body +print response.headers + + +ALERTS + +Create a new Alert + +This endpoint allows you to create a new alert. + +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. + +Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly". + +For more information about alerts, please see our User Guide. + +POST /alerts + + +data = { + "email_to": "example@example.com", + "frequency": "daily", + "type": "stats_notification" +} +response = sg.client.alerts.post(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve all alerts + +GET /alerts + + +response = sg.client.alerts.get() +print response.status_code +print response.body +print response.headers +Update an alert + +This endpoint allows you to update an alert. + +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. + +Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly". + +For more information about alerts, please see our User Guide. + +PATCH /alerts/{alert_id} + + +data = { + "email_to": "example@example.com" +} +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 +Retrieve a specific alert + +This endpoint allows you to retrieve a specific alert. + +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. + +Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly". + +For more information about alerts, please see our User Guide. + +GET /alerts/{alert_id} + + +alert_id = "test_url_param" +response = sg.client.alerts._(alert_id).get() +print response.status_code +print response.body +print response.headers +Delete an alert + +This endpoint allows you to delete an alert. + +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. + +Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly". + +For more information about alerts, please see our User Guide. + +DELETE /alerts/{alert_id} + + +alert_id = "test_url_param" +response = sg.client.alerts._(alert_id).delete() +print response.status_code +print response.body +print response.headers + + +API KEYS + +Create API keys + +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. + +There is a limit of 100 API Keys on your account. + +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. + +See the API Key Permissions List for a list of all available scopes. + +POST /api_keys + + +data = { + "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 +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 generate an API Key credential which can be used for authentication with the SendGrid v3 Web API or the Mail API Endpoint. + +GET /api_keys + + +params = {'limit': 1} +response = sg.client.api_keys.get(query_params=params) +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. + +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. + +PUT /api_keys/{api_key_id} + + +data = { + "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) +print response.status_code +print response.body +print response.headers +Update API keys + +This endpoint allows you to update the name of an existing API Key. + +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. + +URI Parameters + +URI PARAMETER TYPE REQUIRED? DESCRIPTION +api_key_id string required The ID of the API Key you are updating. +PATCH /api_keys/{api_key_id} + + +data = { + "name": "A New Hope" +} +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 +Retrieve an existing 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. + +GET /api_keys/{api_key_id} + + +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 +Delete API keys + +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 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. + +URI Parameters + +URI PARAMETER TYPE REQUIRED? DESCRIPTION +api_key_id string required The ID of the API Key you are deleting. +DELETE /api_keys/{api_key_id} + + +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 + + +ASM + +Create a new suppression group + +This endpoint allows you to create a new suppression group. + +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. + +Each user can create up to 25 different suppression groups. + +POST /asm/groups + + +data = { + "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 +print response.body +print response.headers +Retrieve information about multiple suppression groups + +This endpoint allows you to retrieve information about multiple suppression groups. + +This endpoint will return information for each group ID that you include in your request. To add a group ID to your request, simply append &id= followed by the group ID. + +Suppressions are a list of email addresses that will not receive content sent under a given group. + +Suppression groups, or unsubscribe groups, 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 + + +params = {'id': 1} +response = sg.client.asm.groups.get(query_params=params) +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 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. + +Each user can create up to 25 different suppression groups. + +PATCH /asm/groups/{group_id} + + +data = { + "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) +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 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. + +Each user can create up to 25 different suppression groups. + +GET /asm/groups/{group_id} + + +group_id = "test_url_param" +response = sg.client.asm.groups._(group_id).get() +print response.status_code +print response.body +print response.headers +Delete a suppression group. + +This endpoint allows you to delete a suppression group. + +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 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. + +Each user can create up to 25 different suppression groups. + +DELETE /asm/groups/{group_id} + + +group_id = "test_url_param" +response = sg.client.asm.groups._(group_id).delete() +print response.status_code +print response.body +print response.headers +Add suppressions to a suppression group + +This endpoint allows you to add email addresses to an unsubscribe group. + +If you attempt to add suppressions to a group that has been deleted or does not exist, the suppressions will be added to the global suppressions list. + +Suppressions are recipient email addresses that are added to unsubscribe groups. Once a recipient's address is on the suppressions list for an unsubscribe group, they will not receive any emails that are tagged with that unsubscribe group. + +POST /asm/groups/{group_id}/suppressions + + +data = { + "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) +print response.status_code +print response.body +print response.headers +Retrieve all suppressions for a suppression group + +This endpoint allows you to retrieve all suppressed email addresses belonging to the given group. + +Suppressions are recipient email addresses that are added to unsubscribe groups. Once a recipient's address is on the suppressions list for an unsubscribe group, they will not receive any emails that are tagged with that unsubscribe group. + +GET /asm/groups/{group_id}/suppressions + + +group_id = "test_url_param" +response = sg.client.asm.groups._(group_id).suppressions.get() +print response.status_code +print response.body +print response.headers +Search for suppressions within a group + +This endpoint allows you to search a suppression group for multiple suppressions. + +When given a list of email addresses and a group ID, this endpoint will return only the email addresses that have been unsubscribed from the given group. + +Suppressions are a list of email addresses that will not receive content sent under a given group. + +POST /asm/groups/{group_id}/suppressions/search + + +data = { + "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) +print response.status_code +print response.body +print response.headers +Delete a suppression from a suppression group + +This endpoint allows you to remove a suppressed email address from the given suppression group. + +Suppressions are recipient email addresses that are added to unsubscribe groups. Once a recipient's address is on the suppressions list for an unsubscribe group, they will not receive any emails that are tagged with that unsubscribe group. + +DELETE /asm/groups/{group_id}/suppressions/{email} + + +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 +Retrieve all suppressions + +This endpoint allows you to retrieve a list of all suppressions. + +Suppressions are a list of email addresses that will not receive content sent under a given group. + +GET /asm/suppressions + + +response = sg.client.asm.suppressions.get() +print response.status_code +print response.body +print response.headers +Add recipient addresses to the global suppression group. + +This endpoint allows you to add one or more email addresses to the global suppressions group. + +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. + +POST /asm/suppressions/global + + +data = { + "recipient_emails": [ +​ "test1@example.com", +​ "test2@example.com" + ] +} +response = sg.client.asm.suppressions._("global").post(request_body=data) +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 suppressed. + +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. + +GET /asm/suppressions/global/{email} + + +email = "test_url_param" +response = sg.client.asm.suppressions._("global")._(email).get() +print response.status_code +print response.body +print response.headers +Delete a Global Suppression + +This endpoint allows you to remove an email address from the global suppressions group. + +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. + +DELETE /asm/suppressions/global/{email} + + +email = "test_url_param" +response = sg.client.asm.suppressions._("global")._(email).delete() +print response.status_code +print response.body +print response.headers +Retrieve all suppression groups for an email address + +This endpoint returns the list of all groups that the given email address has been unsubscribed from. + +Suppressions are a list of email addresses that will not receive content sent under a given group. + +GET /asm/suppressions/{email} + + +email = "test_url_param" +response = sg.client.asm.suppressions._(email).get() +print response.status_code +print response.body +print response.headers + + +BROWSERS + +Retrieve email statistics by browser. + +This endpoint allows you to retrieve your email statistics segmented by browser type. + +We only store up to 7 days of email activity in our database. By default, 500 items will be returned per request via the Advanced Stats API endpoints. + +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. + +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'} +response = sg.client.browsers.stats.get(query_params=params) +print response.status_code +print response.body +print response.headers + + +CAMPAIGNS + +Create a Campaign + +This endpoint allows you to create a campaign. + +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. + +For more information: + +User Guide > Marketing Campaigns + +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" +} +response = sg.client.campaigns.post(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve all Campaigns + +This endpoint allows you to retrieve a list of all of your campaigns. + +Returns campaigns in reverse order they were created (newest first). + +Returns an empty array if no campaigns exist. + +For more information: + +User Guide > Marketing Campaigns + +GET /campaigns + + +params = {'limit': 10, 'offset': 0} +response = sg.client.campaigns.get(query_params=params) +print response.status_code +print response.body +print response.headers +Update a Campaign + +Update a campaign. This is especially useful if you only set up the campaign using POST /campaigns, but didn't set many of the parameters. + +For more information: + +User Guide > Marketing Campaigns + +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" +} +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 +Retrieve a single campaign + +This endpoint allows you to retrieve a specific campaign. + +Our Marketing Campaigns API lets you create, manage, send, and schedule campaigns. + +For more information: + +User Guide > Marketing Campaigns + +GET /campaigns/{campaign_id} + + +campaign_id = "test_url_param" +response = sg.client.campaigns._(campaign_id).get() +print response.status_code +print response.body +print response.headers +Delete a Campaign + +This endpoint allows you to delete a specific campaign. + +Our Marketing Campaigns API lets you create, manage, send, and schedule campaigns. + +For more information: + +User Guide > Marketing Campaigns + +DELETE /campaigns/{campaign_id} + + +campaign_id = "test_url_param" +response = sg.client.campaigns._(campaign_id).delete() +print response.status_code +print response.body +print response.headers +Update a Scheduled Campaign + +This endpoint allows to you change the scheduled time and date for a campaign to be sent. + +For more information: + +User Guide > Marketing Campaigns + +PATCH /campaigns/{campaign_id}/schedules + + +data = { + "send_at": 1489451436 +} +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 +Schedule a Campaign + +This endpoint allows you to schedule a specific date and time for your campaign to be sent. + +For more information: + +User Guide > Marketing Campaigns + +POST /campaigns/{campaign_id}/schedules + + +data = { + "send_at": 1489771528 +} +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 +View Scheduled Time of a Campaign + +This endpoint allows you to retrieve the date and time that the given campaign has been scheduled to be sent. + +For more information: + +User Guide > Marketing Campaigns + +GET /campaigns/{campaign_id}/schedules + + +campaign_id = "test_url_param" +response = sg.client.campaigns._(campaign_id).schedules.get() +print response.status_code +print response.body +print response.headers +Unschedule a Scheduled Campaign + +This endpoint allows you to unschedule a campaign that has already been scheduled to be sent. + +A successful unschedule will return a 204. +If the specified campaign is in the process of being sent, the only option is to cancel (a different method). + +For more information: + +User Guide > Marketing Campaigns + +DELETE /campaigns/{campaign_id}/schedules + + +campaign_id = "test_url_param" +response = sg.client.campaigns._(campaign_id).schedules.delete() +print response.status_code +print response.body +print response.headers +Send a Campaign + +This endpoint allows you to immediately send a campaign at the time you make the API call. + +Normally a POST would have a request body, but since this endpoint is telling us to send a resource that is already created, a request body is not needed. + +For more information: + +User Guide > Marketing Campaigns + +POST /campaigns/{campaign_id}/schedules/now + + +campaign_id = "test_url_param" +response = sg.client.campaigns._(campaign_id).schedules.now.post() +print response.status_code +print response.body +print response.headers +Send a Test Campaign + +This endpoint allows you to send a test campaign. + +To send to multiple addresses, use an array for the JSON "to" value ["one@address","two@address"] + +For more information: + +User Guide > Marketing Campaigns + +POST /campaigns/{campaign_id}/schedules/test + + +data = { + "to": "your.email@example.com" +} +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 + + +CATEGORIES + +Retrieve all categories + +This endpoint allows you to retrieve a list of all of your categories. + +Categories can help organize your email analytics by enabling you to tag emails by type or broad topic. You can define your own custom categories. For more information, please see our User Guide. + +GET /categories + + +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 +Retrieve Email Statistics for Categories + +This endpoint allows you to retrieve all of your email statistics for each of your categories. + +If you do not define any query parameters, this endpoint will return a sum for each category in groups of 10. + +Categories allow you to group your emails together according to broad topics that you define. For more information, please see our User Guide. + +GET /categories/stats + + +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 +Retrieve sums of email stats for each category [Needs: Stats object defined, has category ID?] + +This endpoint allows you to retrieve the total sum of each email statistic for every category over the given date range. + +If you do not define any query parameters, this endpoint will return a sum for each category in groups of 10. + +Categories allow you to group your emails together according to broad topics that you define. For more information, please see our User Guide. + +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'} +response = sg.client.categories.stats.sums.get(query_params=params) +print response.status_code +print response.body +print response.headers + + +CLIENTS + +Retrieve email statistics by client type. + +This endpoint allows you to retrieve your email statistics segmented by client type. + +We only store up to 7 days of email activity in our database. By default, 500 items will be returned per request via the Advanced Stats API endpoints. + +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. + +GET /clients/stats + + +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 +Retrieve stats by a specific client type. + +This endpoint allows you to retrieve your email statistics segmented by a specific client type. + +We only store up to 7 days of email activity in our database. By default, 500 items will be returned per request via the Advanced Stats API endpoints. + +Available Client Types + +phone + +tablet + +webmail + +desktop + +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. + +GET /clients/{client_type}/stats + + +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 + + +CONTACTDB + +Create a Custom Field + +This endpoint allows you to create a custom field. + +The contactdb is a database of your contacts for SendGrid Marketing Campaigns. + +POST /contactdb/custom_fields + + +data = { + "name": "pet", + "type": "text" +} +response = sg.client.contactdb.custom_fields.post(request_body=data) +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. + +GET /contactdb/custom_fields + + +response = sg.client.contactdb.custom_fields.get() +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. + +GET /contactdb/custom_fields/{custom_field_id} + + +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 +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. + +DELETE /contactdb/custom_fields/{custom_field_id} + + +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 +Create a List + +This endpoint allows you to create a list for your recipients. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +POST /contactdb/lists + + +data = { + "name": "your list name" +} +response = sg.client.contactdb.lists.post(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve all lists + +This endpoint allows you to retrieve all of your recipient lists. If you don't have any lists, an empty array will be returned. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +GET /contactdb/lists + + +response = sg.client.contactdb.lists.get() +print response.status_code +print response.body +print response.headers +Delete Multiple lists + +This endpoint allows you to delete multiple recipient lists. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +DELETE /contactdb/lists + + +data = [ + 1, + 2, + 3, + 4 +] +response = sg.client.contactdb.lists.delete(request_body=data) +print response.status_code +print response.body +print response.headers +Update a List + +This endpoint allows you to update the name of one of your recipient lists. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +PATCH /contactdb/lists/{list_id} + + +data = { + "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) +print response.status_code +print response.body +print response.headers +Retrieve a single list + +This endpoint allows you to retrieve a single recipient list. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +GET /contactdb/lists/{list_id} + + +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 +Delete a List + +This endpoint allows you to delete a specific recipient list with the given ID. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +DELETE /contactdb/lists/{list_id} + + +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 +Add Multiple Recipients to a List + +This endpoint allows you to add multiple recipients to a list. + +Adds existing recipients to a list, passing in the recipient IDs to add. Recipient IDs should be passed exactly as they are returned from recipient endpoints. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +POST /contactdb/lists/{list_id}/recipients + + +data = [ + "recipient_id1", + "recipient_id2" +] +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 +Retrieve all recipients on a List + +This endpoint allows you to retrieve all recipients on the list with the given ID. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +GET /contactdb/lists/{list_id}/recipients + + +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 +Add a Single Recipient to a List + +This endpoint allows you to add a single recipient to a list. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +POST /contactdb/lists/{list_id}/recipients/{recipient_id} + + +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 +Delete a Single Recipient from a Single List + +This endpoint allows you to delete a single recipient from a list. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +DELETE /contactdb/lists/{list_id}/recipients/{recipient_id} + + +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 +Update Recipient + +This endpoint allows you to update one or more recipients. + +The body of an API call to this endpoint must include an array of one or more recipient objects. + +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. + +PATCH /contactdb/recipients + + +data = [ + { +​ "email": "jones@example.com", +​ "first_name": "Guy", +​ "last_name": "Jones" + } +] +response = sg.client.contactdb.recipients.patch(request_body=data) +print response.status_code +print response.body +print response.headers +Add recipients + +This endpoint allows you to add a Marketing Campaigns recipient. + +It is of note that you can add custom field data as a parameter on this endpoint. We have provided an example using some of the default custom fields SendGrid provides. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +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" + } +] +response = sg.client.contactdb.recipients.post(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve recipients + +This endpoint allows you to retrieve all of your Marketing Campaigns recipients. + +Batch deletion of a page makes it possible to receive an empty page of recipients before reaching the end of +the list of recipients. To avoid this issue; iterate over pages until a 404 is retrieved. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +GET /contactdb/recipients + + +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 +Delete Recipient + +This endpoint allows you to deletes 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. + +DELETE /contactdb/recipients + + +data = [ + "recipient_id1", + "recipient_id2" +] +response = sg.client.contactdb.recipients.delete(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve the count of billable recipients + +This endpoint allows you to retrieve the number of Marketing Campaigns recipients that you will be billed for. + +You are billed for marketing campaigns based on the highest number of recipients you have had in your account at one time. This endpoint will allow you to know the current billable count value. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +GET /contactdb/recipients/billable_count + + +response = sg.client.contactdb.recipients.billable_count.get() +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. + +GET /contactdb/recipients/count + + +response = sg.client.contactdb.recipients.count.get() +print response.status_code +print response.body +print response.headers +Retrieve recipients matching search criteria + +This endpoint allows you to perform a search on all of your Marketing Campaigns recipients. + +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) + +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. + +GET /contactdb/recipients/search + + +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 +Retrieve a single recipient + +This endpoint allows you to retrieve a single recipient by ID from your contact database. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +GET /contactdb/recipients/{recipient_id} + + +recipient_id = "test_url_param" +response = sg.client.contactdb.recipients._(recipient_id).get() +print response.status_code +print response.body +print response.headers +Delete a Recipient + +This endpoint allows you to delete a single recipient with the given ID from your contact database. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +DELETE /contactdb/recipients/{recipient_id} + + +recipient_id = "test_url_param" +response = sg.client.contactdb.recipients._(recipient_id).delete() +print response.status_code +print response.body +print response.headers +Retrieve the lists that a recipient is on + +This endpoint allows you to retrieve the lists that a given recipient belongs to. + +Each recipient can be on many lists. This endpoint gives you all of the lists that any one recipient has been added to. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +GET /contactdb/recipients/{recipient_id}/lists + + +recipient_id = "test_url_param" +response = sg.client.contactdb.recipients._(recipient_id).lists.get() +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. + +GET /contactdb/reserved_fields + + +response = sg.client.contactdb.reserved_fields.get() +print response.status_code +print response.body +print response.headers +Create a Segment + +This endpoint allows you to create a segment. + +All recipients in your contactdb will be added or removed automatically depending on whether they match the criteria for this segment. + +List Id: + +Send this to segment from an existing list + +Don't send this in order to segment from your entire contactdb. + +Valid operators for create and update depend on the type of the field you are segmenting: + +Dates: "eq", "ne", "lt" (before), "gt" (after) + +Text: "contains", "eq" (is - matches the full field), "ne" (is not - matches any field where the entire field is not the condition value) + +Numbers: "eq", "lt", "gt" + +Email Clicks and Opens: "eq" (opened), "ne" (not opened) + +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 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 recipients. + +For more information about segments in Marketing Campaigns, please see our User Guide. + +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" +} +response = sg.client.contactdb.segments.post(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve all segments + +This endpoint allows you to retrieve all of your segments. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +For more information about segments in Marketing Campaigns, please see our User Guide. + +GET /contactdb/segments + + +response = sg.client.contactdb.segments.get() +print response.status_code +print response.body +print response.headers +Update a segment + +This endpoint allows you to update a segment. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +For more information about segments in Marketing Campaigns, please see our User Guide. + +PATCH /contactdb/segments/{segment_id} + + +data = { + "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) +print response.status_code +print response.body +print response.headers +Retrieve a segment + +This endpoint allows you to retrieve a single segment with the given ID. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +For more information about segments in Marketing Campaigns, please see our User Guide. + +GET /contactdb/segments/{segment_id} + + +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 +Delete a segment + +This endpoint allows you to delete a segment from your recipients database. + +You also have the option to delete all the contacts from your Marketing Campaigns recipient database who were in this segment. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +For more information about segments in Marketing Campaigns, please see our User Guide. + +DELETE /contactdb/segments/{segment_id} + + +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 +Retrieve recipients on a segment + +This endpoint allows you to retrieve all of the recipients in a segment with the given ID. + +The Contacts API helps you manage your Marketing Campaigns recipients. + +For more information about segments in Marketing Campaigns, please see our User Guide. + +GET /contactdb/segments/{segment_id}/recipients + + +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 + + +DEVICES + +Retrieve email statistics by device type. + +This endpoint allows you to retrieve your email statistics segmented by the device type. + +We only store up to 7 days of email activity in our database. By default, 500 items will be returned per request via the Advanced Stats API endpoints. + +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. | +| 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. + +GET /devices/stats + + +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 + + +GEO + +Retrieve email statistics by country and state/province. + +This endpoint allows you to retrieve your email statistics segmented by country and state/province. + +We only store up to 7 days of email activity in our database. By default, 500 items will be returned per request via the Advanced Stats API endpoints. + +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. + +GET /geo/stats + + +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 + + +IPS + +Retrieve all IP addresses + +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. + +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. + +GET /ips + + +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 +Retrieve all assigned IPs + +This endpoint allows you to retrieve only assigned IP addresses. + +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. + +GET /ips/assigned + + +response = sg.client.ips.assigned.get() +print response.status_code +print response.body +print response.headers +Create an IP pool. + +This endpoint allows you to create an IP pool. + +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 can only be used with whitelabeled IP addresses. + +If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. + +POST /ips/pools + + +data = { + "name": "marketing" +} +response = sg.client.ips.pools.post(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve all 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. + +If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. + +GET /ips/pools + + +response = sg.client.ips.pools.get() +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 can only be used with whitelabeled IP addresses. + +If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. + +PUT /ips/pools/{pool_name} + + +data = { + "name": "new_pool_name" +} +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 +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 can only be used with whitelabeled IP addresses. + +If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. + +GET /ips/pools/{pool_name} + + +pool_name = "test_url_param" +response = sg.client.ips.pools._(pool_name).get() +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 can only be used with whitelabeled IP addresses. + +If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. + +DELETE /ips/pools/{pool_name} + + +pool_name = "test_url_param" +response = sg.client.ips.pools._(pool_name).delete() +print response.status_code +print response.body +print response.headers +Add an IP address to a pool + +This endpoint allows you to add an IP address to an IP pool. + +You can add the same IP address to multiple pools. It may take up to 60 seconds for your IP address to be added to a pool after your request is made. + +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. + +POST /ips/pools/{pool_name}/ips + + +data = { + "ip": "0.0.0.0" +} +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 +Remove an IP address from a pool. + +This endpoint allows you to remove an IP address from an IP pool. + +The same IP address can be added to multiple IP pools. + +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. + +DELETE /ips/pools/{pool_name}/ips/{ip} + + +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 +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 for more details on how SendGrid limits your email traffic for IPs in warmup. + +For more general information about warming up IPs, please see our Classroom. + +POST /ips/warmup + + +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 +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 for more details on how SendGrid limits your email traffic for IPs in warmup. + +For more general information about warming up IPs, please see our Classroom. + +GET /ips/warmup + + +response = sg.client.ips.warmup.get() +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 for more details on how SendGrid limits your email traffic for IPs in warmup. + +For more general information about warming up IPs, please see our Classroom. + +GET /ips/warmup/{ip_address} + + +ip_address = "test_url_param" +response = sg.client.ips.warmup._(ip_address).get() +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 for more details on how SendGrid limits your email traffic for IPs in warmup. + +For more general information about warming up IPs, please see our Classroom. + +DELETE /ips/warmup/{ip_address} + + +ip_address = "test_url_param" +response = sg.client.ips.warmup._(ip_address).delete() +print response.status_code +print response.body +print response.headers +Retrieve all IP pools an IP address belongs to + +This endpoint allows you to see which IP pools a particular IP address has been added to. + +The same IP address can be added to multiple IP pools. + +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. + +GET /ips/{ip_address} + + +ip_address = "test_url_param" +response = sg.client.ips._(ip_address).get() +print response.status_code +print response.body +print response.headers + + +MAIL + +Create a batch ID + +This endpoint allows you to generate a new batch ID. This batch ID can be associated with scheduled sends via the mail/send endpoint. + +If you set the SMTPAPI header batch_id, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at anytime up to 10 minutes before the schedule date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint. + +More Information: + +Scheduling Parameters > Batch ID + +POST /mail/batch + + +response = sg.client.mail.batch.post() +print response.status_code +print response.body +print response.headers +Validate batch ID + +This endpoint allows you to validate a batch ID. + +If you set the SMTPAPI header batch_id, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at anytime up to 10 minutes before the schedule date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint. + +More Information: + +Scheduling Parameters > Batch ID + +GET /mail/batch/{batch_id} + + +batch_id = "test_url_param" +response = sg.client.mail.batch._(batch_id).get() +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. + +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. + +For an overview of the v3 Mail Send endpoint, please visit our v3 API Reference + +For more detailed information about how to use the v3 Mail Send endpoint, please visit our Classroom. + +POST /mail/send + +This endpoint has a helper, check it out here. + + +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": "

Thanks
The 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": [ +​ { +​ "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 %>." +​ } + } +} +response = sg.client.mail.send.post(request_body=data) +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 or SMTP Relay. + +GET /mail_settings + + +params = {'limit': 1, 'offset': 1} +response = sg.client.mail_settings.get(query_params=params) +print response.status_code +print response.body +print response.headers +Update address whitelist mail settings + +This endpoint allows you to update your current email address whitelist settings. + +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 or SMTP Relay. + +PATCH /mail_settings/address_whitelist + + +data = { + "enabled": True, + "list": [ +​ "email1@example.com", +​ "example.com" + ] +} +response = sg.client.mail_settings.address_whitelist.patch(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve address whitelist mail settings + +This endpoint allows you to retrieve your current email address whitelist settings. + +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 or SMTP Relay. + +GET /mail_settings/address_whitelist + + +response = sg.client.mail_settings.address_whitelist.get() +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. + +Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids Web API or SMTP Relay. + +PATCH /mail_settings/bcc + + +data = { + "email": "email@example.com", + "enabled": False +} +response = sg.client.mail_settings.bcc.patch(request_body=data) +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. + +Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids Web API or SMTP Relay. + +GET /mail_settings/bcc + + +response = sg.client.mail_settings.bcc.get() +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. + +Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids Web API or SMTP Relay. + +PATCH /mail_settings/bounce_purge + + +data = { + "enabled": True, + "hard_bounces": 5, + "soft_bounces": 5 +} +response = sg.client.mail_settings.bounce_purge.patch(request_body=data) +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. + +Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids Web API or SMTP Relay. + +GET /mail_settings/bounce_purge + + +response = sg.client.mail_settings.bounce_purge.get() +print response.status_code +print response.body +print response.headers +Update footer mail settings + +This endpoint allows you to update your current Footer mail settings. + +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 or SMTP Relay. + +PATCH /mail_settings/footer + + +data = { + "enabled": True, + "html_content": "...", + "plain_content": "..." +} +response = sg.client.mail_settings.footer.patch(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve footer mail settings + +This endpoint allows you to retrieve your current Footer mail settings. + +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 or SMTP Relay. + +GET /mail_settings/footer + + +response = sg.client.mail_settings.footer.get() +print response.status_code +print response.body +print response.headers +Update forward bounce mail settings + +This endpoint allows you to update your current bounce forwarding mail settings. + +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 or SMTP Relay. + +PATCH /mail_settings/forward_bounce + + +data = { + "email": "example@example.com", + "enabled": True +} +response = sg.client.mail_settings.forward_bounce.patch(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve forward bounce mail settings + +This endpoint allows you to retrieve your current bounce forwarding mail settings. + +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 or SMTP Relay. + +GET /mail_settings/forward_bounce + + +response = sg.client.mail_settings.forward_bounce.get() +print response.status_code +print response.body +print response.headers +Update forward spam mail settings + +This endpoint allows you to update your current Forward Spam mail settings. + +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 or SMTP Relay. + +PATCH /mail_settings/forward_spam + + +data = { + "email": "", + "enabled": False +} +response = sg.client.mail_settings.forward_spam.patch(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve forward spam mail settings + +This endpoint allows you to retrieve your current Forward Spam mail settings. + +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 or SMTP Relay. + +GET /mail_settings/forward_spam + + +response = sg.client.mail_settings.forward_spam.get() +print response.status_code +print response.body +print response.headers +Update plain content mail settings + +This endpoint allows you to update your current Plain Content mail settings. + +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 or SMTP Relay. + +PATCH /mail_settings/plain_content + + +data = { + "enabled": False +} +response = sg.client.mail_settings.plain_content.patch(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve plain content mail settings + +This endpoint allows you to retrieve your current Plain Content mail settings. + +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 or SMTP Relay. + +GET /mail_settings/plain_content + + +response = sg.client.mail_settings.plain_content.get() +print response.status_code +print response.body +print response.headers +Update spam check mail settings + +This endpoint allows you to update your current spam checker mail settings. + +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 or SMTP Relay. + +PATCH /mail_settings/spam_check + + +data = { + "enabled": True, + "max_score": 5, + "url": "url" +} +response = sg.client.mail_settings.spam_check.patch(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve spam check mail settings + +This endpoint allows you to retrieve your current Spam Checker mail settings. + +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 or SMTP Relay. + +GET /mail_settings/spam_check + + +response = sg.client.mail_settings.spam_check.get() +print response.status_code +print response.body +print response.headers +Update template mail settings + +This endpoint allows you to update your current legacy email template settings. + +This setting refers to our original email templates. We currently support more fully featured transactional templates. + +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 or SMTP Relay. + +PATCH /mail_settings/template + + +data = { + "enabled": True, + "html_content": "<% body %>" +} +response = sg.client.mail_settings.template.patch(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve legacy template mail settings + +This endpoint allows you to retrieve your current legacy email template settings. + +This setting refers to our original email templates. We currently support more fully featured transactional templates. + +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 or SMTP Relay. + +GET /mail_settings/template + + +response = sg.client.mail_settings.template.get() +print response.status_code +print response.body +print response.headers + + +MAILBOX PROVIDERS + +Retrieve email statistics by mailbox provider. + +This endpoint allows you to retrieve your email statistics segmented by recipient mailbox provider. + +We only store up to 7 days of email activity in our database. By default, 500 items will be returned per request via the Advanced Stats API endpoints. + +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. + +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'} +response = sg.client.mailbox_providers.stats.get(query_params=params) +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. + +GET /partner_settings + + +params = {'limit': 1, 'offset': 1} +response = sg.client.partner_settings.get(query_params=params) +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. + +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. + +PATCH /partner_settings/new_relic + + +data = { + "enable_subuser_statistics": True, + "enabled": True, + "license_key": "" +} +response = sg.client.partner_settings.new_relic.patch(request_body=data) +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. + +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. + +GET /partner_settings/new_relic + + +response = sg.client.partner_settings.new_relic.get() +print response.status_code +print response.body +print response.headers + + +SCOPES + +Retrieve a list of scopes for which this user has access. + +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, or the Mail API Endpoint. 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 or Classroom. + +GET /scopes + + +response = sg.client.scopes.get() +print response.status_code +print response.body +print response.headers + + +SENDERS + +Create a Sender Identity + +This endpoint allows you to create a new sender identity. + +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. + +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" +} +response = sg.client.senders.post(request_body=data) +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. + +GET /senders + + +response = sg.client.senders.get() +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. + +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. + +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" +} +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 +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. + +GET /senders/{sender_id} + + +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).get() +print response.status_code +print response.body +print response.headers +Delete a Sender Identity + +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. + +DELETE /senders/{sender_id} + + +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).delete() +print response.status_code +print response.body +print response.headers +Resend Sender Identity Verification + +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. + +POST /senders/{sender_id}/resend_verification + + +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).resend_verification.post() +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 + + +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 Subuser + +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 + +Classroom > How do I add more subusers to my account? + +POST /subusers + + +data = { + "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 +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 + +Classroom > How do I add more subusers to my account? + +GET /subusers + + +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 + +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. + +GET /subusers/reputations + + +params = {'usernames': 'test_string'} +response = sg.client.subusers.reputations.get(query_params=params) +print response.status_code +print response.body +print response.headers +Retrieve email statistics for your subusers. + +This endpoint allows you to retrieve the email statistics for the given subusers. + +You may retrieve statistics for up to 10 different subusers by including an additional subusers parameter for each additional 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. 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. + +GET /subusers/stats + + +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 +Retrieve monthly stats for all subusers + +This endpoint allows you to retrieve the monthly email statistics for all subusers over the given date range. + +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. + +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. + +GET /subusers/stats/monthly + + +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 +Retrieve the totals for each email statistic metric for all subusers. + +This endpoint allows you to retrieve the total sums of each email statistic metric for all subusers over the given date range. + +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. + +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'} +response = sg.client.subusers.stats.sums.get(query_params=params) +print response.status_code +print response.body +print response.headers +Enable/disable a subuser + +This endpoint allows you to enable or disable a subuser. + +For more information about Subusers: + +User Guide > Subusers + +Classroom > How do I add more subusers to my account? + +PATCH /subusers/{subuser_name} + + +data = { + "disabled": 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 +Delete a subuser + +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 Subusers: + +User Guide > Subusers + +Classroom > How do I add more subusers to my account? + +DELETE /subusers/{subuser_name} + + +subuser_name = "test_url_param" +response = sg.client.subusers._(subuser_name).delete() +print response.status_code +print response.body +print response.headers +Update IPs assigned to a subuser + +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. + +More information: + +How to request more IPs + +IPs can be whitelabeled + +PUT /subusers/{subuser_name}/ips + + +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 +Update Monitor Settings for a subuser + +Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails. + +PUT /subusers/{subuser_name}/monitor + + +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 + +Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails. + +POST /subusers/{subuser_name}/monitor + + +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 +Retrieve monitor settings for a subuser + +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 + + +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 + +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 + + +subuser_name = "test_url_param" +response = sg.client.subusers._(subuser_name).monitor.delete() +print response.status_code +print response.body +print response.headers +Retrieve the monthly email statistics for a single subuser + +This endpoint allows you to retrieve the monthly email statistics for 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. + +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. + +GET /subusers/{subuser_name}/stats/monthly + + +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 + + +SUPPRESSION + +Retrieve all blocks + +This endpoint allows you to retrieve a list of all email addresses that are currently on your blocks list. + +Blocks 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. + +GET /suppression/blocks + + +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 +Delete blocks + +This endpoint allows you to delete all email addresses on your blocks list. + +There are two options for deleting blocked emails: + +You can delete all blocked emails by setting delete_all to true in the request body. + +You can delete some blocked emails by specifying the email addresses in an array in the request body. + +Blocks 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. + +DELETE /suppression/blocks + + +data = { + "delete_all": False, + "emails": [ +​ "example1@example.com", +​ "example2@example.com" + ] +} +response = sg.client.suppression.blocks.delete(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. + +Blocks 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. + +GET /suppression/blocks/{email} + + +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 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. + +DELETE /suppression/blocks/{email} + + +email = "test_url_param" +response = sg.client.suppression.blocks._(email).delete() +print response.status_code +print response.body +print response.headers +Retrieve all bounces + +This endpoint allows you to retrieve all of your bounces. + +Bounces are messages that are returned to the server that sent it. + +For more information see: + +User Guide > Bounces for more information + +Glossary > Bounces + +GET /suppression/bounces + + +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 for more information + +Glossary > Bounces + +Classroom > List Scrubbing Guide + +Note: the delete_all and emails parameters should be used independently of each other as they have different purposes. + +DELETE /suppression/bounces + + +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 +Retrieve a Bounce + +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. + +For more information see: + +User Guide > Bounces for more information + +Glossary > Bounces + +Classroom > List Scrubbing Guide + +GET /suppression/bounces/{email} + + +email = "test_url_param" +response = sg.client.suppression.bounces._(email).get() +print response.status_code +print response.body +print response.headers +Delete a bounce + +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 address from your bounce list. + +For more information see: + +User Guide > Bounces for more information + +Glossary > Bounces + +Classroom > List Scrubbing Guide + +DELETE /suppression/bounces/{email} + + +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 all invalid emails + +This endpoint allows you to retrieve a list of all invalid email addresses. + +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. + +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. + +GET /suppression/invalid_emails + + +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 +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: + +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. + +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. + +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. + +DELETE /suppression/invalid_emails + + +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 a specific invalid email + +This endpoint allows you to retrieve a specific invalid email addresses. + +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. + +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. + +GET /suppression/invalid_emails/{email} + + +email = "test_url_param" +response = sg.client.suppression.invalid_emails._(email).get() +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. + +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. + +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. + +DELETE /suppression/invalid_emails/{email} + + +email = "test_url_param" +response = sg.client.suppression.invalid_emails._(email).delete() +print response.status_code +print response.body +print response.headers +Retrieve a specific spam report + +This endpoint allows you to retrieve a specific spam report. + +Spam reports happen when a recipient indicates that they think your email is spam and then their email provider reports this to SendGrid. + +For more information, please see our User Guide. + +GET /suppression/spam_report/{email} + + +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 + +This endpoint allows you to delete a specific spam report. + +Spam reports happen when a recipient indicates that they think your email is spam and then their email provider reports this to SendGrid. + +For more information, please see our User Guide. + +DELETE /suppression/spam_report/{email} + + +email = "test_url_param" +response = sg.client.suppression.spam_report._(email).delete() +print response.status_code +print response.body +print response.headers +Retrieve all spam reports + +This endpoint allows you to retrieve all spam reports. + +Spam reports happen when a recipient indicates that they think your email is spam and then their email provider reports this to SendGrid. + +For more information, please see our User Guide. + +GET /suppression/spam_reports + + +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 +Delete spam reports + +This endpoint allows you to delete your spam reports. + +There are two options for deleting spam reports: + +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. + +Spam reports happen when a recipient indicates that they think your email is spam and then their email provider reports this to SendGrid. + +For more information, please see our User Guide. + +DELETE /suppression/spam_reports + + +data = { + "delete_all": False, + "emails": [ +​ "example1@example.com", +​ "example2@example.com" + ] +} +response = sg.client.suppression.spam_reports.delete(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. + +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. + +GET /suppression/unsubscribes + + +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 + + +TEMPLATES + +Create a transactional template. + +This endpoint allows you to create 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. + +Transactional templates are templates created specifically for transactional email and are not to be confused with Marketing Campaigns templates. For more information about transactional templates, please see our User Guide. + +POST /templates + + +data = { + "name": "example_name" +} +response = sg.client.templates.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. + +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. + +Transactional templates are templates created specifically for transactional email and are not to be confused with Marketing Campaigns templates. For more information about transactional templates, please see our User Guide. + +GET /templates + + +response = sg.client.templates.get() +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. + +Transactional templates are templates created specifically for transactional email and are not to be confused with Marketing Campaigns templates. For more information about transactional templates, please see our User Guide. + +PATCH /templates/{template_id} + + +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 +Retrieve a single transactional template. + +This endpoint allows you to retrieve a single 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. + +Transactional templates are templates created specifically for transactional email and are not to be confused with Marketing Campaigns templates. For more information about transactional templates, please see our User Guide. + +GET /templates/{template_id} + + +template_id = "test_url_param" +response = sg.client.templates._(template_id).get() +print response.status_code +print response.body +print response.headers +Delete a template. + +This endpoint allows you to delete 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. + +Transactional templates are templates created specifically for transactional email and are not to be confused with Marketing Campaigns templates. For more information about transactional templates, please see our User Guide. + +DELETE /templates/{template_id} + + +template_id = "test_url_param" +response = sg.client.templates._(template_id).delete() +print response.status_code +print response.body +print response.headers +Create a new transactional template version. + +This endpoint allows you to create a new version of a template. + +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. + +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" +} +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 +Edit a transactional template version. + +This endpoint allows you to edit a version of one of your transactional templates. + +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. + +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 /templates/{template_id}/versions/{version_id} + + +data = { + "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) +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. + +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. + +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 /templates/{template_id}/versions/{version_id} + + +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 +Delete a transactional template version. + +This endpoint allows you to delete one of your transactional template versions. + +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. + +URI Parameters + +URI PARAMETER TYPE DESCRIPTION +template_id string The ID of the original template +version_id string The ID of the template version +DELETE /templates/{template_id}/versions/{version_id} + + +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 +Activate a transactional template version. + +This endpoint allows you to activate a version of one of your templates. + +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. + +URI Parameters + +URI PARAMETER TYPE DESCRIPTION +template_id string The ID of the original template +version_id string The ID of the template version +POST /templates/{template_id}/versions/{version_id}/activate + + +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 + + +TRACKING SETTINGS + +Retrieve Tracking Settings + +This endpoint allows you to retrieve a list of all tracking settings that you can enable on your account. + +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. + +GET /tracking_settings + + +params = {'limit': 1, 'offset': 1} +response = sg.client.tracking_settings.get(query_params=params) +print response.status_code +print response.body +print response.headers +Update Click Tracking Settings + +This endpoint allows you to change your current click tracking setting. You can enable, or disable, click tracking using this endpoint. + +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. + +PATCH /tracking_settings/click + + +data = { + "enabled": True +} +response = sg.client.tracking_settings.click.patch(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve Click Track Settings + +This endpoint allows you to retrieve your current click tracking 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. + +For more information about tracking, please see our User Guide. + +GET /tracking_settings/click + + +response = sg.client.tracking_settings.click.get() +print response.status_code +print response.body +print response.headers +Update Google Analytics Settings + +This endpoint allows you to update your current setting for Google Analytics. + +For more information about using Google Analytics, please refer to Googles URL Builder and their article on "Best Practices for Campaign Building". + +We default the settings to Googles recommendations. For more information, see Google Analytics Demystified. + +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. + +PATCH /tracking_settings/google_analytics + + +data = { + "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) +print response.status_code +print response.body +print response.headers +Retrieve Google Analytics Settings + +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 and their article on "Best Practices for Campaign Building". + +We default the settings to Googles recommendations. For more information, see Google Analytics Demystified. + +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. + +GET /tracking_settings/google_analytics + + +response = sg.client.tracking_settings.google_analytics.get() +print response.status_code +print response.body +print response.headers +Update Open Tracking Settings + +This endpoint allows you to update your current settings for open tracking. + +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. + +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. + +PATCH /tracking_settings/open + + +data = { + "enabled": True +} +response = sg.client.tracking_settings.open.patch(request_body=data) +print response.status_code +print response.body +print response.headers +Get Open Tracking Settings + +This endpoint allows you to retrieve your current settings for open tracking. + +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. + +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. + +GET /tracking_settings/open + + +response = sg.client.tracking_settings.open.get() +print response.status_code +print response.body +print response.headers +Update Subscription Tracking Settings + +This endpoint allows you to update your current settings for subscription tracking. + +Subscription tracking adds links to the bottom of your emails that allows your recipients to subscribe to, or unsubscribe from, your emails. + +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. + +PATCH /tracking_settings/subscription + + +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 +Retrieve Subscription Tracking Settings + +This endpoint allows you to retrieve your current settings for subscription tracking. + +Subscription tracking adds links to the bottom of your emails that allows your recipients to subscribe to, or unsubscribe from, your emails. + +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. + +GET /tracking_settings/subscription + + +response = sg.client.tracking_settings.subscription.get() +print response.status_code +print response.body +print response.headers + + +USER + +Get a user's account information. + +This endpoint allows you to retrieve your user account details. + +Your user's account information includes the user's account type and reputation. + +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. + +For more information about your user profile: + +SendGrid Account Settings + +GET /user/account + + +response = sg.client.user.account.get() +print response.status_code +print response.body +print response.headers +Retrieve your credit balance + +This endpoint allows you to retrieve the current credit balance for your account. + +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. + +GET /user/credits + + +response = sg.client.user.credits.get() +print response.status_code +print response.body +print response.headers +Update your account email address + +This endpoint allows you to update the email address currently on file for your account. + +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. + +For more information about your user profile: + +SendGrid Account Settings + +PUT /user/email + + +data = { + "email": "example@example.com" +} +response = sg.client.user.email.put(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve your account email address + +This endpoint allows you to retrieve the email address currently on file for your account. + +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. + +For more information about your user profile: + +SendGrid Account Settings + +GET /user/email + + +response = sg.client.user.email.get() +print response.status_code +print response.body +print response.headers +Update your password + +This endpoint allows you to update your password. + +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. + +For more information about your user profile: + +SendGrid Account Settings + +PUT /user/password + + +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 +Update a user's profile + +This endpoint allows you to update your current profile details. + +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. + +For more information about your user profile: + +SendGrid Account Settings + +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. + +PATCH /user/profile + + +data = { + "city": "Orange", + "first_name": "Example", + "last_name": "User" +} +response = sg.client.user.profile.patch(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. + +For more information about your user profile: + +SendGrid Account Settings + +GET /user/profile + + +response = sg.client.user.profile.get() +print response.status_code +print response.body +print response.headers +Cancel or pause a scheduled send + +This endpoint allows you to cancel or pause an email that has been scheduled to be sent. + +If the maximum number of cancellations/pauses are added, HTTP 400 will +be returned. + +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 /user/scheduled_sends + + +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 +Retrieve all scheduled sends + +This endpoint allows you to retrieve all cancel/paused scheduled send information. + +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 + + +response = sg.client.user.scheduled_sends.get() +print response.status_code +print response.body +print response.headers +Update user scheduled send information + +This endpoint allows you to update the status of a scheduled send for the given 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. + +PATCH /user/scheduled_sends/{batch_id} + + +data = { + "status": "pause" +} +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 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} + + +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 + +This endpoint allows you to delete the cancellation/pause of a scheduled send. + +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} + + +batch_id = "test_url_param" +response = sg.client.user.scheduled_sends._(batch_id).delete() +print response.status_code +print response.body +print response.headers +Update Enforced TLS settings + +This endpoint allows you to update your current Enforced TLS settings. + +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 for more information on opportunistic TLS. + +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. + +PATCH /user/settings/enforced_tls + + +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 +Retrieve current Enforced TLS settings. + +This endpoint allows you to retrieve your current Enforced TLS settings. + +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 for more information on opportunistic TLS. + +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. + +GET /user/settings/enforced_tls + + +response = sg.client.user.settings.enforced_tls.get() +print response.status_code +print response.body +print response.headers +Update your username + +This endpoint allows you to update the username for your account. + +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. + +For more information about your user profile: + +SendGrid Account Settings + +PUT /user/username + + +data = { + "username": "test_username" +} +response = sg.client.user.username.put(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve your username + +This endpoint allows you to retrieve your current account username. + +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. + +For more information about your user profile: + +SendGrid Account Settings + +GET /user/username + + +response = sg.client.user.username.get() +print response.status_code +print response.body +print response.headers +Update Event Notification Settings + +This endpoint allows you to update your current event webhook settings. + +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. + +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. + +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" +} +response = sg.client.user.webhooks.event.settings.patch(request_body=data) +print response.status_code +print response.body +print response.headers +Retrieve Event Webhook settings + +This endpoint allows you to retrieve your current event webhook settings. + +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. + +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 /user/webhooks/event/settings + + +response = sg.client.user.webhooks.event.settings.get() +print response.status_code +print response.body +print response.headers +Test Event Notification Settings + +This endpoint allows you to test your event webhook by sending a fake event notification post to the provided URL. + +SendGrids Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as SendGrid processes your email. + +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. + +POST /user/webhooks/event/test + + +data = { + "url": "url" +} +response = sg.client.user.webhooks.event.test.post(request_body=data) +print response.status_code +print response.body +print response.headers +Create a parse setting + +This endpoint allows you to create a new inbound parse setting. + +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. + +POST /user/webhooks/parse/settings + + +data = { + "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 +print response.body +print response.headers +Retrieve all parse settings + +This endpoint allows you to retrieve all of your current inbound parse settings. + +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. + +GET /user/webhooks/parse/settings + + +response = sg.client.user.webhooks.parse.settings.get() +print response.status_code +print response.body +print response.headers +Update a parse setting + +This endpoint allows you to update a specific inbound parse setting. + +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. + +PATCH /user/webhooks/parse/settings/{hostname} + + +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 +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 content, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our User Guide. + +GET /user/webhooks/parse/settings/{hostname} + + +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 + +This endpoint allows you to delete a specific inbound parse setting. + +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. + +DELETE /user/webhooks/parse/settings/{hostname} + + +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. + +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 SendGrid Parse Webhook which make processing events easy. You can find these integrations in the Library Index. + +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'} +response = sg.client.user.webhooks.parse.stats.get(query_params=params) +print response.status_code +print response.body +print response.headers + + +WHITELABEL + +Create a domain whitelabel. + +This endpoint allows you to create a whitelabel for one of your domains. + +If you are creating a domain whitelabel that you would like a subuser to use, you have two options: + +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. + +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. + +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 on whitelabeling, please see our User Guide + +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" +} +response = sg.client.whitelabel.domains.post(request_body=data) +print response.status_code +print response.body +print response.headers +List all domain whitelabels. + +This endpoint allows you to retrieve a list of all domain whitelabels you have created. + +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 on whitelabeling, please see our User Guide + +GET /whitelabel/domains + + +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. + +This endpoint allows you to retrieve the default whitelabel for a domain. + +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 on whitelabeling, please see our User Guide + +URI Parameters + +URI PARAMETER TYPE DESCRIPTION +domain string The domain to find a default domain whitelabel for. +GET /whitelabel/domains/default + + +response = sg.client.whitelabel.domains.default.get() +print response.status_code +print response.body +print response.headers +List the domain whitelabel associated with the given user. + +This endpoint allows you to retrieve all of the whitelabels that have been assigned to a specific 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 parent may then associate the whitelabel via the subuser management tools. + +For more information on whitelabeling, please see our User Guide + +URI Parameters + +URI PARAMETER TYPE DESCRIPTION +username string Username of the subuser to find associated whitelabels for. +GET /whitelabel/domains/subuser + + +response = sg.client.whitelabel.domains.subuser.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 parent may then associate the whitelabel via the subuser management tools. + +For more information on whitelabeling, please see our User Guide + +URI Parameters + +URI PARAMETER TYPE REQUIRED? DESCRIPTION +username string required Username for the subuser to find associated whitelabels for. +DELETE /whitelabel/domains/subuser + + +response = sg.client.whitelabel.domains.subuser.delete() +print response.status_code +print response.body +print response.headers +Update a domain whitelabel. + +This endpoint allows you to update the settings for a domain whitelabel. + +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 on whitelabeling, please see our User Guide + +PATCH /whitelabel/domains/{domain_id} + + +data = { + "custom_spf": True, + "default": False +} +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 +Retrieve a domain whitelabel. + +This endpoint allows you to retrieve a specific domain whitelabel. + +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 on whitelabeling, please see our User Guide + +GET /whitelabel/domains/{domain_id} + + +domain_id = "test_url_param" +response = sg.client.whitelabel.domains._(domain_id).get() +print response.status_code +print response.body +print response.headers +Delete a domain whitelabel. + +This endpoint allows you to delete a domain whitelabel. + +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 on whitelabeling, please see our User Guide + +DELETE /whitelabel/domains/{domain_id} + + +domain_id = "test_url_param" +response = sg.client.whitelabel.domains._(domain_id).delete() +print response.status_code +print response.body +print response.headers +Associate a domain whitelabel with a given user. + +This endpoint allows you to associate a specific domain whitelabel with 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 parent may then associate the whitelabel via the subuser management tools. + +For more information on whitelabeling, please see our User Guide + +URI Parameters + +URI PARAMETER TYPE DESCRIPTION +domain_id integer ID of the domain whitelabel to associate with the subuser. +POST /whitelabel/domains/{domain_id}/subuser + + +data = { + "username": "jane@example.com" +} +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 +Add an IP to a domain whitelabel. + +This endpoint allows you to add an IP address to a domain whitelabel. + +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 on whitelabeling, please see our User Guide + +URI Parameters + +URI PARAMETER TYPE DESCRIPTION +id integer ID of the domain to which you are adding an IP +POST /whitelabel/domains/{id}/ips + + +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 +Remove an IP from a domain whitelabel. + +This endpoint allows you to remove a domain's IP address from that domain's whitelabel. + +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 on whitelabeling, please see our User Guide + +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. +DELETE /whitelabel/domains/{id}/ips/{ip} + + +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 +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. + +For more information on whitelabeling, please see our User Guide + +URI Parameters + +URI PARAMETER TYPE DESCRIPTION +id integer ID of the domain whitelabel to validate. +POST /whitelabel/domains/{id}/validate + + +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 + +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. + +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. + +For more information, please see our User Guide. + +POST /whitelabel/ips + + +data = { + "domain": "example.com", + "ip": "192.168.1.1", + "subdomain": "email" +} +response = sg.client.whitelabel.ips.post(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 created 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."). + +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. + +For more information, please see our User Guide. + +GET /whitelabel/ips + + +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 +Retrieve an IP whitelabel + +This endpoint allows you to retrieve an IP whitelabel. + +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. + +For more information, please see our User Guide. + +GET /whitelabel/ips/{id} + + +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 + +This endpoint allows you to delete an IP whitelabel. + +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. + +For more information, please see our User Guide. + +DELETE /whitelabel/ips/{id} + + +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 + +This endpoint allows you to validate an IP whitelabel. + +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. + +For more information, please see our User Guide. + +POST /whitelabel/ips/{id}/validate + + +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 + +This endpoint allows you to create a new link whitelabel. + +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, please see our User Guide. + +POST /whitelabel/links + + +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 +Retrieve all link whitelabels + +This endpoint allows you to retrieve all link whitelabels. + +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, please see our User Guide. + +GET /whitelabel/links + + +params = {'limit': 1} +response = sg.client.whitelabel.links.get(query_params=params) +print response.status_code +print response.body +print response.headers +Retrieve a Default Link Whitelabel + +This endpoint allows you to retrieve the default link whitelabel. + +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) + +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, please see our User Guide. + +GET /whitelabel/links/default + + +params = {'domain': 'test_string'} +response = sg.client.whitelabel.links.default.get(query_params=params) +print response.status_code +print response.body +print response.headers +Retrieve Associated Link Whitelabel + +This endpoint allows you to retrieve the associated link whitelabel for a subuser. + +Link whitelables can be associated with subusers from the parent account. This functionality allows +subusers to send mail using their parent's link 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. + +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, please see our User Guide. + +GET /whitelabel/links/subuser + + +params = {'username': 'test_string'} +response = sg.client.whitelabel.links.subuser.get(query_params=params) +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. + +Link whitelables can be associated with subusers from the parent account. This functionality allows +subusers to send mail using their parent's link 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. + +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, please see our User Guide. + +DELETE /whitelabel/links/subuser + + +params = {'username': 'test_string'} +response = sg.client.whitelabel.links.subuser.delete(query_params=params) +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. + +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, please see our User Guide. + +PATCH /whitelabel/links/{id} + + +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 Link Whitelabel + +This endpoint allows you to retrieve a specific link whitelabel. + +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, please see our User Guide. + +GET /whitelabel/links/{id} + + +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 + +This endpoint allows you to delete a link whitelabel. + +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, please see our User Guide. + +DELETE /whitelabel/links/{id} + + +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 + +This endpoint allows you to validate a link whitelabel. + +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, please see our User Guide. + +POST /whitelabel/links/{id}/validate + + +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 + +This endpoint allows you to associate a link whitelabel with a subuser account. + +Link whitelables can be associated with subusers from the parent account. This functionality allows +subusers to send mail using their parent's link 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. + +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, please see our User Guide. + +POST /whitelabel/links/{link_id}/subuser + + +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.headersPOST /access_settings/whitelist ```python diff --git a/docker-test/README.md b/docker-test/README.md index d44ebf759..487a17ee6 100644 --- a/docker-test/README.md +++ b/docker-test/README.md @@ -20,7 +20,7 @@ This Docker image contains: - `python setup.py install` 2. [Install Docker](https://docs.docker.com/install/) 3. [Setup local environment variable SENDGRID_API_KEY](https://github.com/sendgrid/sendgrid-php#setup-environment-variables) -4. Build Docker image, run Docker container, login to the Docker container +4. Build a Docker image, run Docker container, login to the Docker container - `docker image build --tag="sendgrid/python3.6" ./docker-test` - `docker run -itd --name="sendgrid_python3.6" -v $(pwd):/root/sendgrid-python sendgrid/python3.6 /bin/bash` 5. Run the tests within the Docker container diff --git a/docker/USAGE.md b/docker/USAGE.md index d869a77ce..0d3f90b90 100644 --- a/docker/USAGE.md +++ b/docker/USAGE.md @@ -77,7 +77,7 @@ Note that the paths you specify in `-v` must be absolute. 1. Install docker-compose on your machine. 2. Must copy sendgrid.env to .env file. -3. Edit .env file for yours versions and paths. +3. Edit .env file for your versions and paths. 4. Must create env folder for clone yours repo. 5. Have fun! :D diff --git a/proposals/mail-helper-refactor.md b/proposals/mail-helper-refactor.md index 5a0127fd6..a057b38e0 100644 --- a/proposals/mail-helper-refactor.md +++ b/proposals/mail-helper-refactor.md @@ -196,7 +196,7 @@ msg.custom_arg = [ msg.send_at = SendAt(1461775052, p=1) -# The values below this comment are global to entire message +# The values below this comment are global to the entire message msg.global_subject = Subject('Sending with SendGrid is Fun') diff --git a/sendgrid/helpers/inbound/README.md b/sendgrid/helpers/inbound/README.md index bc69d1189..f8bec75ce 100644 --- a/sendgrid/helpers/inbound/README.md +++ b/sendgrid/helpers/inbound/README.md @@ -1,4 +1,4 @@ -**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 diff --git a/use_cases/asynchronous_mail_send.md b/use_cases/asynchronous_mail_send.md index 57dd61b2a..253b07a0c 100644 --- a/use_cases/asynchronous_mail_send.md +++ b/use_cases/asynchronous_mail_send.md @@ -2,7 +2,7 @@ ## Using `asyncio` (3.5+) -The built-in `asyncio` library can be used to send email in a non-blocking manner. `asyncio` helps us execute mail sending in a separate context, allowing us to continue execution of business logic without waiting for all our emails to send first. +The built-in `asyncio` library can be used to send email in a non-blocking manner. `asyncio` helps us execute mail sending in a separate context, allowing us to continue the execution of business logic without waiting for all our emails to send first. ```python import sendgrid diff --git a/use_cases/aws.md b/use_cases/aws.md index d07d5769c..83f3ca61c 100644 --- a/use_cases/aws.md +++ b/use_cases/aws.md @@ -2,14 +2,14 @@ This tutorial explains how to set up a simple "Hello Email" app on AWS, using the AWS CodeStar service. -We'll be creating a basic web service to send email via SendGrid. The application will run on AWS Lambda, and the "endpoint" will be via AWS API Gateway. +We'll be creating a basic web service to send an email via SendGrid. The application will run on AWS Lambda, and the "endpoint" will be via AWS API Gateway. -The neat thing is that CodeStar provides all of this in a pre-configured package. We just have to make some config changes, and push our code. +The neat thing is that CodeStar provides all of this in a pre-configured package. We just have to make some config changes and push our code. -Once this tutorial is complete, you'll have a basic web service for sending email that can be invoked via a link to your newly created API endpoint. +Once this tutorial is complete, you'll have a basic web service for sending an email that can be invoked via a link to your newly created API endpoint. ### Prerequisites -Python 2.6, 2.7, 3.4, or 3.5 are supported by the sendgrid Python library, however I was able to utilize 3.6 with no issue. +Python 2.6, 2.7, 3.4, or 3.5 are supported by the sendgrid Python library, however, I was able to utilize 3.6 with no issue. Before starting this tutorial, you will need to have access to an AWS account in which you are allowed to provision resources. This tutorial also assumes you've already created a SendGrid account with free-tier access. Finally, it is highly recommended you utilize [virtualenv](https://virtualenv.pypa.io/en/stable/). @@ -19,18 +19,18 @@ Before starting this tutorial, you will need to have access to an AWS account in ## Getting Started ### Create AWS CodeStar Project -Log in to your AWS account and go to the AWS CodeStar service. Click "Start a project". For this tutorial we're going to choose a Python Web service, utilizing AWS Lambda. You can use the filters on the left hand side of the UI to narrow down the available choices. +Log in to your AWS account and go to the AWS CodeStar service. Click "Start a project". For this tutorial we're going to choose a Python Web service, utilizing AWS Lambda. You can use the filters on the left-hand side of the UI to narrow down the available choices. -After you've selected the template, you're asked to provide a name for your project. Go ahead and name it "hello-email". Once you've entered a name, click "Create Project" in the lower right hand corner. You can then choose which tools you want to use to interact with the project. For this tutorial, we'll be choosing "Command Line". +After you've selected the template, you're asked to provide a name for your project. Go ahead and name it "hello-email". Once you've entered a name, click "Create Project" in the lower right-hand corner. You can then choose which tools you want to use to interact with the project. For this tutorial, we'll be choosing the "Command Line". -Once that is completed, you'll be given some basic steps to get Git installed and setup, and instructions for connecting to the AWS CodeCommit(git) repository. You can either use HTTPS, or SSH. Instructions for setting up either are provided. +Once that is completed, you'll be given some basic steps to get Git installed and setup, and instructions for connecting to the AWS CodeCommit(git) repository. You can either use HTTPS or SSH. Instructions for setting up either are provided. -Go ahead and clone the Git repository link after it is created. You may need to click "Skip" in the lower right hand corner to proceed. +Go ahead and clone the Git repository link after it is created. You may need to click "Skip" in the lower right-hand corner to proceed. -Once that's done, you've successfully created a CodeStar project! You should be at the dashboard, with a view of the wiki, change log, build pipeline, and application endpoint. +Once that's done, you've successfully created a CodeStar project! You should be at the dashboard, with a view of the wiki, changelog, build a pipeline, and application endpoint. ### Create SendGrid API Key -Log in to your SendGrid account. Click on your user name on the left hand side of the UI and choose "Setup Guide" from the drop-down menu. On the "Welcome" menu, choose "Send Your First Email", and then "Integrate using our Web API or SMTP relay." Choose "Web API" as the recommended option on the next screen, as we'll be using that for this tutorial. For more information about creating API keys, see https://sendgrid.com/docs/Classroom/Send/How_Emails_Are_Sent/api_keys.html +Log in to your SendGrid account. Click on your username on the left-hand side of the UI and choose "Setup Guide" from the drop-down menu. On the "Welcome" menu, choose "Send Your First Email", and then "Integrate using our Web API or SMTP relay." Choose "Web API" as the recommended option on the next screen, as we'll be using that for this tutorial. For more information about creating API keys, see https://sendgrid.com/docs/Classroom/Send/How_Emails_Are_Sent/api_keys.html On the next menu, you have the option to choose what programming language you'll be using. The obvious choice for this tutorial will be Python. @@ -100,7 +100,7 @@ virtualenv venv source ./venv/bin/activate ``` -Prior to being able to deploy our Python code, we'll need to install the sendgrid Python module *locally*. One of the idiosyncracies of AWS Lambda is that all library and module dependencies that aren't part of the standard library have to be included with the code/build artifact. Virtual environments do not translate to the Lambda runtime environment. +Prior to being able to deploy our Python code, we'll need to install the sendgrid Python module *locally*. One of the idiosyncrasies of AWS Lambda is that all library and module dependencies that aren't part of the standard library have to be included with the code/build artifact. Virtual environments do not translate to the Lambda runtime environment. In the root project directory, run the following command: ``` @@ -169,4 +169,4 @@ SENDGRID_API_KEY Now, go back to your project dashboard in CodeStar. Click on the link under "Application endpoints". After a moment, you should be greeted with JSON output indicating an email was successfully sent. -Congratulations, you've just used serverless technology to create an email sending app in AWS! \ No newline at end of file +Congratulations, you've just used serverless technology to create an email sending the app in AWS! \ No newline at end of file diff --git a/use_cases/django.md b/use_cases/django.md index 554e5fa21..c6b14dad2 100644 --- a/use_cases/django.md +++ b/use_cases/django.md @@ -1,4 +1,4 @@ -# Create a Django app to send email with SendGrid +# Create a Django app to send an email with SendGrid This tutorial explains how we set up a simple Django app to send an email with the SendGrid Python SDK and how we deploy our app to Heroku. @@ -75,7 +75,7 @@ def index(request): return HttpResponse('Email Sent!') ``` -**Note:** It would be best to change your to email from `test@example.com` to your own email, so that you can see the email you receive. +**Note:** It would be best to change your to email from `test@example.com` to your own email so that you can see the email you receive. Now the folder structure should look like this: @@ -92,7 +92,7 @@ hello-sendgrid └── requirements.txt ``` -Next we open the file `urls.py` in order to add the view we have just created to the Django URL dispatcher. +Next, we open the file `urls.py` in order to add the view we have just created to the Django URL dispatcher. ```python from django.conf.urls import url @@ -119,7 +119,7 @@ $ python manage.py migrate $ python manage.py runserver ``` -By default, it starts the development server at `http://127.0.0.1:8000/`. To test if we can send email or not, go to `http://127.0.0.1:8000/sendgrid/`. If it works, we should see the page says "Email Sent!". +By default, it starts the development server at `http://127.0.0.1:8000/`. To test if we can send an email or not, go to `http://127.0.0.1:8000/sendgrid/`. If it works, we should see the page says "Email Sent!". **Note:** If you use `test@example.com` as your from email, it's likely to go to your spam folder. To have the emails show up in your inbox, try using an email address at the domain you registered your SendGrid account. diff --git a/use_cases/flask_heroku.md b/use_cases/flask_heroku.md index ef0fa599a..fd55c77b5 100644 --- a/use_cases/flask_heroku.md +++ b/use_cases/flask_heroku.md @@ -1,4 +1,4 @@ -# Create a Flask app to send email with SendGrid +# Create a Flask app to send an email with SendGrid This tutorial explains how to deploy a simple Flask app, to send an email using the SendGrid Python SDK, on Heroku. From f90ece888dd55b4137aa9ee3853c0b1c8c563927 Mon Sep 17 00:00:00 2001 From: zkan Date: Sat, 6 Oct 2018 15:31:47 +0700 Subject: [PATCH 54/82] Test when env format is invalid, it should not set env --- test/test_config.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/test_config.py b/test/test_config.py index 301bacc92..fe720ad5c 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -41,7 +41,7 @@ def test_initialization(self): for key in keys: self.assertTrue(key in self.config.keys) - def test_init_environment(self): + def test_init_environment_should_set_env_from_dotenv(self): config_file = sendgrid.helpers.inbound.config.__file__ env_file_path = os.path.abspath(os.path.dirname(config_file)) + '/.env' with open(env_file_path, 'w') as f: @@ -49,3 +49,12 @@ def test_init_environment(self): Config() os.remove(env_file_path) self.assertEqual('RANDOM_VALUE', os.environ['RANDOM_VARIABLE']) + + def test_init_environment_should_not_set_env_if_format_is_invalid(self): + config_file = sendgrid.helpers.inbound.config.__file__ + env_file_path = os.path.abspath(os.path.dirname(config_file)) + '/.env' + with open(env_file_path, 'w') as f: + f.write('RANDOM_VARIABLE=RANDOM_VALUE=ANOTHER_RANDOM_VALUE') + Config() + os.remove(env_file_path) + self.assertIsNone(os.environ.get('RANDOM_VARIABLE')) From 2ba466632fdd3b7c14fe73f3c1820d8f0ea07e4e Mon Sep 17 00:00:00 2001 From: zkan Date: Sat, 6 Oct 2018 15:57:43 +0700 Subject: [PATCH 55/82] Correct assertion and improve Python coding style a bit --- test/test_config.py | 48 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/test/test_config.py b/test/test_config.py index fe720ad5c..658018858 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -15,29 +15,31 @@ def setUp(self): def test_initialization(self): endpoint = '/inbound' port = 5000 - debug_mode = True - keys = ['from', - 'attachments', - 'headers', - 'text', - 'envelope', - 'to', - 'html', - 'sender_ip', - 'attachment-info', - 'subject', - 'dkim', - 'SPF', - 'charsets', - 'content-ids', - 'spam_report', - 'spam_score', - 'email'] + keys = [ + 'from', + 'attachments', + 'headers', + 'text', + 'envelope', + 'to', + 'html', + 'sender_ip', + 'attachment-info', + 'subject', + 'dkim', + 'SPF', + 'charsets', + 'content-ids', + 'spam_report', + 'spam_score', + 'email', + ] host = 'http://127.0.0.1:5000/inbound' - self.assertTrue(debug_mode, self.config.debug_mode) - self.assertTrue(endpoint, self.config.endpoint) - self.assertTrue(host, self.config.host) - self.assertTrue(port, self.config.port) + + self.assertTrue(self.config.debug_mode) + self.assertEqual(self.config.endpoint, endpoint) + self.assertEqual(self.config.host, host) + self.assertEqual(self.config.port, port) for key in keys: self.assertTrue(key in self.config.keys) @@ -48,7 +50,7 @@ def test_init_environment_should_set_env_from_dotenv(self): f.write('RANDOM_VARIABLE=RANDOM_VALUE') Config() os.remove(env_file_path) - self.assertEqual('RANDOM_VALUE', os.environ['RANDOM_VARIABLE']) + self.assertEqual(os.environ['RANDOM_VARIABLE'], 'RANDOM_VALUE') def test_init_environment_should_not_set_env_if_format_is_invalid(self): config_file = sendgrid.helpers.inbound.config.__file__ From fb8d334ca7ce72aa228611e81bd9935426314b0f Mon Sep 17 00:00:00 2001 From: Arshad Kazmi Date: Sun, 7 Oct 2018 00:16:21 +0530 Subject: [PATCH 56/82] troubleshooting broken link fix --- TROUBLESHOOTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index 1298ab7d1..1b71b4852 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -77,7 +77,7 @@ Click the "Clone or download" green button in [GitHub](https://github.com/sendgr ## Testing v3 /mail/send Calls Directly -[Here](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/curl_examples.html) are some cURL examples for common use cases. +[Here](https://sendgrid.com/docs/for-developers/sending-email/curl-examples/) are some cURL examples for common use cases. ## Using the Package Manager From fe4f43b3554e38ff6cd2ae8f378d71a0cb205cfe Mon Sep 17 00:00:00 2001 From: Joshua de Guzman Date: Mon, 8 Oct 2018 19:36:58 +0800 Subject: [PATCH 57/82] Fix helper mail_example redirection link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 023a289ec..4132b62b5 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ pip install sendgrid ## Hello Email -The following is the minimum needed code to send an email with the [/mail/send Helper](https://github.com/sendgrid/sendgrid-python/tree/master/sendgrid/helpers/mail) ([here](https://github.com/sendgrid/sendgrid-python/blob/master/examples/helpers/mail/mail_example.py#L20) is a full example): +The following is the minimum needed code to send an email with the [/mail/send Helper](https://github.com/sendgrid/sendgrid-python/tree/master/sendgrid/helpers/mail) ([here](https://github.com/sendgrid/sendgrid-python/blob/master/examples/helpers/mail_example.py) is a full example): ### With Mail Helper Class From 935a4d70a0259b557452bb49278ef8d6947fa91d Mon Sep 17 00:00:00 2001 From: Xeon Zolt Date: Mon, 15 Oct 2018 15:28:20 +0530 Subject: [PATCH 58/82] fixed changes suggested --- CODE_OF_CONDUCT.md | 16 ++++++++-------- CONTRIBUTING.md | 8 ++++---- TROUBLESHOOTING.md | 2 +- use_cases/aws.md | 20 ++++++++++---------- use_cases/django.md | 6 +++--- use_cases/flask_heroku.md | 2 +- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 670a82f62..31743bc0e 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,6 +1,6 @@ # SendGrid Community Code of Conduct - The SendGrid open source community is made up of members from around the globe with a diverse set of skills, personalities, and experiences. It is through these differences that our community experiences successes and continued growth. When you're working with members of the community, we encourage you to follow these guidelines, which help steer our interactions and strive to maintain a positive, successful and growing community. + The SendGrid open source community is made up of members from around the globe with a diverse set of skills, personalities, and experiences. It is through these differences that our community experiences successes and continued growth. When you're working with members of the community, we encourage you to follow these guidelines, which help steer our interactions and strive to maintain a positive, successful and growing community. ### Be Open Members of the community are open to collaboration, whether it's on pull requests, code reviews, approvals, issues or otherwise. We're receptive to constructive comments and criticism, as the experiences and skill sets of all members contribute to the whole of our efforts. We're accepting of all who wish to take part in our activities, fostering an environment where anyone can participate, and everyone can make a difference. @@ -9,15 +9,15 @@ Members of the community are considerate of their peers, which include other contributors and users of SendGrid. We're thoughtful when addressing the efforts of others, keeping in mind that often the labor was completed with the intent of the good of the community. We're attentive in our communications, whether in person or online, and we're tactful when approaching differing views. ### Be Respectful - Members of the community are respectful. We're respectful of others, their positions, their skills, their commitments ,and their efforts. We're respectful of the volunteer efforts that permeate the SendGrid community. We're respectful of the processes outlined in the community, and we work within them. When we disagree, we are courteous in raising our issues. Overall, we're good with each other. We contribute to this community not because we have to, but because we want to. If we remember that, these guidelines will come naturally. + Members of the community are respectful. We're respectful of others, their positions, their skills, their commitments, and their efforts. We're respectful of the volunteer efforts that permeate the SendGrid community. We're respectful of the processes outlined in the community, and we work within them. When we disagree, we are courteous in raising our issues. Overall, we're good with each other. We contribute to this community not because we have to, but because we want to. If we remember that, these guidelines will come naturally. - ## Additional Guidance + ## Additional Guidance ### Disclose Potential Conflicts of Interest Community discussions often involve interested parties. We expect participants to be aware when they are conflicted due to employment or other projects they are involved in and disclose those interests to other project members. When in doubt, over-disclose. Perceived conflicts of interest are important to address so that the community’s decisions are credible even when unpopular, difficult or favorable to the interests of one group over another. ### Interpretation - This Code is not exhaustive or complete. It is not a rulebook; it serves to distill our common understanding of a collaborative, shared environment and goals. We expect it to be followed in spirit as much as in the letter. When in doubt, try to abide by [SendGrid’s cultural values](https://sendgrid.com/blog/employee-engagement-the-4h-way) defined by our “4H’s”: Happy, Hungry, Humble and Honest. + This Code is not exhaustive or complete. It is not a rulebook; it serves to distill our common understanding of a collaborative, shared environment and goals. We expect it to be followed in spirit as much as in the letter. When in doubt, try to abide by [SendGrid’s cultural values](https://sendgrid.com/blog/employee-engagement-the-4h-way) defined by our “4H’s”: Happy, Hungry, Humble and Honest. ### Enforcement Most members of the SendGrid community always comply with this Code, not because of the existence of this Code, but because they have long experience participating in open source communities where the conduct described above is normal and expected. However, failure to observe this Code may be grounds for suspension, reporting the user for abuse or changing permissions for outside contributors. @@ -30,12 +30,12 @@ **Contact the Moderators** - You can reach the SendGrid moderators by emailing dx@sendgrid.com. ## Submission to SendGrid Repositories - Finally, just a reminder, changes to the SendGrid repositories will only be accepted upon completion of the [SendGrid Contributor Agreement](https://cla.sendgrid.com). + Finally, just a reminder, changes to the SendGrid repositories will only be accepted upon completion of the [SendGrid Contributor Agreement](https://cla.sendgrid.com). ## Attribution SendGrid thanks the following, on which it draws for content and inspiration: - [Python Community Code of Conduct](https://www.python.org/psf/codeofconduct/) - [Open Source Initiative General Code of Conduct](https://opensource.org/codeofconduct) - [Apache Code of Conduct](https://www.apache.org/foundation/policies/conduct.html) + [Python Community Code of Conduct](https://www.python.org/psf/codeofconduct/) + [Open Source Initiative General Code of Conduct](https://opensource.org/codeofconduct) + [Apache Code of Conduct](https://www.apache.org/foundation/policies/conduct.html) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 90f8a1f42..f3bba6d65 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,7 +62,7 @@ We welcome direct contributions to the sendgrid-python code base. Thank you! ### Development Environment ### #### There are two ways to get set up: #### #### 1. Using Docker #### -This is usually the easiest and fastest way to get set up. +This is usually the easiest and fastest way to get set up. You can use our Docker image to avoid setting up the development environment yourself. See [USAGE.md](https://github.com/sendgrid/sendgrid-python/blob/master/docker/USAGE.md). #### - OR - #### @@ -191,10 +191,10 @@ Please run your code through: ```bash # Clone your fork of the repo into the current directory git clone https://github.com/sendgrid/sendgrid-python - + # Navigate to the newly cloned directory cd sendgrid-python - + # Assign the original repo to a remote called "upstream" git remote add upstream https://github.com/sendgrid/sendgrid-python ``` @@ -213,7 +213,7 @@ Please run your code through: git checkout -b ``` -4. Commit your changes in logical chunks. Please adhere to these [git commits +4. Commit your changes in logical chunks. Please adhere to these [git commit message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) or your code is unlikely to be merged into the main project. Use Git's [interactive rebase](https://help.github.com/articles/interactive-rebase) diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index a33919a26..97eca9b55 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -95,7 +95,7 @@ If you are using a [requirements file](https://pip.readthedocs.io/en/1.1/require ## 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 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](https://github.com/sendgrid/sendgrid-python/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-python/releases) section. +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 in 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](https://github.com/sendgrid/sendgrid-python/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-python/releases) section. ## Viewing the Request Body diff --git a/use_cases/aws.md b/use_cases/aws.md index 83f3ca61c..2d8d25b00 100644 --- a/use_cases/aws.md +++ b/use_cases/aws.md @@ -2,11 +2,11 @@ This tutorial explains how to set up a simple "Hello Email" app on AWS, using the AWS CodeStar service. -We'll be creating a basic web service to send an email via SendGrid. The application will run on AWS Lambda, and the "endpoint" will be via AWS API Gateway. +We'll be creating a basic web service to send email via SendGrid. The application will run on AWS Lambda, and the "endpoint" will be via AWS API Gateway. The neat thing is that CodeStar provides all of this in a pre-configured package. We just have to make some config changes and push our code. -Once this tutorial is complete, you'll have a basic web service for sending an email that can be invoked via a link to your newly created API endpoint. +Once this tutorial is complete, you'll have a basic web service for sending email that can be invoked via a link to your newly created API endpoint. ### Prerequisites Python 2.6, 2.7, 3.4, or 3.5 are supported by the sendgrid Python library, however, I was able to utilize 3.6 with no issue. @@ -21,13 +21,13 @@ Before starting this tutorial, you will need to have access to an AWS account in ### Create AWS CodeStar Project Log in to your AWS account and go to the AWS CodeStar service. Click "Start a project". For this tutorial we're going to choose a Python Web service, utilizing AWS Lambda. You can use the filters on the left-hand side of the UI to narrow down the available choices. -After you've selected the template, you're asked to provide a name for your project. Go ahead and name it "hello-email". Once you've entered a name, click "Create Project" in the lower right-hand corner. You can then choose which tools you want to use to interact with the project. For this tutorial, we'll be choosing the "Command Line". +After you've selected the template, you're asked to provide a name for your project. Go ahead and name it "hello-email". Once you've entered a name, click "Create Project" in the lower right-hand corner. You can then choose which tools you want to use to interact with the project. For this tutorial, we'll be choosing "Command Line". -Once that is completed, you'll be given some basic steps to get Git installed and setup, and instructions for connecting to the AWS CodeCommit(git) repository. You can either use HTTPS or SSH. Instructions for setting up either are provided. +Once that is completed, you'll be given some basic steps to get Git installed and setup, and instructions for connecting to the AWS CodeCommit(git) repository. You can either use HTTPS or SSH. Instructions for setting up either are provided. Go ahead and clone the Git repository link after it is created. You may need to click "Skip" in the lower right-hand corner to proceed. -Once that's done, you've successfully created a CodeStar project! You should be at the dashboard, with a view of the wiki, changelog, build a pipeline, and application endpoint. +Once that's done, you've successfully created a CodeStar project! You should be at the dashboard, with a view of the wiki, changelog, build pipeline, and application endpoint. ### Create SendGrid API Key Log in to your SendGrid account. Click on your username on the left-hand side of the UI and choose "Setup Guide" from the drop-down menu. On the "Welcome" menu, choose "Send Your First Email", and then "Integrate using our Web API or SMTP relay." Choose "Web API" as the recommended option on the next screen, as we'll be using that for this tutorial. For more information about creating API keys, see https://sendgrid.com/docs/Classroom/Send/How_Emails_Are_Sent/api_keys.html @@ -44,7 +44,7 @@ For the rest of the tutorial, we'll be working out of the Git repository we clon ``` $ cd hello-email ``` -note: this assumes you cloned the Git repo inside your current directory. My directory is: +note: this assumes you cloned the Git repo inside your current directory. My directory is: ``` ~/projects/hello-email @@ -100,7 +100,7 @@ virtualenv venv source ./venv/bin/activate ``` -Prior to being able to deploy our Python code, we'll need to install the sendgrid Python module *locally*. One of the idiosyncrasies of AWS Lambda is that all library and module dependencies that aren't part of the standard library have to be included with the code/build artifact. Virtual environments do not translate to the Lambda runtime environment. +Prior to being able to deploy our Python code, we'll need to install the sendgrid Python module *locally*. One of the idiosyncrasies of AWS Lambda is that all library and module dependencies that aren't part of the standard library have to be included with the code/build artifact. Virtual environments do not translate to the Lambda runtime environment. In the root project directory, run the following command: ``` @@ -157,7 +157,7 @@ $ git commit -m 'hello-email app' $ git push ``` -Once the code is successfully pushed, head back to the AWS CodeStar dashboard for your project. After your commit successfully registers, an automated build and deployment process should kick off. +Once the code is successfully pushed, head back to the AWS CodeStar dashboard for your project. After your commit successfully registers, an automated build and deployment process should kick off. One more step left before our application will work correctly. After your code has bee deployed, head to the AWS Lambda console. Click on your function name, which should start with `awscodestar-hello-email-lambda-`, or similar. @@ -167,6 +167,6 @@ Scroll down to the "Environment Variables" section. Here we need to populate our SENDGRID_API_KEY ``` -Now, go back to your project dashboard in CodeStar. Click on the link under "Application endpoints". After a moment, you should be greeted with JSON output indicating an email was successfully sent. +Now, go back to your project dashboard in CodeStar. Click on the link under "Application endpoints". After a moment, you should be greeted with JSON output indicating an email was successfully sent. -Congratulations, you've just used serverless technology to create an email sending the app in AWS! \ No newline at end of file +Congratulations, you've just used serverless technology to create an email sending app in AWS! diff --git a/use_cases/django.md b/use_cases/django.md index c6b14dad2..aae2d3c04 100644 --- a/use_cases/django.md +++ b/use_cases/django.md @@ -1,4 +1,4 @@ -# Create a Django app to send an email with SendGrid +# Create a Django app to send email with SendGrid This tutorial explains how we set up a simple Django app to send an email with the SendGrid Python SDK and how we deploy our app to Heroku. @@ -119,7 +119,7 @@ $ python manage.py migrate $ python manage.py runserver ``` -By default, it starts the development server at `http://127.0.0.1:8000/`. To test if we can send an email or not, go to `http://127.0.0.1:8000/sendgrid/`. If it works, we should see the page says "Email Sent!". +By default, it starts the development server at `http://127.0.0.1:8000/`. To test if we can send email or not, go to `http://127.0.0.1:8000/sendgrid/`. If it works, we should see the page says "Email Sent!". **Note:** If you use `test@example.com` as your from email, it's likely to go to your spam folder. To have the emails show up in your inbox, try using an email address at the domain you registered your SendGrid account. @@ -198,4 +198,4 @@ $ git commit -am "Create simple Hello Email Django app using SendGrid" $ git push heroku master ``` -After that, let's verify if our app is working or not by accessing the root domain of your Heroku app. You should see the page says "Email Sent!" and on the Activity Feed page in the SendGrid dashboard, you should see a new feed with the email you set in the code. \ No newline at end of file +After that, let's verify if our app is working or not by accessing the root domain of your Heroku app. You should see the page says "Email Sent!" and on the Activity Feed page in the SendGrid dashboard, you should see a new feed with the email you set in the code. diff --git a/use_cases/flask_heroku.md b/use_cases/flask_heroku.md index fd55c77b5..ef0fa599a 100644 --- a/use_cases/flask_heroku.md +++ b/use_cases/flask_heroku.md @@ -1,4 +1,4 @@ -# Create a Flask app to send an email with SendGrid +# Create a Flask app to send email with SendGrid This tutorial explains how to deploy a simple Flask app, to send an email using the SendGrid Python SDK, on Heroku. From 9ffe918a842c2a3eb933a71df4553a86ab944549 Mon Sep 17 00:00:00 2001 From: Tulika Date: Tue, 16 Oct 2018 23:49:42 +0530 Subject: [PATCH 59/82] Create README.md --- examples/helpers/README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 examples/helpers/README.md diff --git a/examples/helpers/README.md b/examples/helpers/README.md new file mode 100644 index 000000000..917aebb16 --- /dev/null +++ b/examples/helpers/README.md @@ -0,0 +1,37 @@ +## 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, subject, to_email, 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](https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/mail.py) + +### Creating Personalizations + +To create personalizations, you need a dictionary to store all your email components. see example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L47) +After creating a dictionary, you can go ahead and create a `Personalization` object. +``` + mock_personalization = Personalization() + for to_addr in personalization['to_list']: + mock_personalization.add_to(to_addr) +``` From 46b7e4df5af08c333e897a4dd471bc7c08858d1a Mon Sep 17 00:00:00 2001 From: Chandler Weiner Date: Wed, 17 Oct 2018 12:52:51 -0400 Subject: [PATCH 60/82] Update verbiage from to "Authentication" --- use_cases/domain_authentication.md | 5 +++++ use_cases/domain_whitelabel.md | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 use_cases/domain_authentication.md delete mode 100644 use_cases/domain_whitelabel.md diff --git a/use_cases/domain_authentication.md b/use_cases/domain_authentication.md new file mode 100644 index 000000000..ea3ea008c --- /dev/null +++ b/use_cases/domain_authentication.md @@ -0,0 +1,5 @@ +# How to Setup a Domain Authentication + +You can find documentation for how to setup Sender Authentication via the UI [here](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) and via API [here](https://github.com/sendgrid/sendgrid-python/blob/master/USAGE.md#sender-authentication). + +Find more information about all of SendGrid's Authenticating related documentation [here](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/). diff --git a/use_cases/domain_whitelabel.md b/use_cases/domain_whitelabel.md deleted file mode 100644 index c28ad055d..000000000 --- a/use_cases/domain_whitelabel.md +++ /dev/null @@ -1,5 +0,0 @@ -# How to Setup a Domain Whitelabel - -You can find documentation for how to setup a domain whitelabel via the UI [here](https://sendgrid.com/docs/Classroom/Basics/Whitelabel/setup_domain_whitelabel.html) and via API [here](https://github.com/sendgrid/sendgrid-python/blob/master/USAGE.md#whitelabel). - -Find more information about all of SendGrid's whitelabeling related documentation [here](https://sendgrid.com/docs/Classroom/Basics/Whitelabel/index.html). \ No newline at end of file From 8ea9a44f4251a6e947a411725c6211f2883a8d61 Mon Sep 17 00:00:00 2001 From: Chandler Weiner Date: Wed, 17 Oct 2018 12:54:04 -0400 Subject: [PATCH 61/82] Change link to Domain Authentication --- use_cases/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/use_cases/README.md b/use_cases/README.md index 9966616e5..f3aa7e361 100644 --- a/use_cases/README.md +++ b/use_cases/README.md @@ -9,7 +9,7 @@ This directory provides examples for specific use cases of this library. Please * [How to Create a Django app, Deployed on Heroku, to Send Email with SendGrid](django.md) * [How to Deploy A Simple Hello Email App on AWS](aws.md) * [How to Deploy a simple Flask app, to send Email with SendGrid, on Heroku](flask_heroku.md) -* [How to Setup a Domain Whitelabel](domain_whitelabel.md) +* [How to Setup a Domain Authentication](domain_authentication.md) * [How to View Email Statistics](email_stats.md) ### Working with Mail @@ -19,4 +19,4 @@ This directory provides examples for specific use cases of this library. Please * [Integrate with Slack Events API](slack_event_api_integration.md) ### Library Features -* [Error Handling](error_handling.md) \ No newline at end of file +* [Error Handling](error_handling.md) From 2793955714386fb0312dfdc51018487f95dfd8e1 Mon Sep 17 00:00:00 2001 From: Harsh Lathwal Date: Thu, 18 Oct 2018 01:16:12 +0530 Subject: [PATCH 62/82] removed similar data and kept fixes --- USAGE.md | 4711 +----------------------------------------------------- 1 file changed, 45 insertions(+), 4666 deletions(-) diff --git a/USAGE.md b/USAGE.md index ea2beae39..40f0472f8 100644 --- a/USAGE.md +++ b/USAGE.md @@ -70,4628 +70,7 @@ IP Access Management allows you to control which IP addresses can be used to acc For more information, please see our [User Guide](http://sendgrid.com/docs/User_Guide/Settings/ip_access_management.html). -This documentation is based on our OAI specification. - -INITIALIZATION - - -import sendgrid -import os - - -sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) -Table of Contents - -ACCESS SETTINGS - -ALERTS - -API KEYS - -ASM - -BROWSERS - -CAMPAIGNS - -CATEGORIES - -CLIENTS - -CONTACTDB - -DEVICES - -GEO - -IPS - -MAIL - -MAIL SETTINGS - -MAILBOX PROVIDERS - -PARTNER SETTINGS - -SCOPES - -SENDERS - -STATS - -SUBUSERS - -SUPPRESSION - -TEMPLATES - -TRACKING SETTINGS - -USER - -WHITELABEL - - - -ACCESS SETTINGS - -Retrieve all recent access attempts - -This endpoint allows you to retrieve a list of all of the IP addresses that recently attempted to access your account either through the User Interface or the API. - -IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account. - -For more information, please see our User Guide. - -GET /access_settings/activity - - -params = {'limit': 1} -response = sg.client.access_settings.activity.get(query_params=params) -print response.status_code -print response.body -print response.headers -Add one or more IPs to the whitelist - -This endpoint allows you to add one or more IP addresses to your IP whitelist. - -When adding an IP to your whitelist, include the IP address in an array. You can whitelist one IP at a time, or you can whitelist multiple IPs at once. - -IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account. - -For more information, please see our User Guide. - -POST /access_settings/whitelist - - -data = { - "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 -print response.body -print response.headers -Retrieve a list of currently whitelisted IPs - -This endpoint allows you to retrieve a list of IP addresses that are currently whitelisted. - -IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account. - -For more information, please see our User Guide. - -GET /access_settings/whitelist - - -response = sg.client.access_settings.whitelist.get() -print response.status_code -print response.body -print response.headers -Remove one or more IPs from the whitelist - -This endpoint allows you to remove one or more IPs from your IP whitelist. - -You can remove one IP at a time, or you can remove multiple IP addresses. - -IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account. - -For more information, please see our User Guide. - -DELETE /access_settings/whitelist - - -data = { - "ids": [ -​ 1, -​ 2, -​ 3 - ] -} -response = sg.client.access_settings.whitelist.delete(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve a specific whitelisted IP - -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. - -IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account. - -For more information, please see our User Guide. - -GET /access_settings/whitelist/{rule_id} - - -rule_id = "test_url_param" -response = sg.client.access_settings.whitelist._(rule_id).get() -print response.status_code -print response.body -print response.headers -Remove a specific IP from the whitelist - -This endpoint allows you to remove a specific IP address from your IP whitelist. - -When removing a specific IP address from your whitelist, you must include the ID in your call. - -IP Access Management allows you to control which IP addresses can be used to access your account, either through the User Interface or the API. There is no limit to the number of IP addresses that you can add to your whitelist. It is possible to remove your own IP address from the whitelist, thus preventing yourself from accessing your account. - -For more information, please see our User Guide. - -DELETE /access_settings/whitelist/{rule_id} - - -rule_id = "test_url_param" -response = sg.client.access_settings.whitelist._(rule_id).delete() -print response.status_code -print response.body -print response.headers - - -ALERTS - -Create a new Alert - -This endpoint allows you to create a new alert. - -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. - -Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly". - -For more information about alerts, please see our User Guide. - -POST /alerts - - -data = { - "email_to": "example@example.com", - "frequency": "daily", - "type": "stats_notification" -} -response = sg.client.alerts.post(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve all alerts - -GET /alerts - - -response = sg.client.alerts.get() -print response.status_code -print response.body -print response.headers -Update an alert - -This endpoint allows you to update an alert. - -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. - -Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly". - -For more information about alerts, please see our User Guide. - -PATCH /alerts/{alert_id} - - -data = { - "email_to": "example@example.com" -} -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 -Retrieve a specific alert - -This endpoint allows you to retrieve a specific alert. - -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. - -Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly". - -For more information about alerts, please see our User Guide. - -GET /alerts/{alert_id} - - -alert_id = "test_url_param" -response = sg.client.alerts._(alert_id).get() -print response.status_code -print response.body -print response.headers -Delete an alert - -This endpoint allows you to delete an alert. - -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. - -Stats notifications allow you to set how frequently you would like to receive email statistics reports. For example, "daily", "weekly", or "monthly". - -For more information about alerts, please see our User Guide. - -DELETE /alerts/{alert_id} - - -alert_id = "test_url_param" -response = sg.client.alerts._(alert_id).delete() -print response.status_code -print response.body -print response.headers - - -API KEYS - -Create API keys - -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. - -There is a limit of 100 API Keys on your account. - -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. - -See the API Key Permissions List for a list of all available scopes. - -POST /api_keys - - -data = { - "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 -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 generate an API Key credential which can be used for authentication with the SendGrid v3 Web API or the Mail API Endpoint. - -GET /api_keys - - -params = {'limit': 1} -response = sg.client.api_keys.get(query_params=params) -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. - -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. - -PUT /api_keys/{api_key_id} - - -data = { - "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) -print response.status_code -print response.body -print response.headers -Update API keys - -This endpoint allows you to update the name of an existing API Key. - -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. - -URI Parameters - -URI PARAMETER TYPE REQUIRED? DESCRIPTION -api_key_id string required The ID of the API Key you are updating. -PATCH /api_keys/{api_key_id} - - -data = { - "name": "A New Hope" -} -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 -Retrieve an existing 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. - -GET /api_keys/{api_key_id} - - -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 -Delete API keys - -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 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. - -URI Parameters - -URI PARAMETER TYPE REQUIRED? DESCRIPTION -api_key_id string required The ID of the API Key you are deleting. -DELETE /api_keys/{api_key_id} - - -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 - - -ASM - -Create a new suppression group - -This endpoint allows you to create a new suppression group. - -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. - -Each user can create up to 25 different suppression groups. - -POST /asm/groups - - -data = { - "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 -print response.body -print response.headers -Retrieve information about multiple suppression groups - -This endpoint allows you to retrieve information about multiple suppression groups. - -This endpoint will return information for each group ID that you include in your request. To add a group ID to your request, simply append &id= followed by the group ID. - -Suppressions are a list of email addresses that will not receive content sent under a given group. - -Suppression groups, or unsubscribe groups, 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 - - -params = {'id': 1} -response = sg.client.asm.groups.get(query_params=params) -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 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. - -Each user can create up to 25 different suppression groups. - -PATCH /asm/groups/{group_id} - - -data = { - "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) -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 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. - -Each user can create up to 25 different suppression groups. - -GET /asm/groups/{group_id} - - -group_id = "test_url_param" -response = sg.client.asm.groups._(group_id).get() -print response.status_code -print response.body -print response.headers -Delete a suppression group. - -This endpoint allows you to delete a suppression group. - -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 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. - -Each user can create up to 25 different suppression groups. - -DELETE /asm/groups/{group_id} - - -group_id = "test_url_param" -response = sg.client.asm.groups._(group_id).delete() -print response.status_code -print response.body -print response.headers -Add suppressions to a suppression group - -This endpoint allows you to add email addresses to an unsubscribe group. - -If you attempt to add suppressions to a group that has been deleted or does not exist, the suppressions will be added to the global suppressions list. - -Suppressions are recipient email addresses that are added to unsubscribe groups. Once a recipient's address is on the suppressions list for an unsubscribe group, they will not receive any emails that are tagged with that unsubscribe group. - -POST /asm/groups/{group_id}/suppressions - - -data = { - "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) -print response.status_code -print response.body -print response.headers -Retrieve all suppressions for a suppression group - -This endpoint allows you to retrieve all suppressed email addresses belonging to the given group. - -Suppressions are recipient email addresses that are added to unsubscribe groups. Once a recipient's address is on the suppressions list for an unsubscribe group, they will not receive any emails that are tagged with that unsubscribe group. - -GET /asm/groups/{group_id}/suppressions - - -group_id = "test_url_param" -response = sg.client.asm.groups._(group_id).suppressions.get() -print response.status_code -print response.body -print response.headers -Search for suppressions within a group - -This endpoint allows you to search a suppression group for multiple suppressions. - -When given a list of email addresses and a group ID, this endpoint will return only the email addresses that have been unsubscribed from the given group. - -Suppressions are a list of email addresses that will not receive content sent under a given group. - -POST /asm/groups/{group_id}/suppressions/search - - -data = { - "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) -print response.status_code -print response.body -print response.headers -Delete a suppression from a suppression group - -This endpoint allows you to remove a suppressed email address from the given suppression group. - -Suppressions are recipient email addresses that are added to unsubscribe groups. Once a recipient's address is on the suppressions list for an unsubscribe group, they will not receive any emails that are tagged with that unsubscribe group. - -DELETE /asm/groups/{group_id}/suppressions/{email} - - -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 -Retrieve all suppressions - -This endpoint allows you to retrieve a list of all suppressions. - -Suppressions are a list of email addresses that will not receive content sent under a given group. - -GET /asm/suppressions - - -response = sg.client.asm.suppressions.get() -print response.status_code -print response.body -print response.headers -Add recipient addresses to the global suppression group. - -This endpoint allows you to add one or more email addresses to the global suppressions group. - -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. - -POST /asm/suppressions/global - - -data = { - "recipient_emails": [ -​ "test1@example.com", -​ "test2@example.com" - ] -} -response = sg.client.asm.suppressions._("global").post(request_body=data) -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 suppressed. - -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. - -GET /asm/suppressions/global/{email} - - -email = "test_url_param" -response = sg.client.asm.suppressions._("global")._(email).get() -print response.status_code -print response.body -print response.headers -Delete a Global Suppression - -This endpoint allows you to remove an email address from the global suppressions group. - -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. - -DELETE /asm/suppressions/global/{email} - - -email = "test_url_param" -response = sg.client.asm.suppressions._("global")._(email).delete() -print response.status_code -print response.body -print response.headers -Retrieve all suppression groups for an email address - -This endpoint returns the list of all groups that the given email address has been unsubscribed from. - -Suppressions are a list of email addresses that will not receive content sent under a given group. - -GET /asm/suppressions/{email} - - -email = "test_url_param" -response = sg.client.asm.suppressions._(email).get() -print response.status_code -print response.body -print response.headers - - -BROWSERS - -Retrieve email statistics by browser. - -This endpoint allows you to retrieve your email statistics segmented by browser type. - -We only store up to 7 days of email activity in our database. By default, 500 items will be returned per request via the Advanced Stats API endpoints. - -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. - -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'} -response = sg.client.browsers.stats.get(query_params=params) -print response.status_code -print response.body -print response.headers - - -CAMPAIGNS - -Create a Campaign - -This endpoint allows you to create a campaign. - -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. - -For more information: - -User Guide > Marketing Campaigns - -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" -} -response = sg.client.campaigns.post(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve all Campaigns - -This endpoint allows you to retrieve a list of all of your campaigns. - -Returns campaigns in reverse order they were created (newest first). - -Returns an empty array if no campaigns exist. - -For more information: - -User Guide > Marketing Campaigns - -GET /campaigns - - -params = {'limit': 10, 'offset': 0} -response = sg.client.campaigns.get(query_params=params) -print response.status_code -print response.body -print response.headers -Update a Campaign - -Update a campaign. This is especially useful if you only set up the campaign using POST /campaigns, but didn't set many of the parameters. - -For more information: - -User Guide > Marketing Campaigns - -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" -} -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 -Retrieve a single campaign - -This endpoint allows you to retrieve a specific campaign. - -Our Marketing Campaigns API lets you create, manage, send, and schedule campaigns. - -For more information: - -User Guide > Marketing Campaigns - -GET /campaigns/{campaign_id} - - -campaign_id = "test_url_param" -response = sg.client.campaigns._(campaign_id).get() -print response.status_code -print response.body -print response.headers -Delete a Campaign - -This endpoint allows you to delete a specific campaign. - -Our Marketing Campaigns API lets you create, manage, send, and schedule campaigns. - -For more information: - -User Guide > Marketing Campaigns - -DELETE /campaigns/{campaign_id} - - -campaign_id = "test_url_param" -response = sg.client.campaigns._(campaign_id).delete() -print response.status_code -print response.body -print response.headers -Update a Scheduled Campaign - -This endpoint allows to you change the scheduled time and date for a campaign to be sent. - -For more information: - -User Guide > Marketing Campaigns - -PATCH /campaigns/{campaign_id}/schedules - - -data = { - "send_at": 1489451436 -} -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 -Schedule a Campaign - -This endpoint allows you to schedule a specific date and time for your campaign to be sent. - -For more information: - -User Guide > Marketing Campaigns - -POST /campaigns/{campaign_id}/schedules - - -data = { - "send_at": 1489771528 -} -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 -View Scheduled Time of a Campaign - -This endpoint allows you to retrieve the date and time that the given campaign has been scheduled to be sent. - -For more information: - -User Guide > Marketing Campaigns - -GET /campaigns/{campaign_id}/schedules - - -campaign_id = "test_url_param" -response = sg.client.campaigns._(campaign_id).schedules.get() -print response.status_code -print response.body -print response.headers -Unschedule a Scheduled Campaign - -This endpoint allows you to unschedule a campaign that has already been scheduled to be sent. - -A successful unschedule will return a 204. -If the specified campaign is in the process of being sent, the only option is to cancel (a different method). - -For more information: - -User Guide > Marketing Campaigns - -DELETE /campaigns/{campaign_id}/schedules - - -campaign_id = "test_url_param" -response = sg.client.campaigns._(campaign_id).schedules.delete() -print response.status_code -print response.body -print response.headers -Send a Campaign - -This endpoint allows you to immediately send a campaign at the time you make the API call. - -Normally a POST would have a request body, but since this endpoint is telling us to send a resource that is already created, a request body is not needed. - -For more information: - -User Guide > Marketing Campaigns - -POST /campaigns/{campaign_id}/schedules/now - - -campaign_id = "test_url_param" -response = sg.client.campaigns._(campaign_id).schedules.now.post() -print response.status_code -print response.body -print response.headers -Send a Test Campaign - -This endpoint allows you to send a test campaign. - -To send to multiple addresses, use an array for the JSON "to" value ["one@address","two@address"] - -For more information: - -User Guide > Marketing Campaigns - -POST /campaigns/{campaign_id}/schedules/test - - -data = { - "to": "your.email@example.com" -} -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 - - -CATEGORIES - -Retrieve all categories - -This endpoint allows you to retrieve a list of all of your categories. - -Categories can help organize your email analytics by enabling you to tag emails by type or broad topic. You can define your own custom categories. For more information, please see our User Guide. - -GET /categories - - -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 -Retrieve Email Statistics for Categories - -This endpoint allows you to retrieve all of your email statistics for each of your categories. - -If you do not define any query parameters, this endpoint will return a sum for each category in groups of 10. - -Categories allow you to group your emails together according to broad topics that you define. For more information, please see our User Guide. - -GET /categories/stats - - -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 -Retrieve sums of email stats for each category [Needs: Stats object defined, has category ID?] - -This endpoint allows you to retrieve the total sum of each email statistic for every category over the given date range. - -If you do not define any query parameters, this endpoint will return a sum for each category in groups of 10. - -Categories allow you to group your emails together according to broad topics that you define. For more information, please see our User Guide. - -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'} -response = sg.client.categories.stats.sums.get(query_params=params) -print response.status_code -print response.body -print response.headers - - -CLIENTS - -Retrieve email statistics by client type. - -This endpoint allows you to retrieve your email statistics segmented by client type. - -We only store up to 7 days of email activity in our database. By default, 500 items will be returned per request via the Advanced Stats API endpoints. - -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. - -GET /clients/stats - - -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 -Retrieve stats by a specific client type. - -This endpoint allows you to retrieve your email statistics segmented by a specific client type. - -We only store up to 7 days of email activity in our database. By default, 500 items will be returned per request via the Advanced Stats API endpoints. - -Available Client Types - -phone - -tablet - -webmail - -desktop - -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. - -GET /clients/{client_type}/stats - - -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 - - -CONTACTDB - -Create a Custom Field - -This endpoint allows you to create a custom field. - -The contactdb is a database of your contacts for SendGrid Marketing Campaigns. - -POST /contactdb/custom_fields - - -data = { - "name": "pet", - "type": "text" -} -response = sg.client.contactdb.custom_fields.post(request_body=data) -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. - -GET /contactdb/custom_fields - - -response = sg.client.contactdb.custom_fields.get() -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. - -GET /contactdb/custom_fields/{custom_field_id} - - -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 -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. - -DELETE /contactdb/custom_fields/{custom_field_id} - - -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 -Create a List - -This endpoint allows you to create a list for your recipients. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -POST /contactdb/lists - - -data = { - "name": "your list name" -} -response = sg.client.contactdb.lists.post(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve all lists - -This endpoint allows you to retrieve all of your recipient lists. If you don't have any lists, an empty array will be returned. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -GET /contactdb/lists - - -response = sg.client.contactdb.lists.get() -print response.status_code -print response.body -print response.headers -Delete Multiple lists - -This endpoint allows you to delete multiple recipient lists. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -DELETE /contactdb/lists - - -data = [ - 1, - 2, - 3, - 4 -] -response = sg.client.contactdb.lists.delete(request_body=data) -print response.status_code -print response.body -print response.headers -Update a List - -This endpoint allows you to update the name of one of your recipient lists. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -PATCH /contactdb/lists/{list_id} - - -data = { - "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) -print response.status_code -print response.body -print response.headers -Retrieve a single list - -This endpoint allows you to retrieve a single recipient list. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -GET /contactdb/lists/{list_id} - - -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 -Delete a List - -This endpoint allows you to delete a specific recipient list with the given ID. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -DELETE /contactdb/lists/{list_id} - - -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 -Add Multiple Recipients to a List - -This endpoint allows you to add multiple recipients to a list. - -Adds existing recipients to a list, passing in the recipient IDs to add. Recipient IDs should be passed exactly as they are returned from recipient endpoints. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -POST /contactdb/lists/{list_id}/recipients - - -data = [ - "recipient_id1", - "recipient_id2" -] -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 -Retrieve all recipients on a List - -This endpoint allows you to retrieve all recipients on the list with the given ID. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -GET /contactdb/lists/{list_id}/recipients - - -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 -Add a Single Recipient to a List - -This endpoint allows you to add a single recipient to a list. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -POST /contactdb/lists/{list_id}/recipients/{recipient_id} - - -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 -Delete a Single Recipient from a Single List - -This endpoint allows you to delete a single recipient from a list. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -DELETE /contactdb/lists/{list_id}/recipients/{recipient_id} - - -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 -Update Recipient - -This endpoint allows you to update one or more recipients. - -The body of an API call to this endpoint must include an array of one or more recipient objects. - -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. - -PATCH /contactdb/recipients - - -data = [ - { -​ "email": "jones@example.com", -​ "first_name": "Guy", -​ "last_name": "Jones" - } -] -response = sg.client.contactdb.recipients.patch(request_body=data) -print response.status_code -print response.body -print response.headers -Add recipients - -This endpoint allows you to add a Marketing Campaigns recipient. - -It is of note that you can add custom field data as a parameter on this endpoint. We have provided an example using some of the default custom fields SendGrid provides. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -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" - } -] -response = sg.client.contactdb.recipients.post(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve recipients - -This endpoint allows you to retrieve all of your Marketing Campaigns recipients. - -Batch deletion of a page makes it possible to receive an empty page of recipients before reaching the end of -the list of recipients. To avoid this issue; iterate over pages until a 404 is retrieved. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -GET /contactdb/recipients - - -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 -Delete Recipient - -This endpoint allows you to deletes 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. - -DELETE /contactdb/recipients - - -data = [ - "recipient_id1", - "recipient_id2" -] -response = sg.client.contactdb.recipients.delete(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve the count of billable recipients - -This endpoint allows you to retrieve the number of Marketing Campaigns recipients that you will be billed for. - -You are billed for marketing campaigns based on the highest number of recipients you have had in your account at one time. This endpoint will allow you to know the current billable count value. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -GET /contactdb/recipients/billable_count - - -response = sg.client.contactdb.recipients.billable_count.get() -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. - -GET /contactdb/recipients/count - - -response = sg.client.contactdb.recipients.count.get() -print response.status_code -print response.body -print response.headers -Retrieve recipients matching search criteria - -This endpoint allows you to perform a search on all of your Marketing Campaigns recipients. - -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) - -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. - -GET /contactdb/recipients/search - - -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 -Retrieve a single recipient - -This endpoint allows you to retrieve a single recipient by ID from your contact database. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -GET /contactdb/recipients/{recipient_id} - - -recipient_id = "test_url_param" -response = sg.client.contactdb.recipients._(recipient_id).get() -print response.status_code -print response.body -print response.headers -Delete a Recipient - -This endpoint allows you to delete a single recipient with the given ID from your contact database. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -DELETE /contactdb/recipients/{recipient_id} - - -recipient_id = "test_url_param" -response = sg.client.contactdb.recipients._(recipient_id).delete() -print response.status_code -print response.body -print response.headers -Retrieve the lists that a recipient is on - -This endpoint allows you to retrieve the lists that a given recipient belongs to. - -Each recipient can be on many lists. This endpoint gives you all of the lists that any one recipient has been added to. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -GET /contactdb/recipients/{recipient_id}/lists - - -recipient_id = "test_url_param" -response = sg.client.contactdb.recipients._(recipient_id).lists.get() -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. - -GET /contactdb/reserved_fields - - -response = sg.client.contactdb.reserved_fields.get() -print response.status_code -print response.body -print response.headers -Create a Segment - -This endpoint allows you to create a segment. - -All recipients in your contactdb will be added or removed automatically depending on whether they match the criteria for this segment. - -List Id: - -Send this to segment from an existing list - -Don't send this in order to segment from your entire contactdb. - -Valid operators for create and update depend on the type of the field you are segmenting: - -Dates: "eq", "ne", "lt" (before), "gt" (after) - -Text: "contains", "eq" (is - matches the full field), "ne" (is not - matches any field where the entire field is not the condition value) - -Numbers: "eq", "lt", "gt" - -Email Clicks and Opens: "eq" (opened), "ne" (not opened) - -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 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 recipients. - -For more information about segments in Marketing Campaigns, please see our User Guide. - -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" -} -response = sg.client.contactdb.segments.post(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve all segments - -This endpoint allows you to retrieve all of your segments. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -For more information about segments in Marketing Campaigns, please see our User Guide. - -GET /contactdb/segments - - -response = sg.client.contactdb.segments.get() -print response.status_code -print response.body -print response.headers -Update a segment - -This endpoint allows you to update a segment. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -For more information about segments in Marketing Campaigns, please see our User Guide. - -PATCH /contactdb/segments/{segment_id} - - -data = { - "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) -print response.status_code -print response.body -print response.headers -Retrieve a segment - -This endpoint allows you to retrieve a single segment with the given ID. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -For more information about segments in Marketing Campaigns, please see our User Guide. - -GET /contactdb/segments/{segment_id} - - -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 -Delete a segment - -This endpoint allows you to delete a segment from your recipients database. - -You also have the option to delete all the contacts from your Marketing Campaigns recipient database who were in this segment. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -For more information about segments in Marketing Campaigns, please see our User Guide. - -DELETE /contactdb/segments/{segment_id} - - -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 -Retrieve recipients on a segment - -This endpoint allows you to retrieve all of the recipients in a segment with the given ID. - -The Contacts API helps you manage your Marketing Campaigns recipients. - -For more information about segments in Marketing Campaigns, please see our User Guide. - -GET /contactdb/segments/{segment_id}/recipients - - -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 - - -DEVICES - -Retrieve email statistics by device type. - -This endpoint allows you to retrieve your email statistics segmented by the device type. - -We only store up to 7 days of email activity in our database. By default, 500 items will be returned per request via the Advanced Stats API endpoints. - -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. | -| 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. - -GET /devices/stats - - -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 - - -GEO - -Retrieve email statistics by country and state/province. - -This endpoint allows you to retrieve your email statistics segmented by country and state/province. - -We only store up to 7 days of email activity in our database. By default, 500 items will be returned per request via the Advanced Stats API endpoints. - -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. - -GET /geo/stats - - -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 - - -IPS - -Retrieve all IP addresses - -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. - -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. - -GET /ips - - -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 -Retrieve all assigned IPs - -This endpoint allows you to retrieve only assigned IP addresses. - -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. - -GET /ips/assigned - - -response = sg.client.ips.assigned.get() -print response.status_code -print response.body -print response.headers -Create an IP pool. - -This endpoint allows you to create an IP pool. - -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 can only be used with whitelabeled IP addresses. - -If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. - -POST /ips/pools - - -data = { - "name": "marketing" -} -response = sg.client.ips.pools.post(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve all 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. - -If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. - -GET /ips/pools - - -response = sg.client.ips.pools.get() -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 can only be used with whitelabeled IP addresses. - -If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. - -PUT /ips/pools/{pool_name} - - -data = { - "name": "new_pool_name" -} -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 -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 can only be used with whitelabeled IP addresses. - -If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. - -GET /ips/pools/{pool_name} - - -pool_name = "test_url_param" -response = sg.client.ips.pools._(pool_name).get() -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 can only be used with whitelabeled IP addresses. - -If an IP pool is NOT specified for an email, it will use any IP available, including ones in pools. - -DELETE /ips/pools/{pool_name} - - -pool_name = "test_url_param" -response = sg.client.ips.pools._(pool_name).delete() -print response.status_code -print response.body -print response.headers -Add an IP address to a pool - -This endpoint allows you to add an IP address to an IP pool. - -You can add the same IP address to multiple pools. It may take up to 60 seconds for your IP address to be added to a pool after your request is made. - -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. - -POST /ips/pools/{pool_name}/ips - - -data = { - "ip": "0.0.0.0" -} -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 -Remove an IP address from a pool. - -This endpoint allows you to remove an IP address from an IP pool. - -The same IP address can be added to multiple IP pools. - -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. - -DELETE /ips/pools/{pool_name}/ips/{ip} - - -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 -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 for more details on how SendGrid limits your email traffic for IPs in warmup. - -For more general information about warming up IPs, please see our Classroom. - -POST /ips/warmup - - -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 -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 for more details on how SendGrid limits your email traffic for IPs in warmup. - -For more general information about warming up IPs, please see our Classroom. - -GET /ips/warmup - - -response = sg.client.ips.warmup.get() -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 for more details on how SendGrid limits your email traffic for IPs in warmup. - -For more general information about warming up IPs, please see our Classroom. - -GET /ips/warmup/{ip_address} - - -ip_address = "test_url_param" -response = sg.client.ips.warmup._(ip_address).get() -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 for more details on how SendGrid limits your email traffic for IPs in warmup. - -For more general information about warming up IPs, please see our Classroom. - -DELETE /ips/warmup/{ip_address} - - -ip_address = "test_url_param" -response = sg.client.ips.warmup._(ip_address).delete() -print response.status_code -print response.body -print response.headers -Retrieve all IP pools an IP address belongs to - -This endpoint allows you to see which IP pools a particular IP address has been added to. - -The same IP address can be added to multiple IP pools. - -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. - -GET /ips/{ip_address} - - -ip_address = "test_url_param" -response = sg.client.ips._(ip_address).get() -print response.status_code -print response.body -print response.headers - - -MAIL - -Create a batch ID - -This endpoint allows you to generate a new batch ID. This batch ID can be associated with scheduled sends via the mail/send endpoint. - -If you set the SMTPAPI header batch_id, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at anytime up to 10 minutes before the schedule date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint. - -More Information: - -Scheduling Parameters > Batch ID - -POST /mail/batch - - -response = sg.client.mail.batch.post() -print response.status_code -print response.body -print response.headers -Validate batch ID - -This endpoint allows you to validate a batch ID. - -If you set the SMTPAPI header batch_id, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at anytime up to 10 minutes before the schedule date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint. - -More Information: - -Scheduling Parameters > Batch ID - -GET /mail/batch/{batch_id} - - -batch_id = "test_url_param" -response = sg.client.mail.batch._(batch_id).get() -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. - -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. - -For an overview of the v3 Mail Send endpoint, please visit our v3 API Reference - -For more detailed information about how to use the v3 Mail Send endpoint, please visit our Classroom. - -POST /mail/send - -This endpoint has a helper, check it out here. - - -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": "

Thanks
The 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": [ -​ { -​ "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 %>." -​ } - } -} -response = sg.client.mail.send.post(request_body=data) -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 or SMTP Relay. - -GET /mail_settings - - -params = {'limit': 1, 'offset': 1} -response = sg.client.mail_settings.get(query_params=params) -print response.status_code -print response.body -print response.headers -Update address whitelist mail settings - -This endpoint allows you to update your current email address whitelist settings. - -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 or SMTP Relay. - -PATCH /mail_settings/address_whitelist - - -data = { - "enabled": True, - "list": [ -​ "email1@example.com", -​ "example.com" - ] -} -response = sg.client.mail_settings.address_whitelist.patch(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve address whitelist mail settings - -This endpoint allows you to retrieve your current email address whitelist settings. - -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 or SMTP Relay. - -GET /mail_settings/address_whitelist - - -response = sg.client.mail_settings.address_whitelist.get() -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. - -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids Web API or SMTP Relay. - -PATCH /mail_settings/bcc - - -data = { - "email": "email@example.com", - "enabled": False -} -response = sg.client.mail_settings.bcc.patch(request_body=data) -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. - -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids Web API or SMTP Relay. - -GET /mail_settings/bcc - - -response = sg.client.mail_settings.bcc.get() -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. - -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids Web API or SMTP Relay. - -PATCH /mail_settings/bounce_purge - - -data = { - "enabled": True, - "hard_bounces": 5, - "soft_bounces": 5 -} -response = sg.client.mail_settings.bounce_purge.patch(request_body=data) -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. - -Mail settings allow you to tell SendGrid specific things to do to every email that you send to your recipients over SendGrids Web API or SMTP Relay. - -GET /mail_settings/bounce_purge - - -response = sg.client.mail_settings.bounce_purge.get() -print response.status_code -print response.body -print response.headers -Update footer mail settings - -This endpoint allows you to update your current Footer mail settings. - -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 or SMTP Relay. - -PATCH /mail_settings/footer - - -data = { - "enabled": True, - "html_content": "...", - "plain_content": "..." -} -response = sg.client.mail_settings.footer.patch(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve footer mail settings - -This endpoint allows you to retrieve your current Footer mail settings. - -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 or SMTP Relay. - -GET /mail_settings/footer - - -response = sg.client.mail_settings.footer.get() -print response.status_code -print response.body -print response.headers -Update forward bounce mail settings - -This endpoint allows you to update your current bounce forwarding mail settings. - -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 or SMTP Relay. - -PATCH /mail_settings/forward_bounce - - -data = { - "email": "example@example.com", - "enabled": True -} -response = sg.client.mail_settings.forward_bounce.patch(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve forward bounce mail settings - -This endpoint allows you to retrieve your current bounce forwarding mail settings. - -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 or SMTP Relay. - -GET /mail_settings/forward_bounce - - -response = sg.client.mail_settings.forward_bounce.get() -print response.status_code -print response.body -print response.headers -Update forward spam mail settings - -This endpoint allows you to update your current Forward Spam mail settings. - -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 or SMTP Relay. - -PATCH /mail_settings/forward_spam - - -data = { - "email": "", - "enabled": False -} -response = sg.client.mail_settings.forward_spam.patch(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve forward spam mail settings - -This endpoint allows you to retrieve your current Forward Spam mail settings. - -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 or SMTP Relay. - -GET /mail_settings/forward_spam - - -response = sg.client.mail_settings.forward_spam.get() -print response.status_code -print response.body -print response.headers -Update plain content mail settings - -This endpoint allows you to update your current Plain Content mail settings. - -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 or SMTP Relay. - -PATCH /mail_settings/plain_content - - -data = { - "enabled": False -} -response = sg.client.mail_settings.plain_content.patch(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve plain content mail settings - -This endpoint allows you to retrieve your current Plain Content mail settings. - -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 or SMTP Relay. - -GET /mail_settings/plain_content - - -response = sg.client.mail_settings.plain_content.get() -print response.status_code -print response.body -print response.headers -Update spam check mail settings - -This endpoint allows you to update your current spam checker mail settings. - -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 or SMTP Relay. - -PATCH /mail_settings/spam_check - - -data = { - "enabled": True, - "max_score": 5, - "url": "url" -} -response = sg.client.mail_settings.spam_check.patch(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve spam check mail settings - -This endpoint allows you to retrieve your current Spam Checker mail settings. - -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 or SMTP Relay. - -GET /mail_settings/spam_check - - -response = sg.client.mail_settings.spam_check.get() -print response.status_code -print response.body -print response.headers -Update template mail settings - -This endpoint allows you to update your current legacy email template settings. - -This setting refers to our original email templates. We currently support more fully featured transactional templates. - -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 or SMTP Relay. - -PATCH /mail_settings/template - - -data = { - "enabled": True, - "html_content": "<% body %>" -} -response = sg.client.mail_settings.template.patch(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve legacy template mail settings - -This endpoint allows you to retrieve your current legacy email template settings. - -This setting refers to our original email templates. We currently support more fully featured transactional templates. - -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 or SMTP Relay. - -GET /mail_settings/template - - -response = sg.client.mail_settings.template.get() -print response.status_code -print response.body -print response.headers - - -MAILBOX PROVIDERS - -Retrieve email statistics by mailbox provider. - -This endpoint allows you to retrieve your email statistics segmented by recipient mailbox provider. - -We only store up to 7 days of email activity in our database. By default, 500 items will be returned per request via the Advanced Stats API endpoints. - -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. - -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'} -response = sg.client.mailbox_providers.stats.get(query_params=params) -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. - -GET /partner_settings - - -params = {'limit': 1, 'offset': 1} -response = sg.client.partner_settings.get(query_params=params) -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. - -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. - -PATCH /partner_settings/new_relic - - -data = { - "enable_subuser_statistics": True, - "enabled": True, - "license_key": "" -} -response = sg.client.partner_settings.new_relic.patch(request_body=data) -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. - -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. - -GET /partner_settings/new_relic - - -response = sg.client.partner_settings.new_relic.get() -print response.status_code -print response.body -print response.headers - - -SCOPES - -Retrieve a list of scopes for which this user has access. - -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, or the Mail API Endpoint. 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 or Classroom. - -GET /scopes - - -response = sg.client.scopes.get() -print response.status_code -print response.body -print response.headers - - -SENDERS - -Create a Sender Identity - -This endpoint allows you to create a new sender identity. - -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. - -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" -} -response = sg.client.senders.post(request_body=data) -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. - -GET /senders - - -response = sg.client.senders.get() -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. - -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. - -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" -} -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 -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. - -GET /senders/{sender_id} - - -sender_id = "test_url_param" -response = sg.client.senders._(sender_id).get() -print response.status_code -print response.body -print response.headers -Delete a Sender Identity - -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. - -DELETE /senders/{sender_id} - - -sender_id = "test_url_param" -response = sg.client.senders._(sender_id).delete() -print response.status_code -print response.body -print response.headers -Resend Sender Identity Verification - -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. - -POST /senders/{sender_id}/resend_verification - - -sender_id = "test_url_param" -response = sg.client.senders._(sender_id).resend_verification.post() -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 - - -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 Subuser - -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 - -Classroom > How do I add more subusers to my account? - -POST /subusers - - -data = { - "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 -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 - -Classroom > How do I add more subusers to my account? - -GET /subusers - - -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 - -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. - -GET /subusers/reputations - - -params = {'usernames': 'test_string'} -response = sg.client.subusers.reputations.get(query_params=params) -print response.status_code -print response.body -print response.headers -Retrieve email statistics for your subusers. - -This endpoint allows you to retrieve the email statistics for the given subusers. - -You may retrieve statistics for up to 10 different subusers by including an additional subusers parameter for each additional 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. 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. - -GET /subusers/stats - - -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 -Retrieve monthly stats for all subusers - -This endpoint allows you to retrieve the monthly email statistics for all subusers over the given date range. - -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. - -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. - -GET /subusers/stats/monthly - - -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 -Retrieve the totals for each email statistic metric for all subusers. - -This endpoint allows you to retrieve the total sums of each email statistic metric for all subusers over the given date range. - -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. - -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'} -response = sg.client.subusers.stats.sums.get(query_params=params) -print response.status_code -print response.body -print response.headers -Enable/disable a subuser - -This endpoint allows you to enable or disable a subuser. - -For more information about Subusers: - -User Guide > Subusers - -Classroom > How do I add more subusers to my account? - -PATCH /subusers/{subuser_name} - - -data = { - "disabled": 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 -Delete a subuser - -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 Subusers: - -User Guide > Subusers - -Classroom > How do I add more subusers to my account? - -DELETE /subusers/{subuser_name} - - -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).delete() -print response.status_code -print response.body -print response.headers -Update IPs assigned to a subuser - -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. - -More information: - -How to request more IPs - -IPs can be whitelabeled - -PUT /subusers/{subuser_name}/ips - - -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 -Update Monitor Settings for a subuser - -Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails. - -PUT /subusers/{subuser_name}/monitor - - -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 - -Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails. - -POST /subusers/{subuser_name}/monitor - - -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 -Retrieve monitor settings for a subuser - -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 - - -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 - -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 - - -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).monitor.delete() -print response.status_code -print response.body -print response.headers -Retrieve the monthly email statistics for a single subuser - -This endpoint allows you to retrieve the monthly email statistics for 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. - -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. - -GET /subusers/{subuser_name}/stats/monthly - - -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 - - -SUPPRESSION - -Retrieve all blocks - -This endpoint allows you to retrieve a list of all email addresses that are currently on your blocks list. - -Blocks 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. - -GET /suppression/blocks - - -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 -Delete blocks - -This endpoint allows you to delete all email addresses on your blocks list. - -There are two options for deleting blocked emails: - -You can delete all blocked emails by setting delete_all to true in the request body. - -You can delete some blocked emails by specifying the email addresses in an array in the request body. - -Blocks 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. - -DELETE /suppression/blocks - - -data = { - "delete_all": False, - "emails": [ -​ "example1@example.com", -​ "example2@example.com" - ] -} -response = sg.client.suppression.blocks.delete(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. - -Blocks 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. - -GET /suppression/blocks/{email} - - -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 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. - -DELETE /suppression/blocks/{email} - - -email = "test_url_param" -response = sg.client.suppression.blocks._(email).delete() -print response.status_code -print response.body -print response.headers -Retrieve all bounces - -This endpoint allows you to retrieve all of your bounces. - -Bounces are messages that are returned to the server that sent it. - -For more information see: - -User Guide > Bounces for more information - -Glossary > Bounces - -GET /suppression/bounces - - -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 for more information - -Glossary > Bounces - -Classroom > List Scrubbing Guide - -Note: the delete_all and emails parameters should be used independently of each other as they have different purposes. - -DELETE /suppression/bounces - - -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 -Retrieve a Bounce - -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. - -For more information see: - -User Guide > Bounces for more information - -Glossary > Bounces - -Classroom > List Scrubbing Guide - -GET /suppression/bounces/{email} - - -email = "test_url_param" -response = sg.client.suppression.bounces._(email).get() -print response.status_code -print response.body -print response.headers -Delete a bounce - -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 address from your bounce list. - -For more information see: - -User Guide > Bounces for more information - -Glossary > Bounces - -Classroom > List Scrubbing Guide - -DELETE /suppression/bounces/{email} - - -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 all invalid emails - -This endpoint allows you to retrieve a list of all invalid email addresses. - -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. - -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. - -GET /suppression/invalid_emails - - -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 -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: - -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. - -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. - -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. - -DELETE /suppression/invalid_emails - - -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 a specific invalid email - -This endpoint allows you to retrieve a specific invalid email addresses. - -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. - -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. - -GET /suppression/invalid_emails/{email} - - -email = "test_url_param" -response = sg.client.suppression.invalid_emails._(email).get() -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. - -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. - -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. - -DELETE /suppression/invalid_emails/{email} - - -email = "test_url_param" -response = sg.client.suppression.invalid_emails._(email).delete() -print response.status_code -print response.body -print response.headers -Retrieve a specific spam report - -This endpoint allows you to retrieve a specific spam report. - -Spam reports happen when a recipient indicates that they think your email is spam and then their email provider reports this to SendGrid. - -For more information, please see our User Guide. - -GET /suppression/spam_report/{email} - - -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 - -This endpoint allows you to delete a specific spam report. - -Spam reports happen when a recipient indicates that they think your email is spam and then their email provider reports this to SendGrid. - -For more information, please see our User Guide. - -DELETE /suppression/spam_report/{email} - - -email = "test_url_param" -response = sg.client.suppression.spam_report._(email).delete() -print response.status_code -print response.body -print response.headers -Retrieve all spam reports - -This endpoint allows you to retrieve all spam reports. - -Spam reports happen when a recipient indicates that they think your email is spam and then their email provider reports this to SendGrid. - -For more information, please see our User Guide. - -GET /suppression/spam_reports - - -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 -Delete spam reports - -This endpoint allows you to delete your spam reports. - -There are two options for deleting spam reports: - -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. - -Spam reports happen when a recipient indicates that they think your email is spam and then their email provider reports this to SendGrid. - -For more information, please see our User Guide. - -DELETE /suppression/spam_reports - - -data = { - "delete_all": False, - "emails": [ -​ "example1@example.com", -​ "example2@example.com" - ] -} -response = sg.client.suppression.spam_reports.delete(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. - -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. - -GET /suppression/unsubscribes - - -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 - - -TEMPLATES - -Create a transactional template. - -This endpoint allows you to create 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. - -Transactional templates are templates created specifically for transactional email and are not to be confused with Marketing Campaigns templates. For more information about transactional templates, please see our User Guide. - -POST /templates - - -data = { - "name": "example_name" -} -response = sg.client.templates.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. - -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. - -Transactional templates are templates created specifically for transactional email and are not to be confused with Marketing Campaigns templates. For more information about transactional templates, please see our User Guide. - -GET /templates - - -response = sg.client.templates.get() -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. - -Transactional templates are templates created specifically for transactional email and are not to be confused with Marketing Campaigns templates. For more information about transactional templates, please see our User Guide. - -PATCH /templates/{template_id} - - -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 -Retrieve a single transactional template. - -This endpoint allows you to retrieve a single 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. - -Transactional templates are templates created specifically for transactional email and are not to be confused with Marketing Campaigns templates. For more information about transactional templates, please see our User Guide. - -GET /templates/{template_id} - - -template_id = "test_url_param" -response = sg.client.templates._(template_id).get() -print response.status_code -print response.body -print response.headers -Delete a template. - -This endpoint allows you to delete 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. - -Transactional templates are templates created specifically for transactional email and are not to be confused with Marketing Campaigns templates. For more information about transactional templates, please see our User Guide. - -DELETE /templates/{template_id} - - -template_id = "test_url_param" -response = sg.client.templates._(template_id).delete() -print response.status_code -print response.body -print response.headers -Create a new transactional template version. - -This endpoint allows you to create a new version of a template. - -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. - -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" -} -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 -Edit a transactional template version. - -This endpoint allows you to edit a version of one of your transactional templates. - -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. - -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 /templates/{template_id}/versions/{version_id} - - -data = { - "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) -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. - -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. - -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 /templates/{template_id}/versions/{version_id} - - -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 -Delete a transactional template version. - -This endpoint allows you to delete one of your transactional template versions. - -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. - -URI Parameters - -URI PARAMETER TYPE DESCRIPTION -template_id string The ID of the original template -version_id string The ID of the template version -DELETE /templates/{template_id}/versions/{version_id} - - -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 -Activate a transactional template version. - -This endpoint allows you to activate a version of one of your templates. - -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. - -URI Parameters - -URI PARAMETER TYPE DESCRIPTION -template_id string The ID of the original template -version_id string The ID of the template version -POST /templates/{template_id}/versions/{version_id}/activate - - -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 - - -TRACKING SETTINGS - -Retrieve Tracking Settings - -This endpoint allows you to retrieve a list of all tracking settings that you can enable on your account. - -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. - -GET /tracking_settings - - -params = {'limit': 1, 'offset': 1} -response = sg.client.tracking_settings.get(query_params=params) -print response.status_code -print response.body -print response.headers -Update Click Tracking Settings - -This endpoint allows you to change your current click tracking setting. You can enable, or disable, click tracking using this endpoint. - -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. - -PATCH /tracking_settings/click - - -data = { - "enabled": True -} -response = sg.client.tracking_settings.click.patch(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve Click Track Settings - -This endpoint allows you to retrieve your current click tracking 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. - -For more information about tracking, please see our User Guide. - -GET /tracking_settings/click - - -response = sg.client.tracking_settings.click.get() -print response.status_code -print response.body -print response.headers -Update Google Analytics Settings - -This endpoint allows you to update your current setting for Google Analytics. - -For more information about using Google Analytics, please refer to Googles URL Builder and their article on "Best Practices for Campaign Building". - -We default the settings to Googles recommendations. For more information, see Google Analytics Demystified. - -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. - -PATCH /tracking_settings/google_analytics - - -data = { - "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) -print response.status_code -print response.body -print response.headers -Retrieve Google Analytics Settings - -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 and their article on "Best Practices for Campaign Building". - -We default the settings to Googles recommendations. For more information, see Google Analytics Demystified. - -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. - -GET /tracking_settings/google_analytics - - -response = sg.client.tracking_settings.google_analytics.get() -print response.status_code -print response.body -print response.headers -Update Open Tracking Settings - -This endpoint allows you to update your current settings for open tracking. - -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. - -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. - -PATCH /tracking_settings/open - - -data = { - "enabled": True -} -response = sg.client.tracking_settings.open.patch(request_body=data) -print response.status_code -print response.body -print response.headers -Get Open Tracking Settings - -This endpoint allows you to retrieve your current settings for open tracking. - -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. - -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. - -GET /tracking_settings/open - - -response = sg.client.tracking_settings.open.get() -print response.status_code -print response.body -print response.headers -Update Subscription Tracking Settings - -This endpoint allows you to update your current settings for subscription tracking. - -Subscription tracking adds links to the bottom of your emails that allows your recipients to subscribe to, or unsubscribe from, your emails. - -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. - -PATCH /tracking_settings/subscription - - -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 -Retrieve Subscription Tracking Settings - -This endpoint allows you to retrieve your current settings for subscription tracking. - -Subscription tracking adds links to the bottom of your emails that allows your recipients to subscribe to, or unsubscribe from, your emails. - -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. - -GET /tracking_settings/subscription - - -response = sg.client.tracking_settings.subscription.get() -print response.status_code -print response.body -print response.headers - - -USER - -Get a user's account information. - -This endpoint allows you to retrieve your user account details. - -Your user's account information includes the user's account type and reputation. - -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. - -For more information about your user profile: - -SendGrid Account Settings - -GET /user/account - - -response = sg.client.user.account.get() -print response.status_code -print response.body -print response.headers -Retrieve your credit balance - -This endpoint allows you to retrieve the current credit balance for your account. - -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. - -GET /user/credits - - -response = sg.client.user.credits.get() -print response.status_code -print response.body -print response.headers -Update your account email address - -This endpoint allows you to update the email address currently on file for your account. - -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. - -For more information about your user profile: - -SendGrid Account Settings - -PUT /user/email - - -data = { - "email": "example@example.com" -} -response = sg.client.user.email.put(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve your account email address - -This endpoint allows you to retrieve the email address currently on file for your account. - -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. - -For more information about your user profile: - -SendGrid Account Settings - -GET /user/email - - -response = sg.client.user.email.get() -print response.status_code -print response.body -print response.headers -Update your password - -This endpoint allows you to update your password. - -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. - -For more information about your user profile: - -SendGrid Account Settings - -PUT /user/password - - -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 -Update a user's profile - -This endpoint allows you to update your current profile details. - -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. - -For more information about your user profile: - -SendGrid Account Settings - -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. - -PATCH /user/profile - - -data = { - "city": "Orange", - "first_name": "Example", - "last_name": "User" -} -response = sg.client.user.profile.patch(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. - -For more information about your user profile: - -SendGrid Account Settings - -GET /user/profile - - -response = sg.client.user.profile.get() -print response.status_code -print response.body -print response.headers -Cancel or pause a scheduled send - -This endpoint allows you to cancel or pause an email that has been scheduled to be sent. - -If the maximum number of cancellations/pauses are added, HTTP 400 will -be returned. - -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 /user/scheduled_sends - - -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 -Retrieve all scheduled sends - -This endpoint allows you to retrieve all cancel/paused scheduled send information. - -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 - - -response = sg.client.user.scheduled_sends.get() -print response.status_code -print response.body -print response.headers -Update user scheduled send information - -This endpoint allows you to update the status of a scheduled send for the given 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. - -PATCH /user/scheduled_sends/{batch_id} - - -data = { - "status": "pause" -} -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 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} - - -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 - -This endpoint allows you to delete the cancellation/pause of a scheduled send. - -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} - - -batch_id = "test_url_param" -response = sg.client.user.scheduled_sends._(batch_id).delete() -print response.status_code -print response.body -print response.headers -Update Enforced TLS settings - -This endpoint allows you to update your current Enforced TLS settings. - -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 for more information on opportunistic TLS. - -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. - -PATCH /user/settings/enforced_tls - - -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 -Retrieve current Enforced TLS settings. - -This endpoint allows you to retrieve your current Enforced TLS settings. - -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 for more information on opportunistic TLS. - -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. - -GET /user/settings/enforced_tls - - -response = sg.client.user.settings.enforced_tls.get() -print response.status_code -print response.body -print response.headers -Update your username - -This endpoint allows you to update the username for your account. - -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. - -For more information about your user profile: - -SendGrid Account Settings - -PUT /user/username - - -data = { - "username": "test_username" -} -response = sg.client.user.username.put(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve your username - -This endpoint allows you to retrieve your current account username. - -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. - -For more information about your user profile: - -SendGrid Account Settings - -GET /user/username - - -response = sg.client.user.username.get() -print response.status_code -print response.body -print response.headers -Update Event Notification Settings - -This endpoint allows you to update your current event webhook settings. - -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. - -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. - -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" -} -response = sg.client.user.webhooks.event.settings.patch(request_body=data) -print response.status_code -print response.body -print response.headers -Retrieve Event Webhook settings - -This endpoint allows you to retrieve your current event webhook settings. - -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. - -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 /user/webhooks/event/settings - - -response = sg.client.user.webhooks.event.settings.get() -print response.status_code -print response.body -print response.headers -Test Event Notification Settings - -This endpoint allows you to test your event webhook by sending a fake event notification post to the provided URL. - -SendGrids Event Webhook will notify a URL of your choice via HTTP POST with information about events that occur as SendGrid processes your email. - -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. - -POST /user/webhooks/event/test - - -data = { - "url": "url" -} -response = sg.client.user.webhooks.event.test.post(request_body=data) -print response.status_code -print response.body -print response.headers -Create a parse setting - -This endpoint allows you to create a new inbound parse setting. - -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. - -POST /user/webhooks/parse/settings - - -data = { - "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 -print response.body -print response.headers -Retrieve all parse settings - -This endpoint allows you to retrieve all of your current inbound parse settings. - -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. - -GET /user/webhooks/parse/settings - - -response = sg.client.user.webhooks.parse.settings.get() -print response.status_code -print response.body -print response.headers -Update a parse setting - -This endpoint allows you to update a specific inbound parse setting. - -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. - -PATCH /user/webhooks/parse/settings/{hostname} - - -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 -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 content, and then have that content POSTed by SendGrid to a URL of your choosing. For more information, please see our User Guide. - -GET /user/webhooks/parse/settings/{hostname} - - -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 - -This endpoint allows you to delete a specific inbound parse setting. - -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. - -DELETE /user/webhooks/parse/settings/{hostname} - - -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. - -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 SendGrid Parse Webhook which make processing events easy. You can find these integrations in the Library Index. - -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'} -response = sg.client.user.webhooks.parse.stats.get(query_params=params) -print response.status_code -print response.body -print response.headers - - -WHITELABEL - -Create a domain whitelabel. - -This endpoint allows you to create a whitelabel for one of your domains. - -If you are creating a domain whitelabel that you would like a subuser to use, you have two options: - -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. - -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. - -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 on whitelabeling, please see our User Guide - -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" -} -response = sg.client.whitelabel.domains.post(request_body=data) -print response.status_code -print response.body -print response.headers -List all domain whitelabels. - -This endpoint allows you to retrieve a list of all domain whitelabels you have created. - -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 on whitelabeling, please see our User Guide - -GET /whitelabel/domains - - -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. - -This endpoint allows you to retrieve the default whitelabel for a domain. - -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 on whitelabeling, please see our User Guide - -URI Parameters - -URI PARAMETER TYPE DESCRIPTION -domain string The domain to find a default domain whitelabel for. -GET /whitelabel/domains/default - - -response = sg.client.whitelabel.domains.default.get() -print response.status_code -print response.body -print response.headers -List the domain whitelabel associated with the given user. - -This endpoint allows you to retrieve all of the whitelabels that have been assigned to a specific 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 parent may then associate the whitelabel via the subuser management tools. - -For more information on whitelabeling, please see our User Guide - -URI Parameters - -URI PARAMETER TYPE DESCRIPTION -username string Username of the subuser to find associated whitelabels for. -GET /whitelabel/domains/subuser - - -response = sg.client.whitelabel.domains.subuser.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 parent may then associate the whitelabel via the subuser management tools. - -For more information on whitelabeling, please see our User Guide - -URI Parameters - -URI PARAMETER TYPE REQUIRED? DESCRIPTION -username string required Username for the subuser to find associated whitelabels for. -DELETE /whitelabel/domains/subuser - - -response = sg.client.whitelabel.domains.subuser.delete() -print response.status_code -print response.body -print response.headers -Update a domain whitelabel. - -This endpoint allows you to update the settings for a domain whitelabel. - -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 on whitelabeling, please see our User Guide - -PATCH /whitelabel/domains/{domain_id} - - -data = { - "custom_spf": True, - "default": False -} -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 -Retrieve a domain whitelabel. - -This endpoint allows you to retrieve a specific domain whitelabel. - -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 on whitelabeling, please see our User Guide - -GET /whitelabel/domains/{domain_id} - - -domain_id = "test_url_param" -response = sg.client.whitelabel.domains._(domain_id).get() -print response.status_code -print response.body -print response.headers -Delete a domain whitelabel. - -This endpoint allows you to delete a domain whitelabel. - -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 on whitelabeling, please see our User Guide - -DELETE /whitelabel/domains/{domain_id} - - -domain_id = "test_url_param" -response = sg.client.whitelabel.domains._(domain_id).delete() -print response.status_code -print response.body -print response.headers -Associate a domain whitelabel with a given user. - -This endpoint allows you to associate a specific domain whitelabel with 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 parent may then associate the whitelabel via the subuser management tools. - -For more information on whitelabeling, please see our User Guide - -URI Parameters - -URI PARAMETER TYPE DESCRIPTION -domain_id integer ID of the domain whitelabel to associate with the subuser. -POST /whitelabel/domains/{domain_id}/subuser - - -data = { - "username": "jane@example.com" -} -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 -Add an IP to a domain whitelabel. - -This endpoint allows you to add an IP address to a domain whitelabel. - -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 on whitelabeling, please see our User Guide - -URI Parameters - -URI PARAMETER TYPE DESCRIPTION -id integer ID of the domain to which you are adding an IP -POST /whitelabel/domains/{id}/ips - - -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 -Remove an IP from a domain whitelabel. - -This endpoint allows you to remove a domain's IP address from that domain's whitelabel. - -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 on whitelabeling, please see our User Guide - -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. -DELETE /whitelabel/domains/{id}/ips/{ip} - - -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 -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. - -For more information on whitelabeling, please see our User Guide - -URI Parameters - -URI PARAMETER TYPE DESCRIPTION -id integer ID of the domain whitelabel to validate. -POST /whitelabel/domains/{id}/validate - - -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 - -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. - -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. - -For more information, please see our User Guide. - -POST /whitelabel/ips - - -data = { - "domain": "example.com", - "ip": "192.168.1.1", - "subdomain": "email" -} -response = sg.client.whitelabel.ips.post(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 created 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."). - -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. - -For more information, please see our User Guide. - -GET /whitelabel/ips - - -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 -Retrieve an IP whitelabel - -This endpoint allows you to retrieve an IP whitelabel. - -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. - -For more information, please see our User Guide. - -GET /whitelabel/ips/{id} - - -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 - -This endpoint allows you to delete an IP whitelabel. - -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. - -For more information, please see our User Guide. - -DELETE /whitelabel/ips/{id} - - -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 - -This endpoint allows you to validate an IP whitelabel. - -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. - -For more information, please see our User Guide. - -POST /whitelabel/ips/{id}/validate - - -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 - -This endpoint allows you to create a new link whitelabel. - -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, please see our User Guide. - -POST /whitelabel/links - - -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 -Retrieve all link whitelabels - -This endpoint allows you to retrieve all link whitelabels. - -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, please see our User Guide. - -GET /whitelabel/links - - -params = {'limit': 1} -response = sg.client.whitelabel.links.get(query_params=params) -print response.status_code -print response.body -print response.headers -Retrieve a Default Link Whitelabel - -This endpoint allows you to retrieve the default link whitelabel. - -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) - -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, please see our User Guide. - -GET /whitelabel/links/default - - -params = {'domain': 'test_string'} -response = sg.client.whitelabel.links.default.get(query_params=params) -print response.status_code -print response.body -print response.headers -Retrieve Associated Link Whitelabel - -This endpoint allows you to retrieve the associated link whitelabel for a subuser. - -Link whitelables can be associated with subusers from the parent account. This functionality allows -subusers to send mail using their parent's link 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. - -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, please see our User Guide. - -GET /whitelabel/links/subuser - - -params = {'username': 'test_string'} -response = sg.client.whitelabel.links.subuser.get(query_params=params) -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. - -Link whitelables can be associated with subusers from the parent account. This functionality allows -subusers to send mail using their parent's link 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. - -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, please see our User Guide. - -DELETE /whitelabel/links/subuser - - -params = {'username': 'test_string'} -response = sg.client.whitelabel.links.subuser.delete(query_params=params) -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. - -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, please see our User Guide. - -PATCH /whitelabel/links/{id} - - -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 Link Whitelabel - -This endpoint allows you to retrieve a specific link whitelabel. - -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, please see our User Guide. - -GET /whitelabel/links/{id} - - -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 - -This endpoint allows you to delete a link whitelabel. - -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, please see our User Guide. - -DELETE /whitelabel/links/{id} - - -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 - -This endpoint allows you to validate a link whitelabel. - -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, please see our User Guide. - -POST /whitelabel/links/{id}/validate - - -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 - -This endpoint allows you to associate a link whitelabel with a subuser account. - -Link whitelables can be associated with subusers from the parent account. This functionality allows -subusers to send mail using their parent's link 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. - -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, please see our User Guide. - -POST /whitelabel/links/{link_id}/subuser - - -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.headersPOST /access_settings/whitelist +### POST /access_settings/whitelist ```python @@ -4912,7 +291,7 @@ print response.headers **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. @@ -4959,7 +338,7 @@ print response.headers **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). @@ -5028,7 +407,7 @@ print response.headers **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 propagation 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). @@ -5055,7 +434,7 @@ print response.headers **This endpoint allows you to create a new suppression group.** -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. +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. @@ -5099,7 +478,7 @@ print response.headers **This endpoint allows you to update or change a suppression group.** -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. +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. @@ -5124,7 +503,7 @@ print response.headers **This endpoint allows you to retrieve a single suppression group.** -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. +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. @@ -5146,7 +525,7 @@ 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 emails 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. @@ -5333,7 +712,7 @@ print response.headers # BROWSERS -## Retrieve email statistics by browser. +## Retrieve email statistics by the browser. **This endpoint allows you to retrieve your email statistics segmented by browser type.** @@ -5360,7 +739,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: @@ -6039,7 +1418,7 @@ 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. @@ -6097,7 +1476,7 @@ 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 @@ -6151,7 +1530,7 @@ print response.headers **This endpoint allows you to retrieve the lists that a given recipient belongs to.** -Each recipient can be on many lists. This endpoint gives you all of the lists that any one recipient has been added to. +Each recipient can be on many lists. This endpoint gives you all of the lists that anyone recipient has been added to. The Contacts API helps you manage your [Marketing Campaigns](https://sendgrid.com/docs/User_Guide/Marketing_Campaigns/index.html) recipients. @@ -6308,7 +1687,7 @@ 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. @@ -6358,10 +1737,10 @@ print response.headers ## Available Device Types | **Device** | **Description** | **Example** | |---|---|---| -| Desktop | Email software on desktop computer. | I.E., Outlook, Sparrow, or Apple Mail. | +| 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 smart phone. | iPhone, Android, Blackberry, etc. -| Tablet | A tablet computer. | iPad, android based tablet, etc. | +| 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). @@ -6404,7 +1783,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 whitelabel 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. @@ -6677,7 +2056,7 @@ print response.headers **This endpoint allows you to generate a new batch ID. This batch ID can be associated with scheduled sends via the mail/send endpoint.** -If you set the SMTPAPI header `batch_id`, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at anytime up to 10 minutes before the schedule date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint. +If you set the SMTPAPI header `batch_id`, it allows you to then associate multiple scheduled mails/send requests together with the same ID. Then at any time up to 10 minutes before the scheduled date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint. More Information: @@ -6696,7 +2075,7 @@ print response.headers **This endpoint allows you to validate a batch ID.** -If you set the SMTPAPI header `batch_id`, it allows you to then associate multiple scheduled mail/send requests together with the same ID. Then at anytime up to 10 minutes before the schedule date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint. +If you set the SMTPAPI header `batch_id`, it allows you to then associate multiple scheduled mails/send requests together with the same ID. Then at anytime up to 10 minutes before the scheduled date, you can cancel all of the mail/send requests that have this batch ID by calling the Cancel Scheduled Send endpoint. More Information: @@ -6935,7 +2314,7 @@ print response.headers **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, 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). @@ -6956,7 +2335,7 @@ print response.headers **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, 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). @@ -7347,7 +2726,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 whitelabeled it will auto verify on creation. Otherwise, an email will be sent to the `from.email`. ### POST /senders @@ -7379,7 +2758,7 @@ print response.headers **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 whitelabeled it will auto verify on creation. Otherwise, an email will be sent to the `from.email`. ### GET /senders @@ -7394,7 +2773,7 @@ print response.headers **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 whitelabeled 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. @@ -7429,7 +2808,7 @@ print response.headers **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 whitelabeled it will auto verify on creation. Otherwise, an email will be sent to the `from.email`. ### GET /senders/{sender_id} @@ -7445,7 +2824,7 @@ print response.headers **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 whitelabeled it will auto verify on creation. Otherwise, an email will be sent to the `from.email`. ### DELETE /senders/{sender_id} @@ -7461,7 +2840,7 @@ print response.headers **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 whitelabeled it will auto verify on creation. Otherwise, an email will be sent to the `from.email`. ### POST /senders/{sender_id}/resend_verification @@ -7543,7 +2922,7 @@ print response.headers ``` ## Retrieve Subuser Reputations -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. +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 affect your sender rating. This endpoint allows you to request the reputations for your subusers. @@ -7952,7 +3331,7 @@ print response.headers **This endpoint allows you to retrieve a list of all invalid email addresses.** -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. +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 recipient's mail server. 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. @@ -7977,7 +3356,7 @@ There are two options for deleting invalid email addresses: 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. -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. +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 recipient's mail server. 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. @@ -8001,9 +3380,9 @@ print response.headers ``` ## Retrieve a specific invalid email -**This endpoint allows you to retrieve a specific invalid email addresses.** +**This endpoint allows you to retrieve a specific invalid email addresse.** -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. +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 recipient's mail server. 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. @@ -8023,7 +3402,7 @@ print response.headers **This endpoint allows you to remove a specific email address from the invalid email address list.** -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. +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 recipient's mail server. 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. @@ -8124,7 +3503,7 @@ print response.headers ``` ## Retrieve all global suppressions -**This endpoint allows you to retrieve a list of all email address that are globally suppressed.** +**This endpoint allows you to retrieve a list of all email address that is globally suppressed.** 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). @@ -8242,7 +3621,7 @@ print response.headers **This endpoint allows you to create a new version of a template.** -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 transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across all templates. For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). @@ -8269,7 +3648,7 @@ print response.headers **This endpoint allows you to edit a version of one of your transactional templates.** -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 transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across all templates. For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). @@ -8301,7 +3680,7 @@ print response.headers **This endpoint allows you to retrieve a specific version of a template.** -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 transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across all templates. For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). @@ -8326,7 +3705,7 @@ print response.headers **This endpoint allows you to delete one of your transactional template versions.** -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 transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across all templates. For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). @@ -8351,7 +3730,7 @@ print response.headers **This endpoint allows you to activate a version of one of your templates.** -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 transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across all templates. For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). @@ -8721,7 +4100,7 @@ print response.headers If the maximum number of cancellations/pauses are added, HTTP 400 will be returned. -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. +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 canceled less than 10 minutes before the scheduled time are not guaranteed to be canceled. ### POST /user/scheduled_sends @@ -8740,7 +4119,7 @@ print response.headers **This endpoint allows you to retrieve all cancel/paused scheduled send information.** -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. +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 canceled less than 10 minutes before the scheduled time are not guaranteed to be canceled. ### GET /user/scheduled_sends @@ -8755,7 +4134,7 @@ print response.headers **This endpoint allows you to update the status of a scheduled send for the given `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. +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 canceled less than 10 minutes before the scheduled time are not guaranteed to be canceled. ### PATCH /user/scheduled_sends/{batch_id} @@ -8774,7 +4153,7 @@ print response.headers **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. +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 canceled less than 10 minutes before the scheduled time are not guaranteed to be canceled. ### GET /user/scheduled_sends/{batch_id} @@ -8790,7 +4169,7 @@ print response.headers **This endpoint allows you to delete the cancellation/pause of a scheduled send.** -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. +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 canceled less than 10 minutes before the scheduled time are not guaranteed to be canceled. ### DELETE /user/scheduled_sends/{batch_id} From 6551f9a303c9e0c1ec0b2a40acd78132d7211192 Mon Sep 17 00:00:00 2001 From: Chandler Weiner Date: Wed, 17 Oct 2018 16:27:57 -0400 Subject: [PATCH 63/82] Remove "Whitelist" and replace with other terms Per the [SendGrid Docs](https://github.com/sendgrid/docs/blob/develop/content/docs/glossary/whitelabel.md), the term "whitelabel" is sunset and needs to be replaced with other words, even though the API still calls it Whitelabeling. --- USAGE.md | 2071 +++++++++++++++++++++++++++--------------------------- 1 file changed, 1037 insertions(+), 1034 deletions(-) diff --git a/USAGE.md b/USAGE.md index 09b78609a..b14656ba8 100644 --- a/USAGE.md +++ b/USAGE.md @@ -30,13 +30,13 @@ sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) * [PARTNER SETTINGS](#partner-settings) * [SCOPES](#scopes) * [SENDERS](#senders) +* [SENDER Authorization](#sender-authorization) * [STATS](#stats) * [SUBUSERS](#subusers) * [SUPPRESSION](#suppression) * [TEMPLATES](#templates) * [TRACKING SETTINGS](#tracking-settings) * [USER](#user) -* [WHITELABEL](#whitelabel) @@ -2852,2184 +2852,2187 @@ 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. + +# Sender Authentication -### GET /stats - - -```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 a new domain authentication. -## Create Subuser +**This endpoint allows you to create an authenticated domain.** -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 domain 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 authenticated domain, 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 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. -* [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/ui/account-and-settings/how-to-set-up-domain-authentication/) -### 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) +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 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. -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/ui/account-and-settings/how-to-set-up-domain-authentication/) -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) +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 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 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. -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/ui/account-and-settings/how-to-set-up-domain-authentication/) -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 whitelabel 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) +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 authentications 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 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. -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 authentication and validate it. The parent may then associate the domain 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/ui/account-and-settings/how-to-set-up-domain-authentication/) -### GET /subusers/stats/monthly +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| username | string | Username of the subuser to find associated whitelabels 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) +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 authenticated domain 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 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. -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 authentication and validate it. The parent may then associate the domain 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/ui/account-and-settings/how-to-set-up-domain-authentication/) -### GET /subusers/stats/sums +## URI Parameters +| URI Parameter | Type | Required? | Description | +|---|---|---|---| +| username | string | required | Username for the subuser to find associated whitelabels 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) +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 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. -* [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/ui/account-and-settings/how-to-set-up-domain-authentication/) -### 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) +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 you delete a subuser it 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 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. -* [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/ui/account-and-settings/how-to-set-up-domain-authentication/) -### DELETE /subusers/{subuser_name} + +### GET /whitelabel/domains/{domain_id} ```python -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).delete() +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 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. -* [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/ui/account-and-settings/how-to-set-up-domain-authentication/) -### 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) +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 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 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 authentication and validate it. The parent may then associate the domain authentication via the subuser management tools. + +For more information on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| domain_id | integer | ID of the domain whitelabel to associate with the subuser. | + +### POST /whitelabel/domains/{domain_id}/subuser ```python data = { - "email": "example@example.com", - "frequency": 500 + "username": "jane@example.com" } -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).monitor.put(request_body=data) +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 ``` -## Create monitor settings +## Add an IP to an authenticated domain. -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 add an IP address to an authenticated domain.** -### POST /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 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 on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| id | integer | ID of the domain to which you are adding an IP | + +### POST /whitelabel/domains/{id}/ips ```python data = { - "email": "example@example.com", - "frequency": 50000 + "ip": "192.168.0.1" } -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).monitor.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 ``` -## Retrieve monitor settings for a subuser +## Remove an IP from an authenticated domain. -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 remove a domain's IP address from an authenticated domain.** -### GET /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 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 on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/)) + +## 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. | + +### DELETE /whitelabel/domains/{id}/ips/{ip} ```python -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).monitor.get() +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 ``` -## Delete monitor settings +## Validate 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. +**This endpoint allows you to validate a domain authentication. If it fails, it will return an error message describing why the domain authentication could not be validated.** -### DELETE /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 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 on domain authentication, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/) + + +## URI Parameters +| URI Parameter | Type | Description | +|---|---|---| +| id | integer |ID of the domain whitelabel to validate. | + +### POST /whitelabel/domains/{id}/validate ```python -subuser_name = "test_url_param" -response = sg.client.subusers._(subuser_name).monitor.delete() +id = "test_url_param" +response = sg.client.whitelabel.domains._(id).validate.post() print response.status_code print response.body print response.headers ``` -## Retrieve the monthly email statistics for a single subuser +## Setup reverse DNS -**This endpoint allows you to retrieve the monthly email statistics for a specific subuser.** +**This endpoint allows you to setup reverse DNS.** -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. +When setting up reverse DNS, you should use the same subdomain that you used when you created a domain authentication. -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`. +Reverse DNS 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. -For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html). +For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-reverse-dns/). -### GET /subusers/{subuser_name}/stats/monthly +### POST /whitelabel/ips ```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) +data = { + "domain": "example.com", + "ip": "192.168.1.1", + "subdomain": "email" +} +response = sg.client.whitelabel.ips.post(request_body=data) print response.status_code print response.body print response.headers ``` - -# SUPPRESSION +## Retrieve all reverse DNS records -## Retrieve all blocks +**This endpoint allows you to retrieve all of the reverse DNS that have been created by this account.** -**This endpoint allows you to retrieve a list of all email addresses that are currently on your blocks list.** +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."). -[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 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. -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/). -### GET /suppression/blocks +### GET /whitelabel/ips ```python -params = {'start_time': 1, 'limit': 1, 'end_time': 1, 'offset': 1} -response = sg.client.suppression.blocks.get(query_params=params) +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 blocks +## Retrieve an reverse DNS setting -**This endpoint allows you to delete all email addresses on your blocks list.** +**This endpoint allows you to retrieve an reverse DNS setting.** -There are two options for deleting blocked emails: +Reverse DNS 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. -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. - -[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). +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 +### GET /whitelabel/ips/{id} ```python -data = { - "delete_all": False, - "emails": [ - "example1@example.com", - "example2@example.com" - ] -} -response = sg.client.suppression.blocks.delete(request_body=data) +id = "test_url_param" +response = sg.client.whitelabel.ips._(id).get() print response.status_code print response.body print response.headers ``` -## Retrieve a specific block +## Delete an reverse DNS record -**This endpoint allows you to retrieve a specific email address from your blocks list.** +**This endpoint allows you to delete an 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. +Reverse DNS 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. -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/). -### GET /suppression/blocks/{email} +### DELETE /whitelabel/ips/{id} ```python -email = "test_url_param" -response = sg.client.suppression.blocks._(email).get() +id = "test_url_param" +response = sg.client.whitelabel.ips._(id).delete() print response.status_code print response.body print response.headers ``` -## Delete a specific block +## Validate an reverse DNS record -**This endpoint allows you to delete a specific email address from your blocks list.** +**This endpoint allows you to validate an 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. +Reverse DNS 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. -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/{email} +### POST /whitelabel/ips/{id}/validate ```python -email = "test_url_param" -response = sg.client.suppression.blocks._(email).delete() +id = "test_url_param" +response = sg.client.whitelabel.ips._(id).validate.post() print response.status_code print response.body print response.headers ``` -## Retrieve all bounces - -**This endpoint allows you to retrieve all of your bounces.** +## Create Link Branding -Bounces are messages that are returned to the server that sent it. +**This endpoint allows you to create a new branded link.** -For more information see: +Link branding allows 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) +For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-link-branding/). -### GET /suppression/bounces +### POST /whitelabel/links ```python -params = {'start_time': 1, 'end_time': 1} -response = sg.client.suppression.bounces.get(query_params=params) +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 bounces +## Retrieve all link brands -**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: +**This endpoint allows you to retrieve all branded links.** -* [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) +Link branding allows all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net. -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/ui/account-and-settings/how-to-set-up-link-branding/). -### DELETE /suppression/bounces +### GET /whitelabel/links ```python -data = { - "delete_all": True, - "emails": [ - "example@example.com", - "example2@example.com" - ] -} -response = sg.client.suppression.bounces.delete(request_body=data) +params = {'limit': 1} +response = sg.client.whitelabel.links.get(query_params=params) print response.status_code print response.body print response.headers ``` -## Retrieve a Bounce +## Retrieve a Default Link Branding -**This endpoint allows you to retrieve a specific bounce for a given email address.** +**This endpoint allows you to retrieve the default link branding.** -Bounces are messages that are returned to the server that sent it. +Default link branding is the actual link whitelabel to be used when sending messages. If there are multiple branded links, the default is determined by the following order: +
    +
  • Validated link branding marked as "default"
  • +
  • Legacy link whitelabels (migrated from the whitelabel wizard)
  • +
  • Default SendGrid link whitelabel (i.e. 100.ct.sendgrid.net)
  • +
-For more information see: +Link branding allows 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/ui/account-and-settings/how-to-set-up-link-branding/). -### GET /suppression/bounces/{email} +### GET /whitelabel/links/default ```python -email = "test_url_param" -response = sg.client.suppression.bounces._(email).get() +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 a bounce +## Retrieve Associated Link Branding -**This endpoint allows you to remove an email address from your bounce list.** +**This endpoint allows you to retrieve the associated link branding for a subuser.** -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. +Link branding can be associated with subusers from the parent account. This functionality allows +subusers to send mail using their parent's link branding. To associate a link branding, the parent account +must first create a branded link 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. -For more information see: +Link branding allows 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/ui/account-and-settings/how-to-set-up-link-branding/). -### DELETE /suppression/bounces/{email} +### GET /whitelabel/links/subuser ```python -params = {'email_address': 'example@example.com'} -email = "test_url_param" -response = sg.client.suppression.bounces._(email).delete(query_params=params) +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 all invalid emails +## Disassociate a Link Branding -**This endpoint allows you to retrieve a list of all 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 branding can be associated with subusers from the parent account. This functionality allows +subusers to send mail using their parent's link branding. To associate a link branding, the parent account +must first create a branded link 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. +Link branding allows 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/ui/account-and-settings/how-to-set-up-link-branding/). -### GET /suppression/invalid_emails +### DELETE /whitelabel/links/subuser ```python -params = {'start_time': 1, 'limit': 1, 'end_time': 1, 'offset': 1} -response = sg.client.suppression.invalid_emails.get(query_params=params) +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 invalid emails +## Update a Link Branding -**This endpoint allows you to remove email addresses from your invalid email address list.** - -There are two options for deleting invalid email addresses: - -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. - -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. +Link branding allows 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/ui/account-and-settings/how-to-set-up-link-branding/). -### DELETE /suppression/invalid_emails +### PATCH /whitelabel/links/{id} ```python data = { - "delete_all": False, - "emails": [ - "example1@example.com", - "example2@example.com" - ] + "default": True } -response = sg.client.suppression.invalid_emails.delete(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 specific invalid email - -**This endpoint allows you to retrieve a specific invalid email addresses.** +## Retrieve 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 retrieve a specific link branding.** -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. +Link branding allows 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/ui/account-and-settings/how-to-set-up-link-branding/). -### GET /suppression/invalid_emails/{email} +### GET /whitelabel/links/{id} ```python -email = "test_url_param" -response = sg.client.suppression.invalid_emails._(email).get() +id = "test_url_param" +response = sg.client.whitelabel.links._(id).get() 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.** +## Delete 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 delete a link branding.** -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. +Link branding allows 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/ui/account-and-settings/how-to-set-up-link-branding/). -### DELETE /suppression/invalid_emails/{email} +### DELETE /whitelabel/links/{id} ```python -email = "test_url_param" -response = sg.client.suppression.invalid_emails._(email).delete() +id = "test_url_param" +response = sg.client.whitelabel.links._(id).delete() print response.status_code print response.body print response.headers ``` -## Retrieve a specific spam report +## Validate a Link Branding -**This endpoint allows you to retrieve a specific spam report.** +**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. +Link branding allows 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/ui/account-and-settings/how-to-set-up-link-branding/). -### GET /suppression/spam_report/{email} +### POST /whitelabel/links/{id}/validate ```python -email = "test_url_param" -response = sg.client.suppression.spam_report._(email).get() +id = "test_url_param" +response = sg.client.whitelabel.links._(id).validate.post() print response.status_code print response.body print response.headers ``` -## Delete a specific spam report +## Associate a Link Branding -**This endpoint allows you to delete a specific spam report.** +**This endpoint allows you to associate a link branding with a subuser account.** -[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. +Link branding can be associated with subusers from the parent account. This functionality allows +subusers to send mail using their parent's link branding. To associate a link branding, the parent account +must first create a branded link 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. -For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html). +Link branding allows all of the click-tracked links you send in your emails to include the URL of your domain instead of sendgrid.net. -### DELETE /suppression/spam_report/{email} +For more information, please see our [User Guide](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-link-branding/). + +### POST /whitelabel/links/{link_id}/subuser ```python -email = "test_url_param" -response = sg.client.suppression.spam_report._(email).delete() +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 ``` -## Retrieve all spam reports -**This endpoint allows you to retrieve all spam reports.** -[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. + +# STATS -For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.html). +## Retrieve global email statistics -### GET /suppression/spam_reports +**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.spam_reports.get(query_params=params) +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 ``` -## Delete spam reports - -**This endpoint allows you to delete your spam reports.** + +# SUBUSERS -There are two options for deleting spam reports: +## Create Subuser -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. +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. -[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. +For more information about Subusers: -For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/spam_reports.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) -### DELETE /suppression/spam_reports +### POST /subusers ```python data = { - "delete_all": False, - "emails": [ - "example1@example.com", - "example2@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.suppression.spam_reports.delete(request_body=data) +response = sg.client.subusers.post(request_body=data) print response.status_code print response.body print response.headers ``` -## Retrieve all global suppressions +## List all Subusers -**This endpoint allows you to retrieve a list of all email address that are globally suppressed.** +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. -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). +For more information about Subusers: -### GET /suppression/unsubscribes +* [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 -params = {'start_time': 1, 'limit': 1, 'end_time': 1, 'offset': 1} -response = sg.client.suppression.unsubscribes.get(query_params=params) +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 ``` - -# TEMPLATES +## Retrieve Subuser Reputations -## Create a transactional template. - -**This endpoint allows you to create 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. +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. -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). +This endpoint allows you to request the reputations for your subusers. -### POST /templates +### GET /subusers/reputations ```python -data = { - "name": "example_name" -} -response = sg.client.templates.post(request_body=data) +params = {'usernames': 'test_string'} +response = sg.client.subusers.reputations.get(query_params=params) print response.status_code print response.body print response.headers ``` -## Retrieve all transactional templates. +## Retrieve email statistics for your subusers. -**This endpoint allows you to retrieve all transactional templates.** +**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. -### GET /templates +For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html). + +### GET /subusers/stats ```python -response = sg.client.templates.get() +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 ``` -## Edit a transactional template. +## Retrieve monthly stats for all subusers -**This endpoint allows you to edit 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). -### PATCH /templates/{template_id} +### GET /subusers/stats/monthly ```python -data = { - "name": "new_example_name" -} -template_id = "test_url_param" -response = sg.client.templates._(template_id).patch(request_body=data) +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 ``` -## Retrieve a single transactional template. +## Retrieve the totals for each email statistic metric for all subusers. -**This endpoint allows you to retrieve a single transactional template.** +**This endpoint allows you to retrieve the total sums of each email statistic metric 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. -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/sums ```python -template_id = "test_url_param" -response = sg.client.templates._(template_id).get() +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 ``` -## Delete a template. - -**This endpoint allows you to delete a transactional template.** +## Enable/disable a subuser -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 enable or disable a 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). +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) -### DELETE /templates/{template_id} +### PATCH /subusers/{subuser_name} ```python -template_id = "test_url_param" -response = sg.client.templates._(template_id).delete() +data = { + "disabled": 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 ``` -## Create a new transactional template version. +## Delete a subuser -**This endpoint allows you to create a new version of a template.** +This endpoint allows you to delete a subuser. This is a permanent action, once you delete a subuser it cannot be retrieved. -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 Subusers: -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) +### DELETE /subusers/{subuser_name} -### POST /templates/{template_id}/versions + +```python +subuser_name = "test_url_param" +response = sg.client.subusers._(subuser_name).delete() +print response.status_code +print response.body +print response.headers +``` +## Update IPs assigned to a subuser + +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. + +More information: + +* [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) + +### PUT /subusers/{subuser_name}/ips ```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) +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 ``` -## Edit a transactional template version. +## Update Monitor Settings for a subuser -**This endpoint allows you to edit a version of one of your transactional 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). -## URI Parameters -| URI Parameter | Type | Description | -|---|---|---| -| template_id | string | The ID of the original template | -| version_id | string | The ID of the template version | +```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 -### PATCH /templates/{template_id}/versions/{version_id} +Subuser monitor settings allow you to receive a sample of an outgoing message by a specific customer at a specific frequency of emails. + +### POST /subusers/{subuser_name}/monitor ```python data = { - "active": 1, - "html_content": "<%body%>", - "name": "updated_example_name", - "plain_content": "<%body%>", - "subject": "<%subject%>" + "email": "example@example.com", + "frequency": 50000 } -template_id = "test_url_param" -version_id = "test_url_param" -response = sg.client.templates._(template_id).versions._(version_id).patch(request_body=data) +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 ``` -## Retrieve a specific transactional template version. +## Retrieve monitor settings for a subuser -**This endpoint allows you to retrieve a specific version of a template.** +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. +### GET /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). -## URI Parameters -| URI Parameter | Type | Description | -|---|---|---| -| template_id | string | The ID of the original template | -| version_id | string | The ID of the template version | +```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 /templates/{template_id}/versions/{version_id} +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 -template_id = "test_url_param" -version_id = "test_url_param" -response = sg.client.templates._(template_id).versions._(version_id).get() +subuser_name = "test_url_param" +response = sg.client.subusers._(subuser_name).monitor.delete() print response.status_code print response.body print response.headers ``` -## Delete a transactional template version. +## Retrieve the monthly email statistics for a single subuser -**This endpoint allows you to delete one of your transactional template versions.** +**This endpoint allows you to retrieve the monthly email statistics for a specific 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. +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 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`. -## URI Parameters -| URI Parameter | Type | Description | -|---|---|---| -| template_id | string | The ID of the original template | -| version_id | string | The ID of the template version | +For more information, see our [User Guide](https://sendgrid.com/docs/User_Guide/Statistics/subuser.html). -### DELETE /templates/{template_id}/versions/{version_id} +### GET /subusers/{subuser_name}/stats/monthly ```python -template_id = "test_url_param" -version_id = "test_url_param" -response = sg.client.templates._(template_id).versions._(version_id).delete() +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 ``` -## Activate a transactional template version. - -**This endpoint allows you to activate a version of one of your templates.** + +# SUPPRESSION -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. +## Retrieve all blocks +**This endpoint allows you to retrieve a list of all email addresses that are currently on your blocks list.** -For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.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. -## URI Parameters -| URI Parameter | Type | Description | -|---|---|---| -| template_id | string | The ID of the original template | -| version_id | string | The ID of the template version | +For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html). -### POST /templates/{template_id}/versions/{version_id}/activate +### GET /suppression/blocks ```python -template_id = "test_url_param" -version_id = "test_url_param" -response = sg.client.templates._(template_id).versions._(version_id).activate.post() +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 ``` - -# TRACKING SETTINGS +## Delete blocks -## Retrieve Tracking Settings +**This endpoint allows you to delete all email addresses on your blocks list.** -**This endpoint allows you to retrieve a list of all tracking settings that you can enable on your account.** +There are two options for deleting blocked emails: -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. +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. -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 +For more information, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Suppressions/blocks.html). + +### DELETE /suppression/blocks ```python -params = {'limit': 1, 'offset': 1} -response = sg.client.tracking_settings.get(query_params=params) +data = { + "delete_all": False, + "emails": [ + "example1@example.com", + "example2@example.com" + ] +} +response = sg.client.suppression.blocks.delete(request_body=data) print response.status_code print response.body print response.headers ``` -## Update Click Tracking Settings +## Retrieve a specific block -**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 a specific email address from your blocks 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. +[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/click +### GET /suppression/blocks/{email} ```python -data = { - "enabled": True -} -response = sg.client.tracking_settings.click.patch(request_body=data) +email = "test_url_param" +response = sg.client.suppression.blocks._(email).get() print response.status_code print response.body print response.headers ``` -## Retrieve Click Track Settings +## Delete a specific block -**This endpoint allows you to retrieve your current click tracking setting.** +**This endpoint allows you to delete a specific email address from your blocks 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. +[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). -### GET /tracking_settings/click +### DELETE /suppression/blocks/{email} ```python -response = sg.client.tracking_settings.click.get() +email = "test_url_param" +response = sg.client.suppression.blocks._(email).delete() print response.status_code print response.body print response.headers ``` -## Update Google Analytics Settings - -**This endpoint allows you to update your current setting for Google Analytics.** +## Retrieve all bounces -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). +**This endpoint allows you to retrieve all of your bounces.** -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). +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/google_analytics +### GET /suppression/bounces ```python -data = { - "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) +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 ``` -## Retrieve Google Analytics Settings +## Delete bounces -**This endpoint allows you to retrieve your current setting for Google Analytics.** +**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.** -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). +Bounces are messages that are returned to the server that sent it. -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 see: -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. +* [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 about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html). +Note: the `delete_all` and `emails` parameters should be used independently of each other as they have different purposes. -### GET /tracking_settings/google_analytics +### DELETE /suppression/bounces ```python -response = sg.client.tracking_settings.google_analytics.get() +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 ``` -## Update Open Tracking Settings +## Retrieve a Bounce -**This endpoint allows you to update 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) -### PATCH /tracking_settings/open +### GET /suppression/bounces/{email} ```python -data = { - "enabled": True -} -response = sg.client.tracking_settings.open.patch(request_body=data) +email = "test_url_param" +response = sg.client.suppression.bounces._(email).get() print response.status_code print response.body print response.headers ``` -## Get Open Tracking Settings +## Delete a bounce -**This endpoint allows you to retrieve your current settings for open tracking.** +**This endpoint allows you to remove an email address from your bounce list.** -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. 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) -### GET /tracking_settings/open +### DELETE /suppression/bounces/{email} ```python -response = sg.client.tracking_settings.open.get() +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 ``` -## Update Subscription Tracking Settings +## Retrieve all invalid emails -**This endpoint allows you to update 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). -### PATCH /tracking_settings/subscription +### GET /suppression/invalid_emails ```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) +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 ``` -## Retrieve Subscription Tracking Settings +## Delete invalid emails -**This endpoint allows you to retrieve your current settings for subscription tracking.** +**This endpoint allows you to remove email addresses from your invalid email address list.** -Subscription tracking adds links to the bottom of your emails that allows your recipients to subscribe to, or unsubscribe from, your emails. +There are two options for deleting invalid email addresses: -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. +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. -For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.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 /tracking_settings/subscription +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). + +### DELETE /suppression/invalid_emails ```python -response = sg.client.tracking_settings.subscription.get() +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 ``` - -# USER - -## Get a user's account information. - -**This endpoint allows you to retrieve your user account details.** +## Retrieve a specific invalid email -Your user's account information includes the user's account type and reputation. +**This endpoint allows you to retrieve a specific invalid email addresses.** -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 +### GET /suppression/invalid_emails/{email} ```python -response = sg.client.user.account.get() +email = "test_url_param" +response = sg.client.suppression.invalid_emails._(email).get() print response.status_code print response.body print response.headers ``` -## Retrieve your credit balance +## Delete a specific invalid email -**This endpoint allows you to retrieve the current credit balance for your account.** +**This endpoint allows you to remove a specific email address from the invalid email address list.** -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). +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). + +### DELETE /suppression/invalid_emails/{email} ```python -response = sg.client.user.credits.get() +email = "test_url_param" +response = sg.client.suppression.invalid_emails._(email).delete() print response.status_code print response.body print response.headers ``` -## Update your account email address - -**This endpoint allows you to update the email address currently on file for your account.** +## Retrieve 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 retrieve 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 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/email +### GET /suppression/spam_report/{email} ```python -data = { - "email": "example@example.com" -} -response = sg.client.user.email.put(request_body=data) +email = "test_url_param" +response = sg.client.suppression.spam_report._(email).get() print response.status_code print response.body print response.headers ``` -## Retrieve your account email address - -**This endpoint allows you to retrieve the email address currently on file for your account.** +## 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 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() +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 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) +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 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) +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() +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) +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() +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) +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() +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) +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() +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) +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() +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) +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 retrieve your current event webhook settings.** +**This endpoint allows you to activate a version of one of your templates.** -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. -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. +For more information about transactional templates, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). -### GET /user/webhooks/event/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 | + +### POST /templates/{template_id}/versions/{version_id}/activate ```python -response = sg.client.user.webhooks.event.settings.get() +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) +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) +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 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. -### 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() +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 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). +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) +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 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). +## 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 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). +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() +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 retrieve the statistics for your Parse Webhook usage.** +**This endpoint allows you to update your current settings for open tracking.** -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. +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. -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). +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/stats +For more information about tracking, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/tracking.html). + +### 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) +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) +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) +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() +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 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 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 +* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html) + +### GET /user/account ```python -response = sg.client.whitelabel.domains.subuser.get() +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 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() +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 email address currently on file for your account.** -**This endpoint allows you to update the settings for a domain whitelabel.** +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. -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) -### PATCH /whitelabel/domains/{domain_id} +### 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) +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 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() +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 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() +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 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 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) +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 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) +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() +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() +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) +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 created 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) +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() +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() +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() +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 update the username for your account.** -**This endpoint allows you to create a new link whitelabel.** +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. -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). +* [SendGrid Account Settings](https://sendgrid.com/docs/User_Guide/Settings/account.html) -### POST /whitelabel/links +### 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) +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 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). +* [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) +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. +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, 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) +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 link 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. +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, 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) +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 link 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. +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, 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) +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 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) +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 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() +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 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() +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 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() +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 link 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 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.** + +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 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) +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 From f49af64b8bdb6e04b66bb0dbc7fa66bad80a35ee Mon Sep 17 00:00:00 2001 From: Chandler Weiner Date: Wed, 17 Oct 2018 16:29:12 -0400 Subject: [PATCH 64/82] Correct spelling and anchor links --- USAGE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/USAGE.md b/USAGE.md index b14656ba8..bdd4dccfc 100644 --- a/USAGE.md +++ b/USAGE.md @@ -30,7 +30,7 @@ sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) * [PARTNER SETTINGS](#partner-settings) * [SCOPES](#scopes) * [SENDERS](#senders) -* [SENDER Authorization](#sender-authorization) +* [SENDER AUTHENTICATION](#sender-authentication) * [STATS](#stats) * [SUBUSERS](#subusers) * [SUPPRESSION](#suppression) From ad7a96af0e11b06b4f83c9b3f627de6d6ac9ed44 Mon Sep 17 00:00:00 2001 From: Chandler Weiner Date: Wed, 17 Oct 2018 16:33:52 -0400 Subject: [PATCH 65/82] Change path and file to "senderauthentication" --- .../senderauthentication.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{whitelabel/whitelabel.py => senderauthentication/senderauthentication.py} (100%) diff --git a/examples/whitelabel/whitelabel.py b/examples/senderauthentication/senderauthentication.py similarity index 100% rename from examples/whitelabel/whitelabel.py rename to examples/senderauthentication/senderauthentication.py From 54f1d305ef85ab92b1d9505be83bc3a3fac117b1 Mon Sep 17 00:00:00 2001 From: Bhavin Jawade Date: Fri, 19 Oct 2018 00:27:22 +0530 Subject: [PATCH 66/82] corrected links in CodeofConduct. Hacktoberfest. Issue #671 --- CODE_OF_CONDUCT.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 39ed18bf7..6532e6d45 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -36,6 +36,6 @@ SendGrid thanks the following, on which it draws for content and inspiration: - [Python Community Code of Conduct](https://www.python.org/psf/codeofconduct/) - [Open Source Initiative General Code of Conduct](https://opensource.org/codeofconduct) - [Apache Code of Conduct](https://www.apache.org/foundation/policies/conduct.html) + [Python Community Code of Conduct](https://www.python.org/psf/codeofconduct/)
+ [Open Source Initiative General Code of Conduct](https://opensource.org/codeofconduct)
+ [Apache Code of Conduct](https://www.apache.org/foundation/policies/conduct.html)
From 3363e01f99cd60d23029d25c7102abdafa5aeacc Mon Sep 17 00:00:00 2001 From: Peter Yasi Date: Thu, 18 Oct 2018 23:23:12 -0400 Subject: [PATCH 67/82] Add unit tests for spam check --- test/test_spam_check.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/test_spam_check.py diff --git a/test/test_spam_check.py b/test/test_spam_check.py new file mode 100644 index 000000000..240b5b114 --- /dev/null +++ b/test/test_spam_check.py @@ -0,0 +1,38 @@ +from sendgrid.helpers.mail.spam_check import SpamCheck + +try: + import unittest2 as unittest +except ImportError: + import unittest + + +class UnitTests(unittest.TestCase): + + def test_spam_all_values(self): + expected = {'enable': True, 'threshold': 5, 'post_to_url': 'https://www.test.com'} + spam_check = SpamCheck(enable=True, threshold=5, post_to_url='https://www.test.com') + self.assertEqual(spam_check.get(), expected) + + def test_spam_no_url(self): + expected = {'enable': True, 'threshold': 10} + spam_check = SpamCheck(enable=True, threshold=10) + self.assertEqual(spam_check.get(), expected) + + def test_spam_no_threshold(self): + expected = {'enable': True} + spam_check = SpamCheck(enable=True) + self.assertEqual(spam_check.get(), expected) + + def test_has_values_but_not_enabled(self): + expected = {'enable': False, 'threshold': 1, 'post_to_url': 'https://www.test.com'} + spam_check = SpamCheck(enable=False, threshold=1, post_to_url='https://www.test.com') + self.assertEqual(spam_check.get(), expected) + + def test_spam_change_properties(self): + expected = {'enable': False, 'threshold': 10, 'post_to_url': 'https://www.testing.com'} + spam_check = SpamCheck(enable=True, threshold=5, post_to_url='https://www.test.com') + spam_check.enable = False + spam_check.threshold = 10 + spam_check.post_to_url = 'https://www.testing.com' + self.assertEqual(spam_check.get(), expected) + From 0f7e83616db51172e3836bdcf4aec7392e00bfaf Mon Sep 17 00:00:00 2001 From: Peter Yasi Date: Thu, 18 Oct 2018 23:28:23 -0400 Subject: [PATCH 68/82] Test description --- test/test_spam_check.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_spam_check.py b/test/test_spam_check.py index 240b5b114..326c5d070 100644 --- a/test/test_spam_check.py +++ b/test/test_spam_check.py @@ -29,6 +29,8 @@ def test_has_values_but_not_enabled(self): self.assertEqual(spam_check.get(), expected) def test_spam_change_properties(self): + """Tests changing the properties of the spam check class""" + expected = {'enable': False, 'threshold': 10, 'post_to_url': 'https://www.testing.com'} spam_check = SpamCheck(enable=True, threshold=5, post_to_url='https://www.test.com') spam_check.enable = False From c9325eac217fd0a803943278c64d33f5e8c67966 Mon Sep 17 00:00:00 2001 From: vkmrishad Date: Sat, 20 Oct 2018 15:42:44 +0530 Subject: [PATCH 69/82] PEP8 Fixes and String Formatting Enhancement --- examples/helpers/stats/stats_example.py | 2 ++ register.py | 2 +- sendgrid/helpers/inbound/config.py | 7 ++++--- sendgrid/helpers/inbound/send.py | 4 +++- sendgrid/helpers/mail/content.py | 1 + sendgrid/helpers/mail/exceptions.py | 2 +- sendgrid/helpers/mail/validators.py | 4 +--- setup.py | 1 + test/test_app.py | 2 +- test/test_config.py | 2 +- test/test_mail.py | 6 +++--- test/test_project.py | 2 ++ test/test_send.py | 15 ++++++++++----- test/test_sendgrid.py | 7 +++++-- test/test_unassigned.py | 4 +++- 15 files changed, 39 insertions(+), 22 deletions(-) diff --git a/examples/helpers/stats/stats_example.py b/examples/helpers/stats/stats_example.py index d48664c3f..f3196881a 100644 --- a/examples/helpers/stats/stats_example.py +++ b/examples/helpers/stats/stats_example.py @@ -45,6 +45,7 @@ def build_subuser_stats(): # 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' @@ -92,6 +93,7 @@ def get_subuser_stats_sums(): print(response.headers) pprint_json(response.body) + get_global_stats() get_category_stats() get_category_stats_sums() diff --git a/register.py b/register.py index 0a7ffe8d8..00ddca15c 100644 --- a/register.py +++ b/register.py @@ -17,4 +17,4 @@ ''' final_text = readme_rst.replace(replace, replacement) with open('./README.txt', 'w', encoding='utf-8') as f: - f.write(final_text) + f.write(final_text) diff --git a/sendgrid/helpers/inbound/config.py b/sendgrid/helpers/inbound/config.py index d0c6517bc..32bec0793 100644 --- a/sendgrid/helpers/inbound/config.py +++ b/sendgrid/helpers/inbound/config.py @@ -15,7 +15,7 @@ def __init__(self, **opts): self.path = opts.get( 'path', os.path.abspath(os.path.dirname(__file__)) ) - with open(self.path + '/config.yml') as stream: + with open('{0}/config.yml'.format(self.path)) as stream: config = yaml.load(stream) self._debug_mode = config['debug_mode'] self._endpoint = config['endpoint'] @@ -28,8 +28,9 @@ 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'): - with open(base_path + '/.env') as f: + 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('=') diff --git a/sendgrid/helpers/inbound/send.py b/sendgrid/helpers/inbound/send.py index 6de575aab..e3526eb7c 100644 --- a/sendgrid/helpers/inbound/send.py +++ b/sendgrid/helpers/inbound/send.py @@ -37,6 +37,7 @@ def url(self): """URL to send to.""" return self._url + def main(): config = Config() parser = argparse.ArgumentParser(description='Test data and optional host.') @@ -54,5 +55,6 @@ def main(): print(response.headers) print(response.body) + if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/sendgrid/helpers/mail/content.py b/sendgrid/helpers/mail/content.py index cff8ac498..da4ed8027 100644 --- a/sendgrid/helpers/mail/content.py +++ b/sendgrid/helpers/mail/content.py @@ -1,5 +1,6 @@ from .validators import ValidateAPIKey + class Content(object): """Content to be included in your email. diff --git a/sendgrid/helpers/mail/exceptions.py b/sendgrid/helpers/mail/exceptions.py index ab4dd9c0c..5279c365a 100644 --- a/sendgrid/helpers/mail/exceptions.py +++ b/sendgrid/helpers/mail/exceptions.py @@ -2,6 +2,7 @@ # Various types of extensible SendGrid related exceptions ################################################################ + class SendGridException(Exception): """Wrapper/default SendGrid-related exception""" pass @@ -19,4 +20,3 @@ def __init__(self, message="SendGrid API Key detected"): self.expression = expression self.message = message - diff --git a/sendgrid/helpers/mail/validators.py b/sendgrid/helpers/mail/validators.py index b4a69f697..96e81795e 100644 --- a/sendgrid/helpers/mail/validators.py +++ b/sendgrid/helpers/mail/validators.py @@ -3,6 +3,7 @@ # Various types of Validators ################################################################ + class ValidateAPIKey(object): """Validates content to ensure SendGrid API key is not present""" @@ -27,7 +28,6 @@ def __init__(self, regex_strings=None, use_default=True): default_regex_string = 'SG\.[0-9a-zA-Z]+\.[0-9a-zA-Z]+' self.regexes.add(re.compile(default_regex_string)) - def validate_message_dict(self, request_body): """With the JSON dict that will be sent to SendGrid's API, check the content for SendGrid API keys - throw exception if found @@ -54,7 +54,6 @@ def validate_message_dict(self, request_body): message_text = content.get("value", "") self.validate_message_text(message_text) - def validate_message_text(self, message_string): """With a message string, check to see if it contains a SendGrid API Key If a key is found, throw an exception @@ -68,4 +67,3 @@ def validate_message_text(self, message_string): for regex in self.regexes: if regex.match(message_string) is not None: raise APIKeyIncludedException() - diff --git a/setup.py b/setup.py index 014691b61..11aa3a07e 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,7 @@ def getRequires(): deps.append('unittest2py3k') return deps + setup( name='sendgrid', version=str(__version__), diff --git a/test/test_app.py b/test/test_app.py index 1a8e4a698..13b0a9522 100644 --- a/test/test_app.py +++ b/test/test_app.py @@ -23,4 +23,4 @@ def test_up_and_running(self): def test_used_port_true(self): if self.config.debug_mode: port = int(os.environ.get("PORT", self.config.port)) - self.assertEqual(port, self.config.port) \ No newline at end of file + self.assertEqual(port, self.config.port) diff --git a/test/test_config.py b/test/test_config.py index 301bacc92..d20af40e2 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -43,7 +43,7 @@ def test_initialization(self): def test_init_environment(self): config_file = sendgrid.helpers.inbound.config.__file__ - env_file_path = os.path.abspath(os.path.dirname(config_file)) + '/.env' + env_file_path = '{0}/.env'.format(os.path.abspath(os.path.dirname(config_file))) with open(env_file_path, 'w') as f: f.write('RANDOM_VARIABLE=RANDOM_VALUE') Config() diff --git a/test/test_mail.py b/test/test_mail.py index 08d0feb8e..ffe5586b4 100644 --- a/test/test_mail.py +++ b/test/test_mail.py @@ -52,7 +52,7 @@ def test_sendgridAPIKey(self): personalization.add_to(Email("test@example.com")) mail.add_personalization(personalization) - #Try to include SendGrid API key + # Try to include SendGrid API key try: mail.add_content(Content("text/plain", "some SG.2123b1B.1212lBaC here")) mail.add_content( @@ -72,11 +72,11 @@ def test_sendgridAPIKey(self): '"subject": "Hello World from the SendGrid Python Library"}' ) - #Exception should be thrown + # Exception should be thrown except Exception as e: pass - #Exception not thrown + # Exception not thrown else: self.fail("Should have failed as SendGrid API key included") diff --git a/test/test_project.py b/test/test_project.py index 4fbc8147c..5e269ae43 100644 --- a/test/test_project.py +++ b/test/test_project.py @@ -5,6 +5,7 @@ except ImportError: import unittest + class ProjectTests(unittest.TestCase): # ./docker @@ -71,5 +72,6 @@ def test_usage(self): def test_use_cases(self): self.assertTrue(os.path.isfile('./use_cases/README.md')) + if __name__ == '__main__': unittest.main() diff --git a/test/test_send.py b/test/test_send.py index 16d496b85..7079c8b0e 100644 --- a/test/test_send.py +++ b/test/test_send.py @@ -30,13 +30,18 @@ def test_send(self): x = send.Send(fake_url) x.test_payload(fake_url) - send.Client.assert_called_once_with(host=fake_url, request_headers={'User-Agent': 'SendGrid-Test', - 'Content-Type': 'multipart/form-data; boundary=xYzZY'}) + send.Client.assert_called_once_with(host=fake_url, request_headers={ + 'User-Agent': 'SendGrid-Test', + 'Content-Type': 'multipart/form-data; boundary=xYzZY' + }) def test_main_call(self): fake_url = 'https://fake_url' - with mock.patch('argparse.ArgumentParser.parse_args', return_value=argparse.Namespace(host=fake_url, data='test_file.txt')): + with mock.patch('argparse.ArgumentParser.parse_args', return_value=argparse.Namespace( + host=fake_url, data='test_file.txt')): send.main() - send.Client.assert_called_once_with(host=fake_url, request_headers={'User-Agent': 'SendGrid-Test', - 'Content-Type': 'multipart/form-data; boundary=xYzZY'}) + send.Client.assert_called_once_with(host=fake_url, request_headers={ + 'User-Agent': 'SendGrid-Test', + 'Content-Type': 'multipart/form-data; boundary=xYzZY' + }) diff --git a/test/test_sendgrid.py b/test/test_sendgrid.py index c545cbb2d..4b386e713 100644 --- a/test/test_sendgrid.py +++ b/test/test_sendgrid.py @@ -144,8 +144,11 @@ def test_hello_world(self): content = Content( "text/plain", "and easy to do anywhere, even with Python") mail = Mail(from_email, subject, to_email, content) - self.assertTrue(mail.get() == {'content': [{'type': 'text/plain', 'value': 'and easy to do anywhere, even with Python'}], 'personalizations': [ - {'to': [{'email': 'test@example.com'}]}], 'from': {'email': 'test@example.com'}, 'subject': 'Sending with SendGrid is Fun'}) + self.assertTrue(mail.get() == { + 'content': [{'type': 'text/plain', 'value': 'and easy to do anywhere, even with Python'}], + 'personalizations': [{'to': [{'email': 'test@example.com'}]}], 'from': {'email': 'test@example.com'}, + 'subject': 'Sending with SendGrid is Fun' + }) def test_access_settings_activity_get(self): params = {'limit': 1} diff --git a/test/test_unassigned.py b/test/test_unassigned.py index d13451277..6054447d8 100644 --- a/test/test_unassigned.py +++ b/test/test_unassigned.py @@ -55,6 +55,7 @@ } ] ''' + def get_all_ip(): ret_val = json.loads(ret_json) return ret_val @@ -67,7 +68,6 @@ def make_data(): return data - def test_unassigned_ip_json(): data = make_data() @@ -79,6 +79,7 @@ def test_unassigned_ip_json(): for item in calculated: assert item["ip"] in data + def test_unassigned_ip_obj(): data = make_data() @@ -89,6 +90,7 @@ def test_unassigned_ip_obj(): for item in calculated: assert item["ip"] in data + def test_unassigned_baddata(): as_json = False calculated = unassigned(dict(), as_json=as_json) From 568e5b08a24dc32ca598c513da56b582e6f26a87 Mon Sep 17 00:00:00 2001 From: Mike Dorman Date: Sat, 20 Oct 2018 21:27:01 +0530 Subject: [PATCH 70/82] Update examples/helpers/README.md Co-Authored-By: tulikavijay --- examples/helpers/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/helpers/README.md b/examples/helpers/README.md index 917aebb16..5d5e31a03 100644 --- a/examples/helpers/README.md +++ b/examples/helpers/README.md @@ -1,5 +1,5 @@ ## 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, +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! From c0b5081db05fbea72d4f3f4f0e0233cd402c43a0 Mon Sep 17 00:00:00 2001 From: Mike Dorman Date: Sat, 20 Oct 2018 21:27:21 +0530 Subject: [PATCH 71/82] Update examples/helpers/README.md Co-Authored-By: tulikavijay --- examples/helpers/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/helpers/README.md b/examples/helpers/README.md index 5d5e31a03..70cec463d 100644 --- a/examples/helpers/README.md +++ b/examples/helpers/README.md @@ -1,6 +1,6 @@ ## 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 +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. From b0778e8631e3e2f6e4f7dc86184331eb7668ab1c Mon Sep 17 00:00:00 2001 From: Mike Dorman Date: Sat, 20 Oct 2018 21:27:28 +0530 Subject: [PATCH 72/82] Update examples/helpers/README.md Co-Authored-By: tulikavijay --- examples/helpers/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/helpers/README.md b/examples/helpers/README.md index 70cec463d..0a9c0c700 100644 --- a/examples/helpers/README.md +++ b/examples/helpers/README.md @@ -3,7 +3,7 @@ You can use helper classes to customize the process of sending emails using Send 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. +> 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) From d923a4b514f8fbd180a2c4f943f4068bbfea0a9f Mon Sep 17 00:00:00 2001 From: Mike Dorman Date: Sat, 20 Oct 2018 21:27:33 +0530 Subject: [PATCH 73/82] Update examples/helpers/README.md Co-Authored-By: tulikavijay --- examples/helpers/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/helpers/README.md b/examples/helpers/README.md index 0a9c0c700..c7f44ac4d 100644 --- a/examples/helpers/README.md +++ b/examples/helpers/README.md @@ -13,7 +13,7 @@ defines minimum requirement to send an email. subject = "Hello World from the SendGrid Python Library" to_email = Email("test@example.com") ``` -you can use `Email` class to define a mail id. +You can use `Email` class to define a mail id. ``` content = Content("text/plain", "some text here") From 759abbb165260ec670c32d7e5662da38d05bda77 Mon Sep 17 00:00:00 2001 From: Mike Dorman Date: Sat, 20 Oct 2018 21:27:40 +0530 Subject: [PATCH 74/82] Update examples/helpers/README.md Co-Authored-By: tulikavijay --- examples/helpers/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/helpers/README.md b/examples/helpers/README.md index c7f44ac4d..5f57ca66e 100644 --- a/examples/helpers/README.md +++ b/examples/helpers/README.md @@ -18,7 +18,7 @@ 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. +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, subject, to_email, content) From 073fd38d71b89fedeb64547865a96778915b5ab0 Mon Sep 17 00:00:00 2001 From: Mike Dorman Date: Sat, 20 Oct 2018 21:27:46 +0530 Subject: [PATCH 75/82] Update examples/helpers/README.md Co-Authored-By: tulikavijay --- examples/helpers/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/helpers/README.md b/examples/helpers/README.md index 5f57ca66e..6774ea7f7 100644 --- a/examples/helpers/README.md +++ b/examples/helpers/README.md @@ -23,7 +23,7 @@ The `Content` class takes mainly two parameters: MIME type and the actual conten ``` mail = Mail(from_email, subject, to_email, 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. +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](https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/mail.py) ### Creating Personalizations From 682d7dfa07dda2076f247a4e459bb816ddc74f44 Mon Sep 17 00:00:00 2001 From: Mike Dorman Date: Sat, 20 Oct 2018 21:27:54 +0530 Subject: [PATCH 76/82] Update examples/helpers/README.md Co-Authored-By: tulikavijay --- examples/helpers/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/helpers/README.md b/examples/helpers/README.md index 6774ea7f7..5fb1445be 100644 --- a/examples/helpers/README.md +++ b/examples/helpers/README.md @@ -24,7 +24,7 @@ The `Content` class takes mainly two parameters: MIME type and the actual conten mail = Mail(from_email, subject, to_email, 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](https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/mail.py) +For more information on parameters and usage, see [here](https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/mail.py) ### Creating Personalizations From 6b27879d61c9ce3bf5b1932eb11affde582945ba Mon Sep 17 00:00:00 2001 From: Mike Dorman Date: Sat, 20 Oct 2018 21:28:03 +0530 Subject: [PATCH 77/82] Update examples/helpers/README.md Co-Authored-By: tulikavijay --- examples/helpers/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/helpers/README.md b/examples/helpers/README.md index 5fb1445be..04e32f0b7 100644 --- a/examples/helpers/README.md +++ b/examples/helpers/README.md @@ -28,7 +28,7 @@ For more information on parameters and usage, see [here](https://github.com/send ### Creating Personalizations -To create personalizations, you need a dictionary to store all your email components. see example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L47) +To create personalizations, you need a dictionary to store all your email components. See example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L47) After creating a dictionary, you can go ahead and create a `Personalization` object. ``` mock_personalization = Personalization() From f4ac98c582faa9f5ff29c7dffe7da4487a6eeccc Mon Sep 17 00:00:00 2001 From: Tulika Date: Sat, 20 Oct 2018 22:05:01 +0530 Subject: [PATCH 78/82] Add remaining sections --- examples/helpers/README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/examples/helpers/README.md b/examples/helpers/README.md index 04e32f0b7..95981b497 100644 --- a/examples/helpers/README.md +++ b/examples/helpers/README.md @@ -35,3 +35,35 @@ After creating a dictionary, you can go ahead and create a `Personalization` obj for to_addr in personalization['to_list']: mock_personalization.add_to(to_addr) ``` + +### 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](https://github.com/sendgrid/sendgrid-python/blob/master/use_cases/attachment.md) + +### Managing Settings + +To configure settings in mail, you can use the `MailSettings` class. The class takes some [parameters](https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/mail_settings.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](https://github.com/sendgrid/sendgrid-python/blob/master/examples/helpers/mail_example.py#L118) and parameters and usage [here](https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/tracking_settings.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.client.mail.send.post(request_body=data) +``` +Make sure you have [environment variable](https://github.com/sendgrid/sendgrid-python/blob/master/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). From 3f3eba45eff1447f51e49d82e6b15b92bbf6b696 Mon Sep 17 00:00:00 2001 From: Rishabh Chaudhary Date: Tue, 30 Oct 2018 00:28:50 +0530 Subject: [PATCH 79/82] Updation in prerequisites --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4132b62b5..114076241 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ We appreciate your continued support, thank you! ## Prerequisites - Python version 2.6, 2.7, 3.4, 3.5 or 3.6 -- The SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-python) +- The SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-python) to send up to 40,000 emails for the first 30 days, then send 100 emails/day free forever or check out [our pricing](https://sendgrid.com/pricing?source=sendgrid-python). ## Setup Environment Variables ### Mac From 4762039541aca8bef1a8f0cca652211a0fcec350 Mon Sep 17 00:00:00 2001 From: Mohammed Rishad Date: Tue, 30 Oct 2018 10:25:42 +0530 Subject: [PATCH 80/82] Updated file with Master branch --- test/test_sendgrid.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/test_sendgrid.py b/test/test_sendgrid.py index 4b386e713..37fe9f9f8 100644 --- a/test/test_sendgrid.py +++ b/test/test_sendgrid.py @@ -1,6 +1,7 @@ import sendgrid from sendgrid.helpers.mail import * from sendgrid.version import __version__ + try: import unittest2 as unittest except ImportError: @@ -25,7 +26,7 @@ def setUpClass(cls): cls.sg = sendgrid.SendGridAPIClient(host=host) cls.devnull = open(os.devnull, 'w') prism_cmd = None - + # try: # # check for prism in the PATH # if subprocess.call('prism version'.split(), stdout=cls.devnull) == 0: @@ -134,7 +135,7 @@ def test_reset_request_headers(self): self.assertNotIn('blah', self.sg.client.request_headers) self.assertNotIn('blah2x', self.sg.client.request_headers) - for k,v in self.sg._default_headers.items(): + for k, v in self.sg._default_headers.items(): self.assertEqual(v, self.sg.client.request_headers[k]) def test_hello_world(self): @@ -144,11 +145,11 @@ def test_hello_world(self): content = Content( "text/plain", "and easy to do anywhere, even with Python") mail = Mail(from_email, subject, to_email, content) - self.assertTrue(mail.get() == { - 'content': [{'type': 'text/plain', 'value': 'and easy to do anywhere, even with Python'}], - 'personalizations': [{'to': [{'email': 'test@example.com'}]}], 'from': {'email': 'test@example.com'}, - 'subject': 'Sending with SendGrid is Fun' - }) + self.assertTrue( + mail.get() == {'content': [{'type': 'text/plain', 'value': 'and easy to do anywhere, even with Python'}], + 'personalizations': [ + {'to': [{'email': 'test@example.com'}]}], 'from': {'email': 'test@example.com'}, + 'subject': 'Sending with SendGrid is Fun'}) def test_access_settings_activity_get(self): params = {'limit': 1} From 1536f51d5d37ee4419bc3317e857ad9213692382 Mon Sep 17 00:00:00 2001 From: Rahul Purohit Date: Wed, 31 Oct 2018 00:41:04 +0530 Subject: [PATCH 81/82] updated README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4132b62b5..77d6185dd 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,10 @@ Please browse the rest of this README for further detail. We appreciate your continued support, thank you! +# Announcements + + **NEW:** If you're a software engineer who is passionate about #DeveloperExperience and/or #OpenSource, [this is an incredible opportunity to join our #DX team](https://sendgrid.com/careers/role/1421152/?gh_jid=1421152) as a Developer Experience Engineer and work with [@thinkingserious](https://github.com/thinkingserious) and [@aroach](https://github.com/aroach)! Tell your friends :) + # Table of Contents * [Installation](#installation) From 76ac470380a8357afab14970e12ff26a97264a95 Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Mon, 12 Nov 2018 11:57:51 -0800 Subject: [PATCH 82/82] Rename transational_templates.md to transactional_templates.md --- .../{transational_templates.md => transactional_templates.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename use_cases/{transational_templates.md => transactional_templates.md} (99%) diff --git a/use_cases/transational_templates.md b/use_cases/transactional_templates.md similarity index 99% rename from use_cases/transational_templates.md rename to use_cases/transactional_templates.md index 491d528bd..48627ee58 100644 --- a/use_cases/transational_templates.md +++ b/use_cases/transactional_templates.md @@ -178,4 +178,4 @@ except urllib.HTTPError as e: print(response.status_code) print(response.body) print(response.headers) -``` \ No newline at end of file +```