---
title: "Replace a site's custom VCL"
url: https://docs.corefinity.com/api/reference/varnish/replace-site-varnish-vcl
type: endpoint
last_updated: 2026-11-13
feature: varnish
related:
  - https://docs.corefinity.com/guides/sites/software-and-services/varnish.md
  - https://docs.corefinity.com/mcp/tools/corestack_varnish_vcl_update.md
---
# Replace a site's custom VCL

Saves the snippets sent in `hooks`: a snippet left out stays as it is. Send the `version` from the last read. The VCL is checked against the policy, compiled, saved and loaded by Varnish, which takes about a minute; one that Varnish refuses or that breaks the shop's home page is put back automatically.

```http
PUT /api/corestack/sites/{site}/varnish/vcl
```

- Scope: `write`
- Two-factor: required on your account (all)
- Rate limit: 20 a minute; 20 a minute for each environment
- Long-running: answers with an operation to poll
- Try it in the console: off. It overwrites data that cannot be brought back. Copy the request and run it yourself when you are sure.

## Path parameters

- `site` (integer, required): The id of a site row. A website's production site and each of its environments has its own id. Digits only.

## Body

- `hooks` (object, required): The snippets to change. One left out stays as it is; `""` or null empties it.
  - `backend_response` (string or null)
  - `deliver` (string or null)
  - `recv` (string or null)
- `note` (string or null): Why, shown in the history.
- `version` (integer, required): The `version` from the last read.

## Request

### curl

```bash
curl -X PUT https://manage.corefinity.com/api/corestack/sites/1042/varnish/vcl \
  -H "Authorization: Bearer $COREFINITY_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "hooks": {
      "backend_response": "if (bereq.url ~ \"^/size-guides/\") { set beresp.ttl = 1d; }"
    },
    "note": "Cache the size guides for a day",
    "version": 1
  }'
```

### PHP

```php
use Illuminate\Support\Facades\Http;

$response = Http::withToken(env('COREFINITY_TOKEN'))
    ->acceptJson()
    ->put('https://manage.corefinity.com/api/corestack/sites/1042/varnish/vcl', [
        'hooks' => [
            'backend_response' => 'if (bereq.url ~ "^/size-guides/") { set beresp.ttl = 1d; }',
        ],
        'note' => 'Cache the size guides for a day',
        'version' => 1,
    ]);

$data = $response->json();
```

### Node

```javascript
const res = await fetch('https://manage.corefinity.com/api/corestack/sites/1042/varnish/vcl', {
  method: 'PUT',
  headers: {
    Authorization: `Bearer ${process.env.COREFINITY_TOKEN}`,
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    hooks: {
      backend_response: 'if (bereq.url ~ "^/size-guides/") { set beresp.ttl = 1d; }',
    },
    note: 'Cache the size guides for a day',
    version: 1,
  }),
});

// An answer with no body (204) has nothing to parse.
const text = await res.text();
const data = text && JSON.parse(text);
```

### Python

```python
import os
import requests

res = requests.put(
    "https://manage.corefinity.com/api/corestack/sites/1042/varnish/vcl",
    headers={
        "Authorization": f"Bearer {os.environ['COREFINITY_TOKEN']}",
        "Accept": "application/json",
    },
    json={
        "hooks": {
            "backend_response": "if (bereq.url ~ \"^/size-guides/\") { set beresp.ttl = 1d; }",
        },
        "note": "Cache the size guides for a day",
        "version": 1,
    },
)

data = res.json() if res.content else None
```

## Responses

### 200 Nothing to follow: the VCL is what the site already has (`revision` and `operation` null), or Varnish is off, so the VCL was saved and loads when Varnish is switched on (`varnish_off: true`).

```json
{
  "operation": null,
  "revision": null
}
```

### 202 The VCL was saved and is being loaded, which takes about a minute. Follow `operation`: its `vcl.outcome` says whether Varnish loaded it.

```json
{
  "operation": {
    "applied_at": null,
    "can_retry": false,
    "cluster": {
      "id": 1017,
      "name": "Northwind UK 1"
    },
    "committed_at": "2026-11-06T09:16:40Z",
    "completed_at": null,
    "created_at": "2026-11-06T09:16:40Z",
    "environment": {
      "env_id": "rs-harbourandfinch-example-com",
      "hostname": "harbourandfinch-example-com.northwind.cfstack.example.net",
      "id": 1042,
      "name": "Production",
      "role": "production",
      "role_label": "Production",
      "slug": "production"
    },
    "error": null,
    "failure_reason": null,
    "from_version": null,
    "hot": false,
    "id": 5125,
    "install": null,
    "label": "Loaded by Varnish",
    "notes": [],
    "parent_operation_id": null,
    "requested_by": {
      "id": 2041,
      "name": "Eleanor Finch"
    },
    "reset_target": null,
    "result": null,
    "result_state": "none",
    "retried_by_operation_id": null,
    "retries_operation_id": null,
    "retry_requires": null,
    "revealed": null,
    "scope": "site",
    "site": {
      "domain": "harbourandfinch.example.com",
      "id": 1042
    },
    "status": "committed",
    "status_label": "Waiting for the platform",
    "step": "loaded",
    "steps": [
      {
        "key": "policy",
        "label": "Checked against the policy",
        "state": "done"
      },
      {
        "key": "compiled",
        "label": "Compiled",
        "state": "done"
      },
      {
        "key": "loaded",
        "label": "Loaded by Varnish",
        "state": "current"
      },
      {
        "key": "checked",
        "label": "Checked",
        "state": "todo"
      }
    ],
    "subject": null,
    "summary": "Varnish VCL",
    "to_version": null,
    "type": "varnish_vcl_change",
    "type_label": "Varnish VCL"
  },
  "revision": {
    "number": 2,
    "status": "saving"
  },
  "warnings": []
}
```

