Created
November 15, 2017 12:04
-
-
Save jamescoxhead/aad2c31219596e42390b28e5175d8d96 to your computer and use it in GitHub Desktop.
Purges the Cloudflare cache. Assumes variables are stored as environment variables
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
# 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