To purge zone versions via the Cloudflare API, follow these steps:
Step 1: Retrieve the environment ID
First, retrieve your zone's environment ID by sending a request to the following API endpoint:
This API call will return a JSON response similar to the example below:
In this particular example, we have three environments: Production, Staging, and Development. You can find the environment ID in the ref
field.
Step 2: Purge cache per environment
To purge the Production environment, use the general cache purge endpoint:
To purge non-production environments, you must use a new purge_cache
endpoint and specify the environment you would like to purge.
To purge the Staging environment from the example above, send a request to the following endpoint:
To purge the Development environment from the example above, send a request to the following endpoint:
Thank you for helping improve Cloudflare's documentation!