bitwarden/server · error · BadRequestException

Unknown Organization connection Type: {model.Type}

Error message

Unknown Organization connection Type: {model.Type}

What it means

Thrown by the default case of the Type switch in CreateConnection (POST /organizations/connections) when model.Type is neither CloudBillingSync(1) nor Scim(2). Because OrganizationConnectionType is a byte enum, ASP.NET model binding can accept raw integer values that fall outside the defined members, so an out-of-range int reaches this branch. Maps to HTTP 400.

Source

Thrown at src/Api/AdminConsole/Controllers/OrganizationConnectionsController.cs:74

    {
        if (!await HasPermissionAsync(model.OrganizationId, model.Type))
        {
            throw new BadRequestException($"You do not have permission to create a connection of type {model.Type}.");
        }

        if (await HasConnectionTypeAsync(model, null, model.Type))
        {
            throw new BadRequestException($"The requested organization already has a connection of type {model.Type}. Only one of each connection type may exist per organization.");
        }

        switch (model.Type)
        {
            case OrganizationConnectionType.CloudBillingSync:
                return await CreateOrUpdateOrganizationConnectionAsync<BillingSyncConfig>(null, model, ValidateBillingSyncConfig);
            case OrganizationConnectionType.Scim:
                return await CreateOrUpdateOrganizationConnectionAsync<ScimConfig>(null, model);
            default:
                throw new BadRequestException($"Unknown Organization connection Type: {model.Type}");
        }
    }

    [HttpPut("{organizationConnectionId}")]
    public async Task<OrganizationConnectionResponseModel> UpdateConnection(Guid organizationConnectionId, [FromBody] OrganizationConnectionRequestModel model)
    {
        if (model == null)
        {
            throw new NotFoundException();
        }

        var existingOrganizationConnection = await _organizationConnectionRepository.GetByIdOrganizationIdAsync(organizationConnectionId, model.OrganizationId);
        if (existingOrganizationConnection == null)
        {
            throw new NotFoundException();
        }

        if (!await HasPermissionAsync(existingOrganizationConnection.OrganizationId, existingOrganizationConnection.Type))

View on GitHub (pinned to e93b962371)

Solutions

  1. Set model.Type to one of the documented values: 1 (CloudBillingSync) or 2 (Scim).
  2. If you intended a newer connection type, upgrade the server to the version that defines it.
  3. Validate the Type on the client against the OrganizationConnectionType enum before sending the request.
  4. Check for typos or integer-vs-string serialization mismatches in the request payload.

Example fix

// before
var model = new { type = 0, organizationId = orgId, config = ... };
// after
var model = new { type = 2 /* Scim */, organizationId = orgId, config = ... };
Defensive patterns

Strategy: type-guard

Validate before calling

var validTypes = new[] { OrganizationConnectionType.CloudBillingSync, OrganizationConnectionType.Scim };
if (!validTypes.Contains(model.Type))
    throw new ArgumentOutOfRangeException(nameof(model.Type), "Type must be CloudBillingSync(1) or Scim(2).");

Type guard

static bool IsKnownConnectionType(OrganizationConnectionType t) =>
    Enum.IsDefined(typeof(OrganizationConnectionType), t) &&
    t is OrganizationConnectionType.CloudBillingSync or OrganizationConnectionType.Scim;

Prevention

When it happens

Trigger: POST /organizations/connections with type set to 0, 3, or any integer not equal to 1 (CloudBillingSync) or 2 (Scim); a client sending a string that ASP.NET coerces to an undefined enum member; a forward-compatibility mismatch where the client targets an enum value added in a newer server version than the one deployed.

Common situations: Client and server version skew (client knows a new connection type the running server does not); hand-crafted JSON with a typo'd or zero-defaulted type field; an integration test using an arbitrary enum value without checking the deployed server's known set.

Related errors


AI-assisted analysis of bitwarden/server@e93b962371 (2026-08-13). Data as JSON: /api/errors/5078762f5e04ddf5. Report an issue: GitHub.