# Sign in

`POST /api/v1/auth/login`

Signs in with email and password and sets the session cookie. An account with two-factor sign-in gets a pending session for the second step, [Sign in with a code](https://docs.monitorly.cloud/api/reference/operations/login-totp.md).

Sign-in: none.

Section: Sign-in and account. Operation id in openapi.json: `login`.

## Request body

Required: yes.

`application/json`: LoginInput

| Field | Type | Required | Description |
|---|---|---|---|
| `email` | string | yes |  |
| `password` | string | yes |  |

## Responses

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

### 200

Signed in, or a second step is needed.

`application/json`: LoginResult

| Field | Type | Required | Description |
|---|---|---|---|
| `session` | SessionView \| null | no |  |
| `totpRequired` | boolean | yes | The password was right and the account has TOTP: send the code to `/api/v1/auth/login/totp`. |

### 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.

- `token.invalid`: the token is malformed, unknown, revoked or expired, or its creator left the workspace
- `auth.invalid_credentials`: wrong email or password

### 403

Forbidden.

- `request.origin_mismatch`, `request.header_required`: a changing request with a session comes from another site or lacks `X-Monitorly-Request: 1`
- `auth.account_unavailable`: the account cannot sign in: it is blocked or was deleted. A deleted account can be restored by support within 30 days

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

### 429

Too Many Requests.

- `auth.rate_limited`: too many failed attempts; `Retry-After` in seconds

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