{"record":{"id":"3da31ecf477b2d8c","repo":"bitwarden/server","slug":"result-aserror-message","errorCode":null,"errorMessage":"result.AsError.Message","messagePattern":"result\\.AsError\\.Message","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"bitwarden_license/src/Scim/Users/PostUserCommand.cs","lineNumber":85,"sourceCode":"            throw new ConflictException();\n        }\n\n        var organization = await organizationRepository.GetByIdAsync(organizationId);\n        if (organization == null)\n        {\n            throw new NotFoundException();\n        }\n\n        var result = await createStagedOrganizationUsersCommand.RunAsync(new CreateStagedOrganizationUsersRequest\n        {\n            Organization = organization,\n            Users = [new StagedOrganizationUserRequest { Email = email, ExternalId = externalId }],\n            EventSystemUser = EventSystemUser.SCIM\n        });\n\n        if (result.IsError)\n        {\n            throw new BadRequestException(result.AsError.Message);\n        }\n\n        // The command skips emails already present in the organization, so an empty result means the user\n        // was added by a concurrent request after the conflict check above.\n        var stagedUser = result.AsSuccess.FirstOrDefault() ?? throw new ConflictException();\n\n        return await organizationUserRepository.GetDetailsByIdAsync(stagedUser.Id);\n    }\n\n    private async Task<OrganizationUserUserDetails?> InviteScimOrganizationUserAsync_vNext(\n        ScimUserRequestModel model,\n        Guid organizationId,\n        ScimProviderType scimProvider)\n    {\n        var organization = await organizationRepository.GetByIdAsync(organizationId);\n\n        if (organization is null)\n        {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/bitwarden/server/blob/e93b962371d80964556f5590c6615f5160a437a1/bitwarden_license/src/Scim/Users/PostUserCommand.cs#L67-L103","documentation":"Thrown as a BadRequestException (HTTP 400) by PostUserCommand when the CreateStagedOrganizationUsersCommand returns an error result. The exception message is the dynamic result.AsError.Message from the staging command, so the specific cause varies. This is a passthrough of an internal creation-pipeline failure surfaced to the SCIM client as a 400.","triggerScenarios":"POST /v2/{organizationId}/Users where the internal staged-user creation pipeline rejects the request — e.g., invalid email format, organization not in a state that allows invites, seat limits exceeded, or other business-rule violations inside CreateStagedOrganizationUsersCommand.","commonSituations":"Organization has reached its seat limit. Email fails internal validation (malformed, blocked domain). Organization is disabled or not in a plan that supports SCIM. Internal command precondition fails.","solutions":["Read the dynamic message in the 400 response body — it contains the specific staging-command error.","Verify the organization has available seats and an active subscription.","Ensure the email is well-formed and not already present.","Check organization status (enabled, SCIM-capable plan) in the admin portal.","Retry after resolving the condition described in the error message."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var user = await scimClient.CreateUserAsync(orgId, model); }\ncatch (ScimException ex) when (ex.StatusCode == 400)\n{ // read ex.Detail for the specific staging-command error\n  logger.Error(\"User creation rejected: {Reason}\", ex.Detail);\n  // address the specific issue (seats, email, org state) before retry }","preventionTips":["Always read the dynamic error message — it identifies the specific staging failure.","Verify org has available seats and an active SCIM-capable plan before bulk-provisioning.","Validate email format client-side before sending.","Monitor org subscription state to catch seat-limit rejections early."],"tags":["scim","validation","users","http-400","create","dynamic-message"],"backgroundTag":null,"analyzedSha":"e93b962371d80964556f5590c6615f5160a437a1","analyzedAt":"2026-08-13T14:22:19.382Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}