Skip to content

Instantly share code, notes, and snippets.

@noeljackson
Created February 9, 2017 04:23
Show Gist options
  • Save noeljackson/d7dedfdb5514903c57f66e2ab4806819 to your computer and use it in GitHub Desktop.
Save noeljackson/d7dedfdb5514903c57f66e2ab4806819 to your computer and use it in GitHub Desktop.
Pure Cloudflare cache for a domain via the shell
#!/bin/bash
CFKEY=apikeygoeshere
[email protected]
CFDOMAIN=yourdomain.com
CFZONE=$(curl -X GET "https://api.cloudflare.com/client/v4/zones?name=$CFDOMAIN&status=active&page=1&per_page=20&order=status&direction=desc&match=all" \
-H "X-Auth-Email: $CFUSER" \
-H "X-Auth-Key: $CFKEY" \
-H "Content-Type: application/json" \
| grep -Eo '"result\"\:\[\{"id":"([^"]+)"' \
| awk '{gsub("\"","");print $1}' \
| awk '{gsub("result:\\[\\{id:","");print $1}')
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/$CFZONE/purge_cache" \
-H "X-Auth-Email: $CFUSER" \
-H "X-Auth-Key: $CFKEY" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment