Cloudflare admin form

The Cloudflare Purge module provides an easy and secure way to manually purge Cloudflare cache from within your Drupal site. It uses the Guzzle HTTP client instead of raw cURL and supports both API Key and Bearer Token authentication methods.

This module replicates the functionality of the following cURL command using Drupal’s internal HTTP API:

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

It also allows purging specific URLs from the Cloudflare cache via a dedicated form, offering finer cache control for developers and editors.

Features

  • Supports both API Key and Bearer Token authentication.
  • Allows purging all cache or individual URLs.
  • Provides a secure, permissions-based interface for cache purging.
  • Credentials can be configured via the admin UI or settings.php.

Typical Use Cases

  • Your hosting provider enables Cloudflare but doesn’t support Drupal-based purging.
  • You’re using the Cloudflare module but can’t install its purge submodule.
  • You need a lightweight alternative for targeted cache control in development or production.

Security

All requests are routed through Drupal's Guzzle HTTP client with CSRF protection and proper permissions, ensuring safe integration without exposing sensitive data.

Requirements

  • Drupal 9.4+ or 10/11.
  • A valid Cloudflare account.
  • Cloudflare Zone ID.
  • One of the following authentication methods:
    • API Key (X-Auth-Key and Email)
    • Bearer Token
  • Permission in Cloudflare: #cache_purge:edit

Installation

Install the module as you would any contributed module.

Configuration

Go to /admin/config/cloudflare-purge/credentials to enter your credentials and toggle between API Key and Bearer Token authentication.

Optional: Use settings.php for Credentials

You can optionally store credentials in settings.php. When present, UI fields will be disabled for safety:

$settings['cloudflare_purge_credentials'] = [
  'email' => 'info@example.com',
  'zone_id' => 'your-zone-id',
  'authorization' => 'your-api-key',
  'bearer_token' => 'your-bearer-token',
  'use_bearer_token' => TRUE,
];

New in Latest Version

  • Support for Bearer Token authentication.
  • Dedicated form to purge a .
  • Improved form logic and config override detection.

Permissions

Drupal admin can give permissions to any Drupal role to purge cached resources from Cloudflare.

Security

As an extra precaution, when you uninstall the module, the Zone ID & Authorization will be deleted from the database.

Legal

This module has not been built, maintained, or supported by Cloudflare Inc. This is an open-source project with no association with Cloudflare Inc. The module uses their API, that's all.

* Read more about Cloudflare's API: Cloudflare API Documentation

Using Cloudflare and Drupal: Five Easy Recommended Steps

back to top ☝️

Alaa Haddad

Developed & Designed By: Alaa Haddad


A Personal Thank You for Your Support

Every project you see here, including this one, reflects countless hours of work driven by my passion for making Drupal better for everyone. Your support truly makes a difference, and there are a few simple ways you can help these projects grow and reach others who might benefit:

  • Use & Share Feedback: Have you found this project (or any of my other work) helpful? Let me know what worked well or how it could be improved. Real user input drives better tools for the entire community.
  • Click "Like" on Drupal.org: It may seem small, but liking this project on Drupal.org helps others discover and trust these tools.
  • Spread the Word: Share these projects on social media, Slack groups, or anywhere Drupal folks connect. Your word of mouth helps these tools find the people who need them.
  • Explore More of My Work: Check out my other projects on Drupal.org to see what else might support your workflow or inspire your next build.

W3CSS Theme (d8w3css) - Solo - W3CSS Paragraphs - Paragraphs Bundles - Amun - Amunet - Anhur - Acquia Purge Varnish - Cloudflare Purge - Reference Blocked Users - Solo Copy Blocks - Solo Utilities - PB Import - VVJA - Accordion - VVJC - 3D Carousel - VVJB - Basic Carousel - VVJF - 3D FlipBox - VVJH - Hero - VVJL - Lightbox - VVJP - Parallax - VVJR - Reveal - VVJS - Slideshow - VVJT - Tabs - Module Matrix - Selectify - Utilikit

If you have any questions, ideas, or feedback about my Drupal.org projects, I’d love to hear from you! To keep things open and helpful for the entire community, I encourage you to post directly in the project's issue queue on Drupal.org. This way, your questions and the answers can benefit others who may have the same needs.

At the end of the day, my goal is to make Drupal easier and more enjoyable for everyone, especially small businesses and site builders who want to create professional sites without extra hassle. Together, we can build something even better. Thank you for your support, and for being part of this journey!

Supporting organizations: 
FlashWebCenter.com: Drupal Developments Services.
DrupalCare.com: Drupal Update & Maintenance Services.

Project information

Releases