How to Clear Cloudflare Cache using a webhook

Automatically purge Cloudflare cache using webhooks and API tokens.

How to Clear Cloudflare Cache using a webhook

When deploying web apps, caching can often get in the way of seeing fresh changes instantly. If you’re using Cloudflare for CDN and DNS, you can automate cache purging as part of your deployment process.

Prerequisites

Before you begin, make sure you have:

  • A Cloudflare account
  • Your Zone ID (found in the Cloudflare dashboard under your domain settings)

Create a Cloudflare API Token

  1. Go to your Cloudflare API Tokens page.
  2. Click “Create Token”.
  3. Select “Custom Token” and grant these permissions:
    • Zone.Zone → Read
    • Zone.Cache Purge → Purge
  4. Scope the token to the specific zone (domain) you’re working with.
  5. Save the token securely — you’ll need it shortly.

Test the token

You can test your token using curl:

curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
     -H "Authorization: Bearer [__CF_TOKEN__]" \
     -H "Content-Type:application/json"

Don’t forget to replace [__CF_TOKEN__] with your actual token.

Purging the Cache

To purge the cache, you can use the following curl command. Replace [__CF_ZONE_ID__] with your Cloudflare Zone ID and [__CF_TOKEN__] with your API token:

curl -X POST "https://api.cloudflare.com/client/v4/zones/[__CF_ZONE_ID__]/purge_cache" \
     -H "Authorization: Bearer [__CF_TOKEN__]" \
     -H "Content-Type: application/json" \
     --data '{"purge_everything":true}'

Optional: Purge Specific Files

If you want to clear only certain files (e.g., /index.html, /styles.css), change the data payload:

--data '{"files":["https://yourdomain.com/index.html", "https://yourdomain.com/styles.css"]}'

Integrate with Coolify

If you are using the fantastic PaaS Coolify for your deployments, you can automate the cache purging process by adding a post-deployment script.

In your Coolify project configuration, scroll to the “Post-Deployment Script” section and add the curl command you created above.

This command will:

  • Run automatically after each successful deploy.
  • Clear all cached assets from Cloudflare for your domain.

Now every time you deploy through Coolify, Cloudflare’s cache will be purged, ensuring that your latest changes are immediately reflected.

More Articles

Adding Umami analytics to the OpenClaw morning brief

Adding Umami analytics to the OpenClaw morning brief

An agent skill that fetches traffic data from Umami, and how it fits into a daily automated briefing.

Setting up Google Calendar sync for OpenClaw

Setting up Google Calendar sync for OpenClaw

How I set up read-only Google Calendar sync for my personal AI assistant running on a home server VM.

Better Clipboard Handling in Claude Code

Better Clipboard Handling in Claude Code

A plugin that makes clipboard operations in Claude Code more reliable and natural to use.

Get notified when Claude Code needs your input

Get notified when Claude Code needs your input

Stop constantly checking your terminal. Set up notifications that alert you when Claude Code is ready for your input.

Auto-format generated Code with Claude Code Hooks

Auto-format generated Code with Claude Code Hooks

How to set up a PostToolUse hook in Claude Code to automatically run prettier after every file edit or write operation.

PWA Web Share Target on Android: The Absolute URL Fix

PWA Web Share Target on Android: The Absolute URL Fix

Getting the Web Share Target API to work on Android PWAs can be frustrating. Your manifest looks correct, but the app never appears in the share sheet. Here is what finally worked.

Standard function keys on external keyboards in MacOS

Standard function keys on external keyboards in MacOS

Configure Karabiner Elements to use standard function keys on external keyboards while keeping media keys on your MacBook.

Monitoring Cron Jobs with Notifery

Monitoring Cron Jobs with Notifery

Stop silent cron job failures from catching you off guard.

Multiplayer Web Game Starter / POC

Multiplayer Web Game Starter / POC

A starting point for building a web-based multiplayer game, utilizing modern web development technologies.