Skip to content

Instantly share code, notes, and snippets.

@jamescoxhead
Created November 15, 2017 12:04
Show Gist options
  • Save jamescoxhead/aad2c31219596e42390b28e5175d8d96 to your computer and use it in GitHub Desktop.
Save jamescoxhead/aad2c31219596e42390b28e5175d8d96 to your computer and use it in GitHub Desktop.
Purges the Cloudflare cache. Assumes variables are stored as environment variables
# Get parameters
$cloudflareApiKey = $Env:CloudflareApiKey
$cloudflareEmail = $Env:CloudflareEmail
$cloudflareZoneId = $Env:CloudflareZoneId
# Build the request
$endpoint = "https://api.cloudflare.com/client/v4/zones/$cloudflareZoneId/purge_cache"
$headers = @{"X-Auth-Key" = $cloudflareApiKey; "X-Auth-Email" = $cloudflareEmail; "Content-Type" = "application/json"}
$body = "{'purge_everything': true}"
# Send the request
$request = Invoke-RestMethod -Uri $endpoint -Method Delete -Headers $headers -Body $body
if ($request.success) {
Write-Host "Cloudflare purged" -ForegroundColor Green
} else {
Write-Host "Error purging Cloudflare cache" -ForegroundColor Red
Write-Host $request.errors
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment