# Create a maintenance window

`POST /api/v1/projects/{projectId}/maintenance`

Creates a one-time or weekly window. During a window its checks are in `MAINTENANCE`: they keep running, open no incidents and send no alerts. Needs the editor role.

Sign-in: a dashboard session, an API token with `maintenance:write` or the `monitorly` CLI's sign-in with `maintenance:write`.

Section: Maintenance windows. Operation id in openapi.json: `create_maintenance`.

## Parameters

| Name | In | Required | Type | Description |
|---|---|---|---|---|
| `projectId` | path | yes | string (uuid) | The project's id. |
| `Idempotency-Key` | header | no | string | Any 1–255 characters, for example a UUID per intended action. A retry with the same key and the same request answers the stored response and creates nothing again; the same key with another request answers `422 request.idempotency_key_reused`. Keys are kept for 24 hours. |

## Request body

Required: yes.

`application/json`: MaintenanceInput

| Field | Type | Required | Description |
|---|---|---|---|
| `checkIds` | array of string (uuid) | yes |  |
| `schedule` | ScheduleDto | yes |  |
| `timezone` | string \| null | no | IANA zone; the workspace's when absent. |
| `title` | string | yes |  |

Example:

```json
{
  "checkIds": [
    "CHECK_ID"
  ],
  "schedule": {
    "endsAt": "2026-12-01T23:00:00Z",
    "kind": "once",
    "startsAt": "2026-12-01T22:00:00Z"
  },
  "timezone": "Europe/Berlin",
  "title": "Database upgrade"
}
```

## Responses

Errors are `application/problem+json` (`Problem`); branch on `type`.

### 201

The window.

`application/json`: MaintenanceView

| Field | Type | Required | Description |
|---|---|---|---|
| `checkIds` | array of string (uuid) | yes |  |
| `createdAt` | string | yes |  |
| `id` | string (uuid) | yes |  |
| `managedBy` | ManagedBy | no | `config` when a config apply manages the window, `ui` otherwise. Always sent; optional in the schema because it was added after the first clients. |
| `projectId` | string (uuid) | yes |  |
| `ref` | string \| null | no | The window's key in a config file; null until a config apply creates or adopts it. Always sent; optional in the schema because it was added after the first clients. |
| `schedule` | ScheduleDto | yes |  |
| `timezone` | string | yes |  |
| `title` | string | yes |  |
| `upcoming` | array of OccurrenceView | yes | The running occurrence first (if any), then the next ones; empty once a one-off window is over. |

Example:

```json
{
  "checkIds": [
    "CHECK_ID"
  ],
  "createdAt": "2026-11-27T15:20:00Z",
  "id": "WINDOW_ID",
  "managedBy": "ui",
  "projectId": "PROJECT_ID",
  "schedule": {
    "endsAt": "2026-12-01T23:00:00Z",
    "kind": "once",
    "startsAt": "2026-12-01T22:00:00Z"
  },
  "timezone": "Europe/Berlin",
  "title": "Database upgrade",
  "upcoming": [
    {
      "active": false,
      "endsAt": "2026-12-01T23:00:00Z",
      "localEndsAt": "2026-12-02T00:00:00",
      "localStartsAt": "2026-12-01T23:00:00",
      "startsAt": "2026-12-01T22:00:00Z"
    }
  ]
}
```

### 400

Bad Request.

- `request.malformed`: the body or a parameter is not of the expected shape
- `request.idempotency_key_invalid`: the key is empty or longer than 255 characters
- `auth.credentials_conflict`: the request carries both a session cookie and a token

### 401

Unauthorized.

- `auth.unauthenticated`, `auth.session_expired`: no session, or it ended
- `token.invalid`: the token is malformed, unknown, revoked or expired, or its creator left the workspace

### 403

Forbidden.

- `auth.forbidden`: your role is too low for this
- `token.scope_missing`: the token lacks the scope this needs; `detail` names it
- `request.origin_mismatch`, `request.header_required`: a changing request with a session comes from another site or lacks `X-Monitorly-Request: 1`

### 404

Not Found.

- `request.not_found`: it does not exist, or you cannot see it

### 413

Payload Too Large.

- `request.too_large`: the body is larger than 256 KiB

### 422

Unprocessable Entity.

- `field.required`, `field.too_long`, `field.invalid`: a field breaks a rule; `errors` points at it
- `maintenance.ends_before_start`: window end is not later than its start
- `maintenance.ends_in_past`: one-time window has already ended
- `maintenance.weekdays_invalid`: weekdays are empty, repeated, or outside 1–7
- `maintenance.duration_out_of_range`: weekly window duration is outside 1–10080 minutes
- `maintenance.check_not_in_project`: check is not from the window's project or is repeated

### 429

Too Many Requests.

- `token.rate_limited`: more than 10 requests a second with this token
- `session.rate_limited`: more than 5 changes a second from your sessions
- `token.create_limited`: more than 30 resources created within an hour from one token; `Retry-After` in seconds

Schemas named above are listed with their fields in [the schema list](https://docs.monitorly.cloud/api/reference/schemas.md).
