# Rollback template deployment

`POST https://api.instacloud.com/projects/{projectId}/template-deployments/{deploymentId}/rollback`

**Token scope:** `account` · `org` · `project` — read-only tokens refused (not a GET).

Return a deployed template instance to the version it was upgraded from — one step, from wherever it is now (async — poll GET /template-deployments/:id). Restores the image, start command, port, always-on, public access, the volume mount path and recorded variables from the older manifest. An existing volume is never resized. Public access on a STORAGE service is lineage-wide: it sets that bucket's access on every branch that has a copy. It does NOT restore data: an app that migrated its own database under the newer version cannot read it back, and a volume only grows.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `projectId` | path | `string` | yes |  |
| `deploymentId` | path | `string` | yes |  |

## Request body (application/json)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `variables` | `object` | no | values for required variables the older version needs that the instance no longer holds — an upgrade to a version that stopped declaring a variable DELETES its value, and the older manifest still requires it. Everything the services still hold is recovered and need not be resent; a 400 missing_variables names exactly what to send here |

## Response 202

Default Response

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `deploymentId` | `string` | no |  |
| `deployment` | `object` | no | One server-side template deployment run and its progress. |
| `deployment.id` | `string` | no |  |
| `deployment.status` | `"running" \| "succeeded" \| "failed" \| "partial"` | no | partial = some services came up healthy, others failed — created resources are kept either way |
| `deployment.step` | `"create_services" \| "write_variables" \| "deploy" \| "health_check"` | no | the pipeline step the run is currently on (or stopped at) |
| `deployment.templateCode` | `string` | no |  |
| `deployment.templateVersion` | `string` | no |  |
| `deployment.projectId` | `string` | no |  |
| `deployment.branchId` | `string` | no |  |
| `deployment.region` | `string` | no | InstaCloud region slug every service of this deployment was created in. Deployments recorded before regions were recorded read as the platform default. |
| `deployment.services` | `object[]` | no |  |
| `deployment.services.name` | `string` | no | the service's actual name on the branch, which is the manifest's name only for the first copy — a second deployment of the same template into the same branch names its services <name>-2 and leaves the first copy alone |
| `deployment.services.serviceId` | `string` | no |  |
| `deployment.services.url` | `string` | no |  |
| `deployment.services.state` | `"pending" \| "created" \| "deployed" \| "healthy" \| "failed"` | no |  |
| `deployment.services.skipped` | `boolean` | no | an upgrade stepped over this service because the user had deleted it — the run never touched it, serviceId points at the deleted row, and state stays pending however the deployment ends. Not "still in progress" |
| `deployment.error` | `string` | no |  |
| `deployment.logsTail` | `string` | no | container log tail captured when a service never became healthy |
| `deployment.rollbackTo` | `object` | no | the version one step back, present only when this deployment was produced by an upgrade: what POST .../rollback would return the instance to. Absent on a first deploy, once the predecessor is gone, and on a deployment a ROLLBACK produced — that row's step back is the newer version it just left, which is offered as the update, not as a way back. Present is not a promise it will succeed — a version whose manifest is no longer recorded, or was republished with different content, still refuses at click time |
| `deployment.rollbackTo.version` | `string` | yes |  |
| `deployment.createdAt` | `string` | no |  |
| `status` | `"approval_required"` | no |  |
| `approvalId` | `string` | no |  |
| `action` | `string` | no |  |
| `actions` | `string[]` | no |  |
| `message` | `string` | no |  |
| `url` | `string` | no |  |
| `nextActions` | `object[]` | no |  |
| `nextActions.op` | `string` | yes | Neutral logical action id, e.g. "service.add" — NOT an operationId or a CLI/MCP tool name; each client maps it to its own surface. |
| `nextActions.reason` | `string` | yes | Natural-language, human/LLM-facing "why do this now". |
| `nextActions.args` | `object` | no | Suggested, flat named arguments; "<placeholder>"s where a value is unknown. |
| `nextActions.gated` | `boolean` | no | True if the action passes a governance gate. |

## Response 400

Default Response

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | `string` | yes |  |
| `missing` | `object[]` | no |  |
| `missing.name` | `string` | yes |  |
| `missing.key` | `string` | yes |  |
| `missing.description` | `string` | no |  |

## Response 403

Default Response

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | `string` | yes |  |

## Response 404

Default Response

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | `string` | yes |  |

## Response 409

code template_no_step_back: this instance was not upgraded from anything, or it is itself the result of a rollback and the version it came from is the newer one. code template_version_not_recorded: the manifest for that version is no longer recorded. code template_version_content_changed: that version was republished with different content after this instance ran it, so the recorded manifest is not what it was running. code template_no_services: the deployment owns nothing to roll back. code template_superseded: this instance already moved off this deployment — the message names the one to act on instead.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | `string` | yes |  |
| `code` | `string` | no | stable machine-readable reason, e.g. private_lane_disabled, private_lane_unavailable_in_region, public_access_closed, credential_change_in_progress |
