---
title: "Restore a version of a deployment template"
url: https://docs.corefinity.com/api/reference/deployments/restore-deploy-template
type: endpoint
last_updated: 2026-11-13
feature: deployment-templates
related:
  - https://docs.corefinity.com/guides/sites/code-and-deployments/deployment-templates.md
  - https://docs.corefinity.com/mcp/tools/corestack_deployments_template_restore.md
---
# Restore a version of a deployment template

Puts the template back to a kept revision (`version_id`), or every stage back to Corefinity's default
(`version` `corefinity`), as a new revision, and writes the change through to the environments that follow it.
Send exactly one of `version_id` and `version`. It is confirmed exactly as a stage save is.

```http
POST /api/corestack/companies/{company}/deploy-templates/{platform}/restore
```

- Scope: `write`
- Two-factor: required on your account (all)
- Rate limit: 10 a minute
- 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

- `company` (integer, required): The id of a company you belong to or manage. Digits only.
- `platform` (string, required): The platform the template is for, such as `magento2`, `laravel` or `wordpress`. The list answers the ones your company can have.

## Body

- `confirm_count` (integer): The dry run's `reach.production_count`.
- `confirm_production` (boolean): True to confirm a change that reaches production environments.
- `confirm_targets` (array of integers): The `site_id` of every production environment in the dry run's `reach.production`.
- `dry_run` (boolean): Answer the reach and write nothing.
- `keep_on` (array of integers): The `site_id`s of environments that keep their own stage. Every environment the reach lists under `cannot_take` must be named.
- `revision` (integer, required): The template revision you read.
- `version` (string): Instead of `version_id`, `corefinity` puts every stage back to Corefinity's default. One of `corefinity`.
- `version_id` (integer): The revision to restore, as the versions list answers it.

## Request

### curl

```bash
curl -X POST https://manage.corefinity.com/api/corestack/companies/1204/deploy-templates/magento2/restore \
  -H "Authorization: Bearer $COREFINITY_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "confirm_count": 1,
    "confirm_production": true,
    "confirm_targets": [
      1042
    ],
    "revision": 2,
    "version_id": 1
  }'
```

### PHP

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

$response = Http::withToken(env('COREFINITY_TOKEN'))
    ->acceptJson()
    ->post('https://manage.corefinity.com/api/corestack/companies/1204/deploy-templates/magento2/restore', [
        'confirm_count' => 1,
        'confirm_production' => true,
        'confirm_targets' => [
            1042,
        ],
        'revision' => 2,
        'version_id' => 1,
    ]);

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

### Node

```javascript
const res = await fetch('https://manage.corefinity.com/api/corestack/companies/1204/deploy-templates/magento2/restore', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.COREFINITY_TOKEN}`,
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    confirm_count: 1,
    confirm_production: true,
    confirm_targets: [
      1042,
    ],
    revision: 2,
    version_id: 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.post(
    "https://manage.corefinity.com/api/corestack/companies/1204/deploy-templates/magento2/restore",
    headers={
        "Authorization": f"Bearer {os.environ['COREFINITY_TOKEN']}",
        "Accept": "application/json",
    },
    json={
        "confirm_count": 1,
        "confirm_production": True,
        "confirm_targets": [
            1042,
        ],
        "revision": 2,
        "version_id": 1,
    },
)

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

## Responses

### 200 The template, with the reach of the restore and, when it was made, what was written.

```json
{
  "can": {
    "edit": true,
    "edit_reason": null
  },
  "chain_note": null,
  "company": {
    "id": 1180,
    "name": "Northwind Digital"
  },
  "configs": {
    "production": {
      "build": {
        "mode": "inherit"
      },
      "database": {
        "mode": "inherit"
      },
      "post_deploy": {
        "mode": "replace",
        "value": {
          "lines": [
            "php bin/magento cache:flush",
            "php bin/magento cron:install"
          ]
        }
      },
      "settings": {
        "mode": "inherit"
      }
    },
    "uat": {
      "build": {
        "mode": "inherit"
      },
      "database": {
        "mode": "inherit"
      },
      "post_deploy": {
        "mode": "inherit"
      },
      "settings": {
        "mode": "inherit"
      }
    }
  },
  "dry_run": false,
  "locked": null,
  "platform": "magento2",
  "presets": {
    "offered": []
  },
  "reach": {
    "cannot_take": [],
    "confirm": {
      "count": 1,
      "required": true
    },
    "digest": "3b50f766bb040794",
    "environments": 1,
    "in_flight": [],
    "list_max": 50,
    "not_reached": [],
    "production": [
      {
        "binding_id": 2210,
        "environment": {
          "name": "Production",
          "slug": "production"
        },
        "site": {
          "domain": "harbourandfinch.example.com",
          "id": 1042
        },
        "site_id": 1042,
        "stages": [
          "post_deploy"
        ]
      }
    ],
    "production_count": 1,
    "tunnels": {
      "access_update": [],
      "runtime_needed": []
    },
    "uat": [],
    "uat_count": 0,
    "unchanged": 0
  },
  "revision": 3,
  "template_id": 12,
  "upstreams": [],
  "written": {
    "environments": 1,
    "kept": 0,
    "revisions": 1,
    "tunnel_access_started": []
  }
}
```

