---
title: "Copy an environment onto another"
url: https://docs.corefinity.com/api/reference/environments/clone-site
type: endpoint
last_updated: 2026-11-13
feature: copies
related:
  - https://docs.corefinity.com/guides/sites/environments-and-copies/clone-a-site.md
  - https://docs.corefinity.com/mcp/tools/corestack_site_clone.md
---
# Copy an environment onto another

Copies `{site}` onto another environment of its website, or onto production (push to live), replacing what
is there; quote the `preview_token` of `previewSiteClone`. A copy that starts answers 201 with its
operation; one that has to wait for something still running answers 202 and starts by itself
(`getQueuedCopy`). A copy onto production keeps a safety copy first and needs `confirm_name` set to the
website's domain.

```http
POST /api/corestack/sites/{site}/clone
```

- Scope: `write`
- Also needs `destructive` when The copy goes onto production (`target.type` is `production`)
- Also needs `exec` when `copy_node_runtime` is true and the source's Node.js packages run install scripts the target does not run now
- Two-factor: required on your account (all)
- Rate limit: 5 a minute
- 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

- `anonymise` (boolean): Make an anonymised copy. Shopware only, from the live database, never onto production. A value that is not true or false, and an anonymised copy that cannot be made, are refused `invalid`.
- `confirm_name` (string): For an environment, its name, typed exactly: checked whenever it is sent, and required when the copy replaces the whole environment. For production, the website's domain, always required.
- `copy_nginx_rules` (boolean): Also copy the source's Nginx rules, once the copy has completed.
- `copy_node_runtime` (boolean): Also copy the source's Node.js version and global packages.
- `copy_php_runtime` (boolean): Also copy the source's PHP settings, once the copy has completed.
- `node_acknowledge` (array of strings): With `copy_node_runtime`, what you acknowledge about the Node.js version being copied. Only `eol`, for a version past its end of life, and at most once.
- `preview_token` (string, required): The `preview_token` of `previewSiteClone`, asked with the same target, scope and snapshot within the last 15 minutes.
- `safety_first` (boolean): Keep a safety copy of the target before it is replaced. Always on for a copy onto production. Defaults to `true`.
- `scope` (string): What a copy takes: files and database, the database only, or files only. One of `files_db`, `db`, `files`. Defaults to `files_db`.
- `snapshot_id` (integer): Copy from this ready snapshot of the source instead of the live environment.
- `target` (object, required)
  - `environment_id` (integer): For `environment`, the site row id of the environment to copy onto. It cannot be production or the source itself.
  - `type` (string, required): `environment` copies onto `environment_id`. `production` copies onto the website's production (push to live). One of `environment`, `production`.

## Request

### curl

```bash
curl -X POST https://manage.corefinity.com/api/corestack/sites/1042/clone \
  -H "Authorization: Bearer $COREFINITY_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "confirm_name": "Staging",
    "preview_token": "cp_Xq7mR2vK9sLp4TzW8nBd",
    "safety_first": true,
    "scope": "files_db",
    "target": {
      "environment_id": 1043,
      "type": "environment"
    }
  }'
```

### PHP

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

$response = Http::withToken(env('COREFINITY_TOKEN'))
    ->acceptJson()
    ->post('https://manage.corefinity.com/api/corestack/sites/1042/clone', [
        'confirm_name' => 'Staging',
        'preview_token' => 'cp_Xq7mR2vK9sLp4TzW8nBd',
        'safety_first' => true,
        'scope' => 'files_db',
        'target' => [
            'environment_id' => 1043,
            'type' => 'environment',
        ],
    ]);

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

### Node

```javascript
const res = await fetch('https://manage.corefinity.com/api/corestack/sites/1042/clone', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.COREFINITY_TOKEN}`,
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    confirm_name: 'Staging',
    preview_token: 'cp_Xq7mR2vK9sLp4TzW8nBd',
    safety_first: true,
    scope: 'files_db',
    target: {
      environment_id: 1043,
      type: 'environment',
    },
  }),
});

// 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.post(
    "https://manage.corefinity.com/api/corestack/sites/1042/clone",
    headers={
        "Authorization": f"Bearer {os.environ['COREFINITY_TOKEN']}",
        "Accept": "application/json",
    },
    json={
        "confirm_name": "Staging",
        "preview_token": "cp_Xq7mR2vK9sLp4TzW8nBd",
        "safety_first": True,
        "scope": "files_db",
        "target": {
            "environment_id": 1043,
            "type": "environment",
        },
    },
)

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

