---
title: "Replace a stage of a deployment template"
url: https://docs.corefinity.com/api/reference/deployments/replace-deploy-template-stage
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_stage_update.md
---
# Replace a stage of a deployment template

Sets one stage of the template, or hands it back to what it inherits, and writes the change through to every
environment that follows that stage. Send `dry_run` true first: the answer's `reach` lists the environments
the change would be written to and writes nothing. A change that reaches production environments is then saved
with `confirm_production`, `confirm_count` and `confirm_targets`, and is refused `reach_changed` if the reach
changed since.

```http
PUT /api/corestack/companies/{company}/deploy-templates/{platform}/{config}/stages/{stage}
```

- Scope: `write`
- Also needs `exec` when The save brings a command the saved stage does not hold (never for a dry run)
- 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.
- `config` (string, required): The configuration the stage belongs to.
- `stage` (string, required): The stage to save. `all` is only for copying one configuration onto the other with `copy_from_config`.

## 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.
- `also_uat` (boolean): For the production configuration only, make the same change to UAT.
- `copy_from_config` (string): With the stage `all`, copy every stage from the other configuration: the one that is not `{config}`. Not with `mode`, `value` or `also_uat`, and refused with any other stage. One of `production`, `uat`.
- `mode` (string): `inherit` hands the stage back to the level above and takes no `value`; `replace` sets it to `value`, which it needs. Required for every stage but `all`. One of `inherit`, `replace`.
- `revision` (integer, required): The template revision you read.
- `value` (object): A stage's content, in the shape the site pipeline's stage and settings endpoints take. The database and after-deploy stages hold `lines`; the build stage holds `mode` with a `preset` or its own `lines`; the settings stage holds the pipeline's settings, each one optional.
  - `hooks` (object): Build only, with `mode` `preset`: each hook's own commands under the hook's name, given once, here or inside `preset`. An empty list in place of the object sets no hook.
  - `keep_node_modules` (boolean)
  - `lines` (array of strings or string): Commands to save: a list with one line in each entry, or one string with a line break between lines. Lines are taken as sent. At most 200 commands, where a line that starts with `#` is a comment and is not counted, nor is an empty line; and at most 8,192 bytes a line, counting the spaces it starts with but not those at its end. More commands are refused `too_many_lines`, a longer line `line_too_long`. The patterns below count characters, so a line holding characters of more than one byte is refused sooner than they show.
  - `maintenance_policy` (string): Settings only, as each of the settings below. One of `when_needed`, `always`, `off`.
  - `mode` (string): Build only. One of `preset`, `custom`.
  - `pause_crons` (string or null) One of `auto`, `off`, `null`.
  - `platform_step_at` (integer or null): Database only. How many of the lines run before the platform's own database step.
  - `preset` (object)
    - `hooks` (object): Build only, with `mode` `preset`: each hook's own commands under the hook's name, given once, here or inside `preset`. An empty list in place of the object sets no hook.
  - `repository_contents` (string): On a WordPress template, what a repository connected from now on holds. It never changes a repository already connected. While site content repositories are paused, a save of `site_content` is refused `feature_off`: a 422, not the 404 a switched-off endpoint answers. One of `whole_site`, `site_content`.
  - `repository_target_path` (string or null): Where in the site that content goes. Null is `wp-content`, or `web/app` on Bedrock.
  - `run_migrations` (boolean or null): Laravel only.
  - `timeouts` (object): Settings only. Whole seconds for `build`, `build_line`, `database_line` and `post_line`, 60 to 3600 each, or null for the default. Any other key is refused `invalid`, and a number outside the bounds `timeout_out_of_range`. An empty list sets none.
  - `tunnels` (string) One of `auto`, `on`, `off`.

## Request

### curl

```bash
curl -X PUT https://manage.corefinity.com/api/corestack/companies/1204/deploy-templates/magento2/production/stages/post_deploy \
  -H "Authorization: Bearer $COREFINITY_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "confirm_count": 1,
    "confirm_production": true,
    "confirm_targets": [
      1042
    ],
    "mode": "replace",
    "revision": 2,
    "value": {
      "lines": [
        "php bin/magento cache:flush",
        "php bin/magento cron:install"
      ]
    }
  }'
```

### PHP

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

$response = Http::withToken(env('COREFINITY_TOKEN'))
    ->acceptJson()
    ->put('https://manage.corefinity.com/api/corestack/companies/1204/deploy-templates/magento2/production/stages/post_deploy', [
        'confirm_count' => 1,
        'confirm_production' => true,
        'confirm_targets' => [
            1042,
        ],
        'mode' => 'replace',
        'revision' => 2,
        'value' => [
            'lines' => [
                'php bin/magento cache:flush',
                'php bin/magento cron:install',
            ],
        ],
    ]);

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

### Node

```javascript
const res = await fetch('https://manage.corefinity.com/api/corestack/companies/1204/deploy-templates/magento2/production/stages/post_deploy', {
  method: 'PUT',
  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,
    ],
    mode: 'replace',
    revision: 2,
    value: {
      lines: [
        'php bin/magento cache:flush',
        'php bin/magento cron:install',
      ],
    },
  }),
});

// 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/companies/1204/deploy-templates/magento2/production/stages/post_deploy",
    headers={
        "Authorization": f"Bearer {os.environ['COREFINITY_TOKEN']}",
        "Accept": "application/json",
    },
    json={
        "confirm_count": 1,
        "confirm_production": True,
        "confirm_targets": [
            1042,
        ],
        "mode": "replace",
        "revision": 2,
        "value": {
            "lines": [
                "php bin/magento cache:flush",
                "php bin/magento cron:install",
            ],
        },
    },
)

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

## Responses

### 200 The template, with the reach of the change and, when it was saved, 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_stage_update`](https://docs.corefinity.com/mcp/tools/corestack_deployments_template_stage_update.md)