### 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: `write`, or `exec` for a reveal and for a change that brings a new command), your company requires two-factor authentication and you have not set it up, or your role lacks the Edit Environment Deployment Pipeline permission (`forbidden`, with `permission`).

```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 template changed since the `revision` you sent (`stale`, with the `revision` it is at now): read it again. Or the environments the change reaches are not the ones you confirmed (`reach_changed`, with the new `reach`, or with `refused` naming an environment that can no longer take the change): review them and confirm again. Or Corefinity has locked the template (`template_locked`).

```json
{
  "code": "reach_changed",
  "message": "The environments this change reaches have changed since you reviewed it. Review them again, then confirm.",
  "reach": {
    "cannot_take": [],
    "confirm": {
      "count": 1,
      "required": true
    },
    "digest": "3b50f766bb040794",
    "environments": 1,
    "in_flight": [],
    "list_max": 50,
    "not_reached": [],
    "production": [
      {
        "binding_id": 2210,
        "environment": {
          "name": "Production",
          "slug": "production"
        },
        "site": {
          "domain": "harbourandfinch.example.com",
          "id": 1042
        },
        "site_id": 1042,
        "stages": [
          "post_deploy"
        ]
      }
    ],
    "production_count": 1,
    "tunnels": {
      "access_update": [],
      "runtime_needed": []
    },
    "uat": [],
    "uat_count": 0,
    "unchanged": 0
  },
  "reason": "reach_changed"
}
```

### 422 The request was refused and nothing was saved. - `invalid`: a field is missing, of the wrong type or not one this endpoint takes, or the stage's `value` is not in the stage's shape. `field` names it; inside a value it is the path, such as `production.build.mode`. - `confirm`: the change reaches production environments and is not confirmed. The answer carries the `reach`. - `version_unavailable`: the version to restore is not one this template keeps. - `preset_unavailable`, `node_too_old`: a build preset, or a Node.js version, that cannot be used here, or two presets that cannot be used together. - `line_credentials`, `too_many_lines`, `line_too_long`: a line that holds a credential, a stage or a hook of more than 200 commands, or a line of more than 8,192 bytes. - `maintenance_policy_unavailable`, `wrong_platform`, `timeout_out_of_range`: a setting the platform does not offer, or a timeout outside its bounds. - `template_refused_on`: an environment the change reaches cannot take it and is not named in `keep_on`. The answer's `refused_on` lists each one's `site_id`, `stage`, `reason` and `message`. Every reason but `invalid` names its field in `errors` only.

```json
{
  "code": "confirm",
  "errors": {
    "confirm_count": [
      "Type the number of production environments to confirm the change."
    ]
  },
  "message": "Type the number of production environments to confirm the change.",
  "reach": {
    "cannot_take": [],
    "confirm": {
      "count": 1,
      "required": true
    },
    "digest": "3b50f766bb040794",
    "environments": 1,
    "in_flight": [],
    "list_max": 50,
    "not_reached": [],
    "production": [
      {
        "binding_id": 2210,
        "environment": {
          "name": "Production",
          "slug": "production"
        },
        "site": {
          "domain": "harbourandfinch.example.com",
          "id": 1042
        },
        "site_id": 1042,
        "stages": [
          "post_deploy"
        ]
      }
    ],
    "production_count": 1,
    "tunnels": {
      "access_update": [],
      "runtime_needed": []
    },
    "uat": [],
    "uat_count": 0,
    "unchanged": 0
  },
  "reason": "confirm"
}
```

### 429 Too many requests (`rate_limited`). Wait for the number of seconds in `Retry-After`, which `retry_after_seconds` repeats.

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

## 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 | `forbidden` | The person is not allowed to do this. |
| 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 | `reach_changed` | The environments this change reaches have changed since you reviewed it. Review them again, then confirm. |
| 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 | `template_locked` | Corefinity has locked this template: Held while a change is reviewed. |
| 422 | `confirm` | The action needs an explicit confirmation field. Ask the person, then send it. |
| 422 | `invalid` | Fix the field named in `field`; `errors` says why. |
| 422 | `feature_off` | This feature is not on for your organisation yet. |
| 422 | `timeout_out_of_range` | Choose a timeout between 60 and 3600 seconds. |
| 422 | `version_unavailable` | This version is not available here. |
| 429 | `rate_limited` | Wait for the seconds in `Retry-After`. |

## The same task elsewhere

- Guide: [Deployment templates](https://docs.corefinity.com/guides/sites/code-and-deployments/deployment-templates.md)
- MCP tool: [`corestack_deployments_template_restore`](https://docs.corefinity.com/mcp/tools/corestack_deployments_template_restore.md)
