---
description: Purge cache for specific zone versions using the API.
title: Purge zone versions via API
image: https://developers.cloudflare.com/og-docs.png
---

[Skip to content](#main-content)

> Documentation Index  
> Fetch the complete documentation index at: https://developers.cloudflare.com/cache/llms.txt  
> Use this file to discover all available pages before exploring further.

# Purge zone versions via API

Last updated Aug 24, 2026|Copy as Markdown|[View as Markdown](https://docs-durable-objects-instance-replaced-errors.previews.developers.cloudflare.com/cache/how-to/purge-cache/purge-zone-versions/index.md)|[Agent setup](https://docs-durable-objects-instance-replaced-errors.previews.developers.cloudflare.com/agent-setup/)

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:

```bash
https://api.cloudflare.com/client/v4/zones/<zone_id>/environments
```

This API call will return a JSON response similar to the example below:

```json
{
  "result": {
    "environments": [
      {
        "name": "Production",
        "ref": "12abcd3e45f678940a573f51834a54",
        "version": 0,
        "expression": "(cf.zone.name eq \"example.com\")",
        "locked_on_deployment": false,
        "position": {
          "before": "5d41402abc4b2a76b9719d911017c"
        }
      },
      {
        "name": "Staging",
        "ref": "5d41402abc4b2a76b9719d911017c",
        "version": 0,
        "expression": "((cf.edge.server_ip in {1.2.3.4 5.6.7.8})) and (cf.zone.name eq \"example.com\")",
        "locked_on_deployment": false,
        "position": {
          "before": "49f0bad299687c62334182178bfd",
          "after": "12abcd3e45f678940a573f51834a54"
        }
      },
      {
        "name": "Development",
        "ref": "49f0bad299687c62334182178bfd",
        "version": 0,
        "expression": "((any(http.request.cookies[\"development\"][*] eq \"true\"))) and (cf.zone.name eq \"example.com\")",
        "locked_on_deployment": false,
        "position": {
          "after": "5d41402abc4b2a76b9719d911017c"
        }
      }
    ]
  },
  "success": true,
  "errors": [],
  "messages": []
}
```

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:

```bash
https://api.cloudflare.com/client/v4/zones/<zone_id>/purge_cache/
```

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:

```bash
https://api.cloudflare.com/client/v4/zones/<zone_id>/environments/5d41402abc4b2a76b9719d911017c/purge_cache/
```

To purge the Development environment from the example above, send a request to the following endpoint:

```bash
https://api.cloudflare.com/client/v4/zones/<zone_id>/environments/49f0bad299687c62334182178bfd/purge_cache/
```

Note

When purging everything for a non-production cache environment, all files for that specific cache environment will be purged. However, when purging everything for the production environment, all files will be purged across all environments.

Was this helpful?

YesNo

## On this page

[![](https://docs-durable-objects-instance-replaced-errors.previews.developers.cloudflare.com/_astro/logo.te5VL_aD.svg)Docs](https://docs-durable-objects-instance-replaced-errors.previews.developers.cloudflare.com/)

```json
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/cache/how-to/purge-cache/purge-zone-versions/#page","headline":"Purge zone versions via API · Cloudflare Cache (CDN) docs","description":"Purge cache for specific zone versions using the API.","url":"https://developers.cloudflare.com/cache/how-to/purge-cache/purge-zone-versions/","inLanguage":"en","image":"https://developers.cloudflare.com/og-docs.png","dateModified":"2026-08-24","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
```