## Responses

### 201 The copy started. Follow `operation.id` with `getOperation` until it completes.

```json
{
  "operation": {
    "applied_at": null,
    "can_retry": false,
    "cluster": {
      "id": 1017,
      "name": "Northwind UK 1"
    },
    "committed_at": null,
    "completed_at": null,
    "created_at": "2026-11-03T07:00:00Z",
    "environment": {
      "env_id": "rs-northwind-harbourandfinch-example-com--staging",
      "hostname": "harbourandfinch-example-com-staging.northwind.cfstack.example.net",
      "id": 1043,
      "name": "Staging",
      "role": "staging",
      "role_label": "Staging",
      "slug": "staging"
    },
    "error": null,
    "failure_reason": null,
    "from_version": null,
    "hot": false,
    "id": 5120,
    "install": null,
    "label": "Snapshots taken",
    "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": 1043
    },
    "status": "executing",
    "status_label": "Taking the source snapshot",
    "step": "snapshot",
    "steps": [
      {
        "key": "snapshot",
        "label": "Snapshots taken",
        "state": "current"
      },
      {
        "key": "bound",
        "label": "Prepared on the cluster",
        "state": "todo"
      },
      {
        "key": "holding",
        "label": "Disk slot held",
        "state": "todo"
      },
      {
        "key": "stopped",
        "label": "Target stopped",
        "state": "todo"
      },
      {
        "key": "copied",
        "label": "Data copied",
        "state": "todo"
      },
      {
        "key": "started",
        "label": "Target started",
        "state": "todo"
      },
      {
        "key": "fixups",
        "label": "Target adjusted",
        "state": "todo"
      },
      {
        "key": "cleanup",
        "label": "Tidied up",
        "state": "todo"
      }
    ],
    "subject": null,
    "summary": "Staging ← Production (files and database)",
    "to_version": null,
    "type": "clone",
    "type_label": "Clone"
  },
  "target": {
    "env_id": "rs-northwind-harbourandfinch-example-com--staging",
    "hostname": "harbourandfinch-example-com-staging.northwind.cfstack.example.net",
    "id": 1043,
    "name": "Staging",
    "role": "staging",
    "role_label": "Staging",
    "slug": "staging"
  }
}
```

### 202 The copy waits its turn (`reason` is `queued`) and starts by itself when what it waits for has finished. Read it with `getQueuedCopy` and `queued.id`; cancel it with `cancelQueuedCopy`.

```json
{
  "message": "Waiting for the change in progress on Staging to finish. It starts on its own.",
  "queued": {
    "ahead": 0,
    "deadline_at": "2026-11-03T13:00:00Z",
    "ended_at": null,
    "id": 6120,
    "message": "Waiting for the change in progress on Staging to finish. It starts on its own.",
    "operation_id": null,
    "queued_at": "2026-11-03T07:00:00Z",
    "reason": "target_busy",
    "source": {
      "id": 1042,
      "name": "Production"
    },
    "state": "waiting",
    "target": {
      "id": 1043,
      "name": "Staging"
    }
  },
  "reason": "queued",
  "target": {
    "env_id": "rs-northwind-harbourandfinch-example-com--staging",
    "hostname": "harbourandfinch-example-com-staging.northwind.cfstack.example.net",
    "id": 1043,
    "name": "Staging",
    "role": "staging",
    "role_label": "Staging",
    "slug": "staging"
  }
}
```

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

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

### 403 The token lacks a scope the copy needs (`scope_required`, with the `scope` to use: `write`, `destructive` for a copy onto production, `exec` for Node.js packages that run install scripts), or your company requires two-factor authentication and you have not set it up.

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

### 404 The source or the target does not exist or is not yours to change, the feature is not on for your company (`feature_off`), or `snapshot_id` is not a ready snapshot of the source.

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

