Purge Cloudflare Cache

CloudFlare is a great service, but their rather agressive caching can be confusing during development.

However there is a way to purge the cache thru their API.

To set this up you need:

  1. Your API-key: Go to Cloudflare > My Profil > API Tokens. Click View or create one.

  2. Zone ID, which you find on the domain’s dashboard, on the bottom right side.

Zone ID

  1. Add this cURL to your deployment script.

curl -X "POST" "https://api.cloudflare.com/client/v4/zones/<Zone ID>/purge_cache" \
     -H 'X-Auth-Email: <Your Email>' \
     -H 'X-Auth-Key: <PI Key>' \
     -H 'Content-Type: application/json' \
     -d $'{
  "purge_everything": true