### 401 No token, or a token that is not valid.

```json
{
  "message": "Unauthenticated."
}
```

### 403 The token lacks the scope (`scope_required`, with the `scope` to use), your company requires two-factor authentication and you have not set it up, or your account has no company that can use Managed Clusters, for example because the company was closed (`company_unavailable` or `company_not_enabled`, whichever the route checks first). For Managed Clusters routes; any other route uses `ForbiddenScopeOrTwoFactor`.

```json
{
  "code": "company_unavailable",
  "message": "Your company is unavailable.",
  "reason": "company_unavailable"
}
```

### 404 The id does not exist or is something you cannot see, or the feature is not on for your company (`feature_off`).

```json
{
  "code": "feature_off",
  "message": "Not found.",
  "reason": "feature_off"
}
```

### 409 The save was refused because of the site's state. `reason` says why: `stale` (the VCL changed since your read; `version` is the current one), `varnish_off` (Varnish has never been set up on the site: switch it on first), `varnish_not_offered` (not a Magento 2 site), `busy`, `restore_running` or `cluster_paused` (other work has not finished, or changes to the site's cluster are paused), `conflict` (another change landed first: try again), `removed` or `managed_elsewhere`.

```json
{
  "code": "busy",
  "message": "Another change to this site is in progress. Wait for it to finish.",
  "reason": "busy"
}
```

### 422 A field is missing or wrong (`invalid`, with `field` and `errors`), the VCL breaks the policy (`vcl_invalid`) or does not compile (`vcl_compile_failed`), each with `diagnostics`, or Corefinity manages the site's VCL (`vcl_locked`). Nothing was saved.

```json
{
  "code": "invalid",
  "errors": {
    "hooks": [
      "hooks is an object of recv, backend_response and deliver, each text or null."
    ]
  },
  "field": "hooks",
  "message": "hooks is an object of recv, backend_response and deliver, each text or null.",
  "reason": "invalid"
}
```

### 429 Too many requests (`rate_limited`): the endpoint's request limit, or the 20 VCL saves and reverts a minute this environment takes from the API and AI assistants together. Wait for `Retry-After`, which `retry_after_seconds` repeats; the save allowance's answer also carries `retry_after`.

```json
{
  "code": "rate_limited",
  "message": "Too many requests. Try again in 60 seconds.",
  "reason": "rate_limited",
  "retry_after_seconds": 60
}
```

### 503 The site's files could not be read, so nothing was saved (`upstream_unavailable`). Try again in a minute.

```json
{
  "code": "upstream_unavailable",
  "message": "The environment's files could not be read. Try again in a minute.",
  "reason": "upstream_unavailable"
}
```

## If it is refused

| Status | Reason | What to do |
|---|---|---|
| 401 |  | Send a valid token as `Authorization: Bearer <token>`. |
| 403 | `company_unavailable` | Your company is unavailable. |
| 403 | `scope_required` | Use a token with the scope named in `scope`. |
| 403 | `two_factor_required` | Turn on two-factor on your account, then send again. |
| 404 | `feature_off` | This feature is not on for your organisation yet. |
| 409 | `busy` | Another operation is running on the site. Wait for it to finish. |
| 409 | `managed_elsewhere` | This site is read-only here. Change it in the control panel that manages it. |
| 409 | `stale` | What you read has changed since you read it. Read it again, then send the change with its new version or quote. |
| 409 | `varnish_not_offered` | Varnish is available for Magento 2 sites only. Nothing to change here. |
| 409 | `varnish_off` | Varnish is off on the environment. Switch it on first. |
| 422 | `invalid` | Fix the field named in `field`; `errors` says why. |
| 422 | `vcl_invalid` | The VCL breaks a rule of the platform. Nothing was saved. Fix what the message names. |
| 422 | `vcl_locked` | Corefinity manages this environment's VCL. Contact support to change it. |
| 429 | `rate_limited` | Wait for the seconds in `Retry-After`. |
| 503 | `upstream_unavailable` | A service the action depends on did not answer. Try again later. |

## The same task elsewhere

- Guide: [Varnish](https://docs.corefinity.com/guides/sites/software-and-services/varnish.md)
- MCP tool: [`corestack_varnish_vcl_update`](https://docs.corefinity.com/mcp/tools/corestack_varnish_vcl_update.md)