### 409 The copy cannot be made now, and it is not something a copy waits for. `reason` says why: `copy_queued` (a copy onto this target already waits), `different_cluster`, `maintenance` (production is in maintenance mode), `too_small` (the target's disk is too small for the data), `scratch_over_quota` (the copy needs more working space than the target's size allows), `capacity_blocked` (with `dimension`), `storage_managed` (the storage of one of the two environments cannot take this copy, or is still being set up), `ssh_unreachable` and `measure_failed` (the source could not be reached or measured: try again in a few minutes), `shopware5_copy_unavailable`, `managed_elsewhere`, or, when copies do not wait their turn on your installation, `target_busy`, `busy` (a change in progress on the source) and `clone_in_progress`. Read `message` for any other reason.

```json
{
  "code": "busy",
  "message": "The source environment has a change in progress. Wait for it to finish.",
  "reason": "busy"
}
```

### 422 The request cannot be taken as written. `invalid` names the field in `field` and `errors`: no or an unknown target or scope, a key the body does not take, a `preview_token` that is missing, older than 15 minutes or was made for another target, scope or snapshot, the same environment as source and target, or a production environment named as an `environment` target. `confirm_mismatch`: `confirm_name` is missing where it is required, or does not match. `snapshot_transfer`: a saved snapshot cannot be copied to an environment on other servers. `ack_required` and `node_major_existing_only`: the Node.js version being copied needs `node_acknowledge`, or cannot be copied to this target. `legacy_search`: a Magento 2 environment whose search runs on a temporary older engine cannot be pushed to live. A `copy_…` field that is not true or false is `invalid` too.

```json
{
  "code": "invalid",
  "errors": {
    "anonymise": [
      "An anonymised copy is offered on Shopware only"
    ]
  },
  "field": "anonymise",
  "message": "An anonymised copy is offered on Shopware only",
  "reason": "invalid"
}
```

### 429 Too many copies in a minute (`rate_limited`: wait for `Retry-After` seconds; only a copy that is taken counts), or your company already has three copies or restores running (`copy_limit`).

```json
{
  "code": "copy_limit",
  "message": "Your company already has 3 copies or restores running. Try again when one has finished.",
  "reason": "copy_limit"
}
```

### 502 The environments could not be read, so nothing was started. Try again in a minute.

```json
{
  "message": "Live status is unavailable. Try again in a minute."
}
```

### 503 The copy cannot be made at the moment (`temporarily_unavailable`). Nothing was changed.

```json
{
  "code": "temporarily_unavailable",
  "message": "We can't make this copy right now. Nothing was changed. Try again in a few minutes; contact support if it keeps happening.",
  "reason": "temporarily_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 | `clone_in_progress` | Another copy is running on the site. Wait for it to finish. |
| 409 | `copy_queued` | A copy onto Staging is already waiting its turn. Cancel it first to queue another. |
| 409 | `different_cluster` | A copy works within one cluster, and the target is in another. Choose a target in the same cluster. |
| 409 | `maintenance` | The site is in maintenance mode, which blocks this. Switch maintenance mode off first. |
| 409 | `managed_elsewhere` | This site is read-only here. Change it in the control panel that manages it. |
| 409 | `ssh_unreachable` | The environment you are copying from cannot be reached right now. Try again in a few minutes. |
| 409 | `target_busy` | The environment to copy or restore into is busy with another change. Nothing was changed. Wait, then try again. |
| 409 | `too_small` | The target is too small for what it would hold. Choose a larger size. |
| 422 | `invalid` | Fix the field named in `field`; `errors` says why. |
| 422 | `confirm_mismatch` | Send the confirmation exactly as the field named in `field` asks for it. |
| 422 | `legacy_search` | This site's search runs on a temporary older engine. Switch the store to the OpenSearch module first. |
| 422 | `snapshot_transfer` | A saved snapshot can be copied only to an environment on the same servers for now. Copy the live environment instead, or restore the snapshot first. |
| 429 | `copy_limit` | Your company already has 3 copies or restores running. Try again when one has finished. |
| 429 | `rate_limited` | Wait for the seconds in `Retry-After`. |
| 502 |  | Read the message; it says what happened. |
| 503 | `temporarily_unavailable` | The Control Panel could not answer just now. Nothing was started; try again shortly. |

## The same task elsewhere

- Guide: [Clone an environment](https://docs.corefinity.com/guides/sites/environments-and-copies/clone-a-site.md)
- MCP tool: [`corestack_site_clone`](https://docs.corefinity.com/mcp/tools/corestack_site_clone.md)
