---
title: "Cancel a deployment"
url: https://docs.corefinity.com/api/reference/enterprise/cancel-environment-deployment
type: endpoint
last_updated: 2026-11-13
feature: enterprise-deployments
related:
  - https://docs.corefinity.com/guides/corestack-enterprise/deployments-and-pipelines.md
---
# Cancel a deployment

Cancels a deployment that has not finished: one that is scheduled, queued, waiting to be deployed or running,
which stops at its current step. Your role needs the Cancel Deployments permission. A deployment of a
CoreStack or CoreCluster site is stopped from the site instead.

```http
POST /api/environments/{environment}/deployments/{deployment}/cancel
```

- Scope: `write`
- Also needs `deploy` when Always
- Rate limit: 60 a minute
- Try it in the console: off. It can need a stronger scope, depending on what you send. Copy the request and run it yourself when you are sure.

## Path parameters

- `environment` (integer, required): The id of a CoreStack Enterprise environment. Not the same number as a site row id.
- `deployment` (integer, required): The id of a deployment of the environment. A deployment of another environment is not found.

## Header parameters

- `Idempotency-Key` (string): A UUID you choose, to make the request safe to repeat. Only the endpoints that list this header read it; each says what a repeated key answers.

## Body

- `expected_action_id` (integer or null): The `attempt_id` you read. If the deployment has moved on since, the answer is `409` `stale` and nothing happens. Left out, the deployment's current run is used.

## Request

### curl

```bash
curl -X POST https://manage.corefinity.com/api/environments/1311/deployments/4410/cancel \
  -H "Authorization: Bearer $COREFINITY_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{}'
```

### PHP

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

$response = Http::withToken(env('COREFINITY_TOKEN'))
    ->acceptJson()
    ->post('https://manage.corefinity.com/api/environments/1311/deployments/4410/cancel', (object) []);

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

### Node

```javascript
const res = await fetch('https://manage.corefinity.com/api/environments/1311/deployments/4410/cancel', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.COREFINITY_TOKEN}`,
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({}),
});

// 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/environments/1311/deployments/4410/cancel",
    headers={
        "Authorization": f"Bearer {os.environ['COREFINITY_TOKEN']}",
        "Accept": "application/json",
    },
    json={},
)

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

## Responses

### 200 The deployment, cancelled. `replayed` is true when the `Idempotency-Key` was used before.

```json
{
  "deployment": {
    "artifact_pruned_at": null,
    "attempt_id": 190419,
    "environment_deployment_pipeline_id": "2210",
    "environment_id": "1311",
    "error": null,
    "git_author": null,
    "git_commit": "5c1d0e9a7b3f42d68a0c9e1f7b2d4a6c8e0f1a3b",
    "git_commit_url": null,
    "git_merge_request": null,
    "hash": "71a7eaca-89a7-4a5f-a7af-17d38ca685e6",
    "id": "4410",
    "name": "Release 2026.10.4",
    "notes": null,
    "status": "5",
    "status_description": "Cancelled"
  },
  "replayed": false
}
```

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

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

### 403 The token lacks the `write` scope or the `deploy` ability (`scope_required`; `scope` names which), or your role lacks the permission the action needs (`forbidden`, with `permission`), or you may not take the action on this deployment or deploy to its site (`forbidden`).

```json
{
  "code": "forbidden",
  "message": "You may not retry this deployment.",
  "reason": "forbidden",
  "result": "forbidden"
}
```

### 404 The id does not exist, or it is something you cannot see. Both answer the same body.

```json
{
  "message": "Not found."
}
```

### 409 Nothing was cancelled. `reason` says why: `stale` (the deployment has finished, or moved on since you read it), `busy` (the same request is still being applied) or `conflict` (the `Idempotency-Key` belongs to another request, or the environment is a CoreStack or CoreCluster site's).

```json
{
  "code": "stale",
  "message": "Only a deployment that has not finished can be cancelled.",
  "reason": "stale",
  "result": "stale_attempt"
}
```

### 422 A field is wrong (`invalid`), or the `Idempotency-Key` header is not a UUID (a message only).

```json
{
  "code": "invalid",
  "errors": {
    "expected_action_id": [
      "The expected action id must be an integer."
    ]
  },
  "field": "expected_action_id",
  "message": "The expected action id must be an integer.",
  "reason": "invalid"
}
```

### 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
}
```

### 500 The action could not be completed (`internal_error`, with `result` `failed`). Read the deployment, then try again.

```json
{
  "code": "internal_error",
  "message": "The cancellation could not be completed. Try again in a moment.",
  "reason": "internal_error",
  "result": "failed"
}
```

## If it is refused

| Status | Reason | What to do |
|---|---|---|
| 401 |  | Send a valid token as `Authorization: Bearer <token>`. |
| 403 | `forbidden` | The person is not allowed to do this. |
| 403 | `scope_required` | Use a token with the scope named in `scope`. |
| 404 |  | Check the id. You see only what your account can reach. |
| 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 | `conflict` | The action conflicts with the object's present state. Read the message. |
| 422 | `invalid` | Fix the field named in `field`; `errors` says why. |
| 429 | `rate_limited` | Wait for the seconds in `Retry-After`. |
| 500 | `internal_error` | Something went wrong on our side. Quote the trace id to support. |

## The same task elsewhere

- Guide: [Deployments and pipelines](https://docs.corefinity.com/guides/corestack-enterprise/deployments-and-pipelines.md)
