# Delete a plan

`DELETE /api/v1/plans/{plan}`

Its backups are kept and stay browsable as orphans, unless `delete_backups` is true, which queues their removal from storage. The answer counts the backups affected.

## Path Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| plan | integer | yes | The ID of the plan. Example: `41`. |

## Query Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| delete_backups | boolean | no | True also removes the plan's backups from storage (queued). Absent or false keeps them, browsable as orphaned backups. Example: `false`. |

## Response

### 200

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| data | object | yes |  |
| data.artifacts_orphaned | integer | yes | How many backup artifacts were left without their plan or server. |
| data.total_bytes | integer | yes | The combined size of those artifacts, in bytes. |
| data.purge_queued | boolean | yes | Whether a job was queued to delete the artifacts from storage; false when the backups were kept. |

### 401

The request carries no valid token: the `Authorization: Bearer` header is missing, or its token is unknown, revoked or past its expiry date. Send a current personal access token.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| message | string | yes | Always `Unauthenticated.`. |

### 403

The token may not do this. The `message` says why: `This token lacks the required ability.` (a `read` token), `Your role does not permit this action.` (its owner is not an Admin or Operator in the client), `This account is disabled.`, `This token is not bound to a client you belong to.`, or `Client suspended`.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| message | string | yes | What went wrong. |

### 404

Not found

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| message | string | yes | What went wrong. |

### 422

The body or the query is invalid. `message` names the first problem and `errors` lists every problem by field.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| message | string | yes | The first problem, and how many more there are. |
| errors | object | yes | Every problem, by field. |

### 429

More than 120 requests a minute for this user. Wait the seconds in `Retry-After`, then retry.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| message | string | yes | What went wrong. |

## Request example

```bash
curl -X DELETE 'https://app.clokeep.com/api/v1/plans/41' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Accept: application/json'
```

## Response example (200)

```json
{
  "data": {
    "artifacts_orphaned": 4,
    "total_bytes": 5368709120,
    "purge_queued": false
  }
}
```

## Response example (401)

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

## Response example (403)

```json
{
  "message": "This token lacks the required ability."
}
```

## Response example (404)

```json
{
  "message": "No query results for model [App\\Models\\Plan] 41"
}
```

## Response example (422)

```json
{
  "message": "The delete backups field must be true or false.",
  "errors": {
    "delete_backups": [
      "The delete backups field must be true or false."
    ]
  }
}
```

## Response example (429)

```json
{
  "message": "Too Many Attempts."
}
```
