{"record":{"id":"892d4beced7dfb44","repo":"bitwarden/server","slug":"the-connection-type-cannot-be-changed","errorCode":null,"errorMessage":"The connection type cannot be changed.","messagePattern":"The connection type cannot be changed\\.","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"src/Api/AdminConsole/Controllers/OrganizationConnectionsController.cs","lineNumber":99,"sourceCode":"        if (model == null)\n        {\n            throw new NotFoundException();\n        }\n\n        var existingOrganizationConnection = await _organizationConnectionRepository.GetByIdOrganizationIdAsync(organizationConnectionId, model.OrganizationId);\n        if (existingOrganizationConnection == null)\n        {\n            throw new NotFoundException();\n        }\n\n        if (!await HasPermissionAsync(existingOrganizationConnection.OrganizationId, existingOrganizationConnection.Type))\n        {\n            throw new BadRequestException(\"You do not have permission to update this connection.\");\n        }\n\n        if (model.Type != existingOrganizationConnection.Type)\n        {\n            throw new BadRequestException(\"The connection type cannot be changed.\");\n        }\n\n        if (await HasConnectionTypeAsync(model, organizationConnectionId, model.Type))\n        {\n            throw new BadRequestException($\"The requested organization already has a connection of type {model.Type}. Only one of each connection type may exist per organization.\");\n        }\n\n        switch (model.Type)\n        {\n            case OrganizationConnectionType.CloudBillingSync:\n                return await CreateOrUpdateOrganizationConnectionAsync<BillingSyncConfig>(organizationConnectionId, model, ValidateBillingSyncConfig);\n            case OrganizationConnectionType.Scim:\n                return await CreateOrUpdateOrganizationConnectionAsync<ScimConfig>(organizationConnectionId, model);\n            default:\n                throw new BadRequestException($\"Unknown Organization connection Type: {model.Type}\");\n        }\n    }\n","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/bitwarden/server/blob/e93b962371d80964556f5590c6615f5160a437a1/src/Api/AdminConsole/Controllers/OrganizationConnectionsController.cs#L81-L117","documentation":"Thrown by UpdateConnection (PUT /organizations/connections/{id}) when the request body's Type differs from the persisted connection's Type. Connection type is immutable after creation; the API rejects any attempt to morph a CloudBillingSync connection into Scim or vice versa. To change type you must delete and recreate. Maps to HTTP 400.","triggerScenarios":"PUT with model.Type set to a value other than existingOrganizationConnection.Type — e.g., GETting a CloudBillingSync connection then PUTting the same id back with type=Scim.","commonSituations":"A generic update form that always sends the full object including a default or user-selected type; a client that mislabels the type field; copy-paste of a request body from one connection type to another's id.","solutions":["Echo back the exact Type from the GET response in the PUT body (do not let the user or UI change it).","If you genuinely need a different type, DELETE the existing connection and POST a new one of the desired type.","Mark the Type field read-only in the edit UI.","Add a client-side assert that model.Type equals the fetched connection's Type before submitting."],"exampleFix":"// before\nvar body = new { type = OrganizationConnectionType.Scim, ... };\nawait client.PutAsync($\"organizations/connections/{billingSyncId}\", body);\n// after\nvar body = new { type = existing.Type /* CloudBillingSync */, ... };\nawait client.PutAsync($\"organizations/connections/{existing.Id}\", body);","handlingStrategy":"validation","validationCode":"var existing = await GetConnectionAsync(connectionId);\nif (model.Type != existing.Type)\n    throw new InvalidOperationException(\"Type is immutable; delete and recreate to change type.\");\nmodel.Type = existing.Type; // echo stored value back in PUT","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat Type as read-only in update forms; populate it from the GET response.","Add a client-side assert that body.Type == fetched.Type before PUT.","To change type, DELETE then POST a new connection."],"tags":["immutable-field","organization-connections","validation","http-400"],"backgroundTag":null,"analyzedSha":"e93b962371d80964556f5590c6615f5160a437a1","analyzedAt":"2026-08-13T14:22:19.382Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}