# Invitations API

## GET /api/v1/admin/invitations

`GET /api/v1/admin/invitations` · operation `listInvitations`

Global admin lists console user invitations (pending by default, status=all includes accepted, revoked and expired; at most 200). Requires console_users and user_invitations. Tokens are never listed. With organization_admins (T168) an organization admin lists only its organization's invitations, and revokes only those.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `status` | query | string, one of `"pending"`, `"all"`, default `"pending"` | pending (default) lists open invitations; all includes accepted, revoked and expired ones. |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Invitations wrapped in data | — |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |


## POST /api/v1/admin/invitations

`POST /api/v1/admin/invitations` · operation `createInvitation`

Global admin invites a named console user with the same role, team and membership rules as direct creation. Returns a single-use invitation token once (Cache-Control no-store) and an accept_path that carries it in the URL fragment. Only the token hash is stored; the invitee receives their own console credential on acceptance, which the administrator never sees.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: object
  - `name` (string, required, min length 2, max length 128)
  - `role` (string, required, one of `"admin"`, `"viewer"`, `"operator"`, `"user"`, `"team_viewer"`, `"team_admin"`)
  - `team_ids` (array of string, max items 20)
  - `memberships` (array of [Membership](/docs/api/schemas/m/#membership), max items 20)
  - `expires_in_hours` (integer, min 1, max 168) — Required unless invitation_email is on, which defaults it to default_expiry_hours (72).
  - `email` (string (email), max length 320) — T168 (invitation_email): send the link to this one address over SMTP. The response then carries no token or accept_path; a refused delivery revokes the invitation (502).
  - `organization_id` (string) — T168 (organization_admins): a global admin places the invited user in this organization (team-scoped roles, that organization's teams). An organization admin's invitations always join its own organization; naming another one answers 403 organization_forbidden. Not accepted in bulk rows.

**Responses**

| Status | Description | Body |
|---|---|---|
| `201` | invitation, token (once) and accept_path; with email, the invitation and emailed true, without the token. invitation.sso_only is true when console OIDC or SAML login is configured (invitation_email): the link then only pre-provisions the user for SSO sign-in. | — |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `409` | invitation_email_not_configured: e-mail requested without delivery settings | — |
| `502` | invitation_email_failed: the SMTP delivery failed with the named class; the invitation was revoked | — |


## DELETE /api/v1/admin/invitations/{id}

`DELETE /api/v1/admin/invitations/{id}` · operation `revokeInvitation`

Revoke a pending invitation; its token can no longer be accepted.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required, pattern `^inv_[a-f0-9]{24}$` |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Responses**

| Status | Description | Body |
|---|---|---|
| `204` | Revoked | — |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Pending invitation not found or feature disabled | — |


## POST /api/v1/admin/invitations/accept

`POST /api/v1/admin/invitations/accept` · operation `acceptInvitation`

Public, same-origin and bounded like login. Consumes a pending invitation and creates the console user in one transaction, returning that user's console token once. Unknown, used, revoked and expired tokens all return 410. The invited role and teams are re-checked at acceptance; a refused acceptance keeps the invitation pending.

**Authentication:** `bearerAuth`

**Request body** (required)

- `application/json`: object
  - `token` (string, required, pattern `^gw_invite_[a-f0-9]{64}$`, write-only)

**Responses**

| Status | Description | Body |
|---|---|---|
| `201` | user and secret (once); Cache-Control no-store | — |
| `202` | T168: an SSO-only invitation. No user or token is created; a 15-minute HttpOnly, Secure, SameSite=None claim cookie binds this browser to the invitation, and the next console OIDC or SAML sign-in creates the invited user and links that identity. Body {sso_required: true, expires_in_seconds}. | — |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `409` | Invited role disabled or team no longer active | — |
| `410` | Invitation invalid, used, revoked or expired | — |


## GET /api/v1/admin/invitation-email

`GET /api/v1/admin/invitation-email` · operation `getInvitationEmail`

T168 (invitation_email). Global admin reads the effective SMTP delivery settings, their source (console, yaml or none), the YAML base, the boot-only network trust and whether invitations are SSO-only. The password is never returned, only password_configured.

**Authentication:** `adminSession`

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Settings | `application/json`: [InvitationEmailEnvelope](/docs/api/schemas/i/#invitationemailenvelope) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |


## PUT /api/v1/admin/invitation-email

`PUT /api/v1/admin/invitation-email` · operation `putInvitationEmail`

Replace the console override of the delivery settings with the current version (0 before the first write). An empty password keeps the stored one; clear_password removes it. The password is encrypted at rest and write-only. plaintext TLS requires a loopback host and the boot allowance admin.invitation_email.allow_plaintext_loopback. Audited as invitation_email.update.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: object
  - `version` (integer (int64), required, min 0)
  - `host` (string, required, max length 253)
  - `port` (integer, required, min 1, max 65535)
  - `tls` (string, one of `"starttls"`, `"implicit"`, `"plaintext"`, default `"starttls"`)
  - `username` (string, max length 256)
  - `password` (string, max length 1024, write-only)
  - `clear_password` (boolean)
  - `from` (string, required, max length 320)
  - `console_url` (string (uri), required, max length 512) — Absolute https origin (and optional path) of the console the link opens; never taken from the request.
  - `default_expiry_hours` (integer, min 0, max 168) — 0 means 72

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Saved; same shape as GET | `application/json`: [InvitationEmailEnvelope](/docs/api/schemas/i/#invitationemailenvelope) |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `409` | Stale version | — |


## DELETE /api/v1/admin/invitation-email

`DELETE /api/v1/admin/invitation-email` · operation `revertInvitationEmail`

Drop the console override (and its stored password) and follow the YAML base. Audited as invitation_email.revert.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: object
  - `version` (integer (int64), required, min 0)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Reverted; same shape as GET | `application/json`: [InvitationEmailEnvelope](/docs/api/schemas/i/#invitationemailenvelope) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | No override or feature disabled | — |
| `409` | Stale version | — |


## POST /api/v1/admin/invitation-email/test

`POST /api/v1/admin/invitation-email/test` · operation `testInvitationEmail`

Global admin sends one fixed message, with no link or secret, to one address using the saved effective settings.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: object
  - `to` (string (email), required, max length 320)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | {delivered: true} or {delivered: false, error_class: destination_rejected\|tls_required\|tls_failed\|settings_invalid\|upstream_rejected\|upstream_retryable\|timeout\|network} | — |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `409` | invitation_email_not_configured | — |

