Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created July 24, 2015 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyanny/cebfc3c6be184c422718 to your computer and use it in GitHub Desktop.
Save kyanny/cebfc3c6be184c422718 to your computer and use it in GitHub Desktop.
Delete email address from suppression list of SendGrid
export API_USER=your_sendgrid_username
export API_KEY=your_sendgrid_password
export EMAIL=foo@example.com
export RED='\033[0;31m'
export GREEN='\033[0;32m'
export NC='\033[0m' # No Color
curl -X GET "https://api.sendgrid.com/api/bounces.get.json?api_user=${API_USER}&api_key=${API_KEY}&email=${EMAIL}" > bounces.json
count=$(ruby -rjson -e "print JSON.parse(File.read(%Q,bounces.json,)).length")
if [ 0 -eq $count ]
then
echo -e "${GREEN}${EMAIL} is not in the list.${NC}"
else
curl -X POST https://api.sendgrid.com/api/bounces.delete.json -d api_user=$API_USER -d api_key=$API_KEY -d email=$EMAIL > results.json
count=$(grep -c 'success' results.json)
if [ 1 -eq $count ]
then
echo -e "${GREEN}${EMAIL} is deleted from the list.${NC}"
else
echo -e "${RED}Can't delete ${EMAIL} from the list.${NC}"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment