# Link a Telegram chat to a project

`POST /api/v1/projects/{projectId}/telegram/link-codes`

A one-time code that links a Telegram chat to the project's alerts: open `startUrl` for a private chat or `startGroupUrl` for a group. Needs the project admin role.

Sign-in: a dashboard session only. API tokens and OAuth sign-ins get `403 token.not_allowed`.

Section: Telegram. Operation id in openapi.json: `create_project_telegram_link_code`.

## Parameters

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

## Responses

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

### 201

The code and its links.

`application/json`: LinkCode

| Field | Type | Required | Description |
|---|---|---|---|
| `botUsername` | string \| null | no | The bot's username without `@` (`MONITORLY_TELEGRAM_BOT_USERNAME`); null when not configured. |
| `code` | string | yes | Send `/start <code>` to the bot in the chat to link. 43 characters of `A-Z a-z 0-9 _ -`, so it is also a valid `start` / `startgroup` parameter of a Telegram deep link. |
| `expiresAt` | string | yes |  |
| `startGroupUrl` | string \| null | no | `https://t.me/<bot>?startgroup=<code>`: Telegram asks which group to add the bot to; the group then sends `/start@<bot> <code>`. Null without a bot username. |
| `startUrl` | string \| null | no | `https://t.me/<bot>?start=<code>`: opens the private chat with the bot, which then receives `/start <code>`. Null without a bot username. |

### 400

Bad Request.

- `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.not_allowed`: this operation needs a signed-in session; tokens cannot call 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

### 429

Too Many Requests.

- `session.rate_limited`: more than 5 changes a second from your sessions

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