Last active
March 28, 2025 13:02
-
-
Save patmigliaccio/fbdbb4c0192deddc229b16ef62347a74 to your computer and use it in GitHub Desktop.
Executes cURL to purge the cache on Cloudflare for a specified set or all files (requires config)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Author: Pat Migliaccio <[email protected]> | |
# License: MIT | |
EMAIL="<Acct_Email>" | |
ZONE="<Zone_ID>" | |
API_KEY="<API_Key>" | |
DATA="{ \"files\": [\"https://example.com/css/style.css\"] }" | |
# Purges all files with `-a` or `--all` flags | |
if [[ "$1" == "--all" || "$1" == "-a" ]]; then | |
echo "Purging everything..." | |
config[data]="{ \"purge_everything\": true }" | |
elif [ ! -z "$1" ]; then | |
echo "Command not found: $1" | |
exit 1 | |
fi | |
# Calls Cloudflare API to Purge Files | |
# Reference: https://api.cloudflare.com/#zone-purge-files-by-url | |
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE/purge_cache" \ | |
-H "X-Auth-Email: $EMAIL" \ | |
-H "X-Auth-Key: $API_KEY" \ | |
-H "Content-Type: application/json" \ | |
--data "$DATA" |
Thank you so much for the command!
I modified mine so it works under github actions and only use the Token ID instead of also the email though, here it is
curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.ZONE_ID }}/purge_cache" \
-H "Authorization: Bearer ${{ secrets.API_TOKEN }}" \
-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
👍