{"record":{"id":"899b4b6e04dcc0b1","repo":"bitwarden/server","slug":"provider-must-be-of-type-reseller-in-order-to-assi","errorCode":null,"errorMessage":"Provider must be of type Reseller in order to assign Organizations to it.","messagePattern":"Provider must be of type Reseller in order to assign Organizations to it\\.","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"bitwarden_license/src/Commercial.Core/AdminConsole/Services/ProviderService.cs","lineNumber":482,"sourceCode":"        await _organizationRepository.ReplaceAsync(organization);\n\n        if (!string.IsNullOrEmpty(organization.GatewayCustomerId))\n        {\n            await _stripeAdapter.UpdateCustomerAsync(organization.GatewayCustomerId, new CustomerUpdateOptions\n            {\n                Email = provider.BillingEmail\n            });\n        }\n\n        await _eventService.LogProviderOrganizationEventAsync(providerOrganization, EventType.ProviderOrganization_Added);\n    }\n\n    public async Task AddOrganizationsToReseller(Guid providerId, IEnumerable<Guid> organizationIds)\n    {\n        var provider = await _providerRepository.GetByIdAsync(providerId);\n        if (provider.Type != ProviderType.Reseller)\n        {\n            throw new BadRequestException(\"Provider must be of type Reseller in order to assign Organizations to it.\");\n        }\n\n        var orgIdsList = organizationIds.ToList();\n        var existingProviderOrganizationsCount = await _providerOrganizationRepository.GetCountByOrganizationIdsAsync(orgIdsList);\n        if (existingProviderOrganizationsCount > 0)\n        {\n            throw new BadRequestException(\"Organizations must not be assigned to any Provider.\");\n        }\n\n        var providerOrganizationsToInsert = orgIdsList.Select(orgId => new ProviderOrganization { ProviderId = providerId, OrganizationId = orgId });\n        var insertedProviderOrganizations = await _providerOrganizationRepository.CreateManyAsync(providerOrganizationsToInsert);\n\n        await _eventService.LogProviderOrganizationEventsAsync(insertedProviderOrganizations.Select(ipo => (ipo, EventType.ProviderOrganization_Added, (DateTime?)null)));\n    }\n\n    private async Task ApplyProviderPriceRateAsync(Organization organization, Provider provider)\n    {\n        // if a provider was created before Nov 6, 2023.If true, the organization plan assigned to that provider is updated to a 2020 plan.","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/bitwarden/server/blob/e93b962371d80964556f5590c6615f5160a437a1/bitwarden_license/src/Commercial.Core/AdminConsole/Services/ProviderService.cs#L464-L500","documentation":"Thrown by ProviderService.AddOrganizationsToReseller when the provider's Type is not ProviderType.Reseller. Only Reseller providers can have organizations bulk-assigned through this method. BadRequestException (HTTP 400).","triggerScenarios":"Calling AddOrganizationsToReseller(providerId, organizationIds) against an MSP or BusinessUnit provider, or a provider whose Type field is misconfigured.","commonSituations":"A provider record created with the wrong type; client hardcoding the reseller-add endpoint for all provider types; a seed/test fixture that defaulted Type to Msp.","solutions":["Verify provider.Type == ProviderType.Reseller before calling AddOrganizationsToReseller.","If the provider should be a reseller, correct the provider Type in the data/admin flow first.","For MSP/BusinessUnit providers use AddOrganization (single) instead of AddOrganizationsToReseller."],"exampleFix":"// before\nawait providerService.AddOrganizationsToReseller(providerId, orgIds);\n\n// after\nif (provider.Type != ProviderType.Reseller)\n{\n    throw new InvalidOperationException(\"Use AddOrganization for non-reseller providers.\");\n}\nawait providerService.AddOrganizationsToReseller(providerId, orgIds);","handlingStrategy":"type-guard","validationCode":"if (provider.Type != ProviderType.Reseller) throw new InvalidOperationException(\"Not a reseller.\");","typeGuard":"static bool IsReseller(Provider p) => p.Type == ProviderType.Reseller;","tryCatchPattern":null,"preventionTips":["Branch on provider.Type before choosing AddOrganization vs AddOrganizationsToReseller.","Validate provider type at the API entry point."],"tags":["provider","reseller","type-guard","bad-request"],"backgroundTag":null,"analyzedSha":"e93b962371d80964556f5590c6615f5160a437a1","analyzedAt":"2026-08-13T14:22:19.382Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}