Skip to content

Instantly share code, notes, and snippets.

@kyanny

kyanny/.sh

Created Jul 24, 2015
Embed
What would you like to do?
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