Skip to content

Instantly share code, notes, and snippets.

@jmarhee
Created August 14, 2026 19:00
Show Gist options
  • Select an option

  • Save jmarhee/a49c02400d1d846f5d1ee1c8ac8aa0b7 to your computer and use it in GitHub Desktop.

Select an option

Save jmarhee/a49c02400d1d846f5d1ee1c8ac8aa0b7 to your computer and use it in GitHub Desktop.
Purge Cloudflare zone cache.
CLOUDFLARE_ZONE_ID=
CLOUDFLARE_API_TOKEN=
# API Token requires `Zone.Cache Purge` permissions.
-include .env
export
.PHONY: purge
purge:
@test -n "$(CLOUDFLARE_ZONE_ID)" || (echo "CLOUDFLARE_ZONE_ID unset"; exit 1)
@test -n "$(CLOUDFLARE_API_TOKEN)" || (echo "CLOUDFLARE_API_TOKEN unset"; exit 1)
@resp=$$(curl -fsS -X POST \
"https://api.cloudflare.com/client/v4/zones/$(CLOUDFLARE_ZONE_ID)/purge_cache" \
-H "Authorization: Bearer $(CLOUDFLARE_API_TOKEN)" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}'); \
echo "$$resp"; \
echo "$$resp" | grep -q '"success":[[:space:]]*true' || (echo "Cloudflare purge failed"; exit 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment