How to purge CloudFlare from post-receive hook?

57 views Asked by At

Can someone provide an example of how to purge CloudFlare from a Git post-receive hook?
Something like https://gist.github.com/jonlong/240eb9a7501f1ae4c09f but using the current API.
If there is a way using a Linux CloudFlare CLI client that would be fine too.

Surprisingly (given this was a common task) there's nothing obvious searching here or on Google.
Thanks in advance for suggestions.

1

There are 1 answers

0
VonC On

The current API should be POST zones/:identifier/purge_cache

curl -X POST "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/purge_cache" \
     -H "X-Auth-Email: [email protected]" \
     -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
     -H "Content-Type: application/json" \
     --data '{"purge_everything":true}'

If you can test it in command-line first, it should be easy to include it your post-receive hook.

The OP rodneyt confirms in the comments the solution is working, and adds:

To determine the correct zone ID view site in Cloudflare and copy Zone strings from the API section in right column (bottom)