# Add a workspace channel

`POST /api/v1/workspaces/{workspaceId}/alert-channels`

Adds a channel for the workspace's service notifications, which projects may then pick for their alerts. Workspace owner or admin.

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

Section: Alert channels. Operation id in openapi.json: `create_workspace_alert_channel`.

## Parameters

| Name | In | Required | Type | Description |
|---|---|---|---|---|
| `workspaceId` | path | yes | string (uuid) | The workspace's id. |

## Request body

Required: yes.

`application/json`: AlertChannelInput

| Field | Type | Required | Description |
|---|---|---|---|
| `appToken` | string \| null | no | `pushover`: the 30-character API token of the customer's own Pushover application. |
| `email` | string \| null | no | `email`: the address that receives alerts once it confirms. |
| `kind` | ChannelKind | yes | Any kind but `telegram` (Telegram chats are linked with a link code). Each kind takes only its own fields. |
| `name` | string \| null | no | 1–100 characters; absent: the address, the provider's name (`Slack`, `Discord`, …) or the URL's host. |
| `routingKey` | string \| null | no | `pagerduty`: the 32-character integration key of an Events API v2 integration. |
| `serviceNotifications` | boolean \| null | no | A channel added for the workspace: the workspace's service notifications go to it (default true). Not accepted when the channel is added in a project. |
| `token` | string \| null | no | `ntfy`, optional: an access token for a protected topic, sent as `Authorization: Bearer`. |
| `topic` | string \| null | no | `ntfy`: the topic, 1–64 letters, digits, `-` and `_`. |
| `url` | string \| null | no | `slack`: the incoming webhook URL (`https://hooks.slack.com/services/…`); `discord`: `https://discord.com/api/webhooks/<id>/<token>`; `teams`: the URL of a Workflows "When a Teams webhook request is received" trigger; `google_chat`: `https://chat.googleapis.com/v1/spaces/<space>/messages?key=…&token=…`; `webhook` and `mattermost`: an https URL; `ntfy`: the server, default `https://ntfy.sh`. Not taken by `pagerduty` and `pushover`, whose address is fixed. |
| `userKey` | string \| null | no | `pushover`: the 30-character user or group key. |

## Responses

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

### 201

The channel; `secret` only for a webhook.

`application/json`: CreatedAlertChannel

| Field | Type | Required | Description |
|---|---|---|---|
| `channel` | AlertChannelView | yes |  |
| `signingSecret` | string \| null | no | Webhooks only, answered only here: the key of the `Monitorly-Signature` HMAC (see the webhooks documentation). |

### 400

Bad Request.

- `request.malformed`: the body or a parameter is not of the expected shape
- `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

### 409

Conflict.

- `alert_channel.duplicate`: the workspace already has a channel with this email, URL, ntfy topic, PagerDuty key or Pushover keys
- `alert_channel.limit_reached`: the workspace reached the ceiling of 1000 channels
- `quota.channels_reached`: the workspace has as many alert channels as its plan allows (Telegram chats are not counted)

### 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
- `alert_channel.url_not_allowed`: the address is not allowed: not `https`, credentials in the address, the host is an internal address, or the URL is not on the provider's host and path (Slack, Discord, Microsoft Teams, Google Chat) or not its fixed address (PagerDuty, Pushover); `detail` gives the expected form

### 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
- `alert_channel.mail_limited`: the address got 3 confirmation emails today, or the workspace 20; nothing was sent or created; wait `Retry-After` seconds
- `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).
