Skip to content

Instantly share code, notes, and snippets.

@kpx-dev
Created November 20, 2014 20:11
Show Gist options
  • Save kpx-dev/0808a113134eed314a4e to your computer and use it in GitHub Desktop.
Save kpx-dev/0808a113134eed314a4e to your computer and use it in GitHub Desktop.
SendGrid bounces example
"""
This Python code snippet will show you how to get all SendGrid bounces
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 bounces.py and run it
$ python bounces.py
"""
import requests
import os
SG_URL = "https://sendgrid.com/api/bounces.get.json"
if __name__ == '__main__':
# get all bounces
url = "{}?api_user={}&api_key={}".format(
SG_URL, os.environ['SG_USERNAME'], os.environ['SG_PASSWORD'])
res = requests.get(url)
print res.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment