Created
November 21, 2014 04:46
-
-
Save kpx-dev/9d0af4b48d167a9b675c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This Python code snippet will show you how to get all SendGrid invalid | |
emails records. | |
install the amazing requests library | |
$ pip install requests==2.4.3 | |
export your SendGrid credential from command line | |
$ export SG_USERNAME=your_sg_username | |
$ export SG_PASSWORD=your_sg_password | |
save this file as python example.py and run it | |
$ python example.py | |
gist link: | |
""" | |
import requests | |
import os | |
SG_URL = "https://api.sendgrid.com/api" | |
def build_url(endpoint, params=None): | |
url = "{}/{}.json?api_user={}&api_key={}".format( | |
SG_URL, | |
endpoint, | |
os.environ['SG_USERNAME'], | |
os.environ['SG_PASSWORD']) | |
if params: | |
for k, v in params.iteritems(): | |
url += "&{}={}".format(k, v) | |
return url | |
if __name__ == '__main__': | |
print 'get all invalid emails...' | |
url = build_url("invalidemails.get") | |
res = requests.get(url) | |
print res.json() | |
print 'get all invalid emails count...' | |
url = build_url("invalidemails.count") | |
res = requests.get(url) | |
print res.json() | |
print 'delete an invalid email...' | |
url = build_url("invalidemails.delete") | |
data = {"email": "example@example.com"} | |
res = requests.post(url, data) | |
print res.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment