RocketChat/Rocket.Chat · error · Meteor.Error

error-max-departments-number-reached

error-max-departments-number-reached

Error message

Maximum number of departments reached

What it means

Thrown by the `livechat:saveDepartment` Meteor method when creating a NEW department (no existing department id) while `isDepartmentCreationAvailable()` returns false. In the community edition that helper only returns true when `LivechatDepartment.countTotal() === 0` (packages/omni-core/src/isDepartmentCreationAvailable.ts), i.e. only ONE department is ever allowed; unlimited departments require the `livechat-enterprise` license module (ee/packages/omni-core-ee/src/isDepartmentCreationAvailable.ts).

Source

Thrown at apps/meteor/server/lib/omnichannel/departmentsLib.ts:52

	}

	const department = _id
		? await LivechatDepartment.findOneById<Pick<ILivechatDepartment, '_id' | 'archived' | 'enabled' | 'parentId'>>(_id, {
				projection: { _id: 1, archived: 1, enabled: 1, parentId: 1 },
			})
		: null;

	if (departmentUnit && !departmentUnit._id && department && department.parentId) {
		const isLastDepartmentInUnit = (await LivechatDepartment.countDepartmentsInUnit(department.parentId)) === 1;
		if (isLastDepartmentInUnit) {
			throw new Meteor.Error('error-unit-cant-be-empty', "The last department in a unit can't be removed", {
				method: 'livechat:saveDepartment',
			});
		}
	}

	if (!department && !(await isDepartmentCreationAvailable())) {
		throw new Meteor.Error('error-max-departments-number-reached', 'Maximum number of departments reached', {
			method: 'livechat:saveDepartment',
		});
	}

	if (department?.archived && departmentData.enabled) {
		throw new Meteor.Error('error-archived-department-cant-be-enabled', 'Archived departments cant be enabled', {
			method: 'livechat:saveDepartment',
		});
	}

	// TODO: Use AJV or Zod for validation (or the lib we are using rn)
	const defaultValidations: Record<string, Match.Matcher<any> | BooleanConstructor | StringConstructor> = {
		enabled: Boolean,
		name: String,
		description: Match.Optional(String),
		showOnRegistration: Boolean,
		email: String,
		showOnOfflineForm: Boolean,

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Verify the limit first via `GET /v1/livechat/department/isDepartmentCreationAvailable` (mirrors apps/meteor/client/views/omnichannel/departments/NewDepartment.tsx) and hide/disable the 'New Department' UI when it returns false
  2. If more departments are needed, install/enable an Enterprise license with the `livechat-enterprise` module, which patches the check to always allow creation
  3. Reuse or edit the existing department (`livechat:saveDepartment` with its `_id`) instead of creating a new one
  4. Delete the existing department to drop countTotal() back to 0 (only viable when one department is genuinely enough)

Example fix

// before
await Meteor.callAsync('livechat:saveDepartment', null, deptData);

// after
const { isDepartmentCreationAvailable } = await useEndpoint('GET', '/v1/livechat/department/isDepartmentCreationAvailable')();
if (!isDepartmentCreationAvailable) {
  throw new Error('Maximum number of departments reached for this license');
}
await Meteor.callAsync('livechat:saveDepartment', null, deptData);
Defensive patterns

Strategy: validation

Validate before calling

// Server-side or via REST before creating
const available = await isDepartmentCreationAvailable(); // or GET /v1/livechat/department/isDepartmentCreationAvailable
if (!available) {
  throw new Error('Department quota reached — upgrade license or edit the existing department');
}
await saveDepartment(null, deptData);

Type guard

const canCreateDepartments = async (): Promise<boolean> =>
  (await fetch('/api/v1/livechat/department/isDepartmentCreationAvailable')
    .then((r) => r.json())).isDepartmentCreationAvailable === true;

Try / catch

try {
  await saveDepartment(null, deptData);
} catch (e) {
  if (isMeteorError(e, 'error-max-departments-number-reached')) {
    // surface license/quota messaging, not a generic failure
  }
}

Prevention

When it happens

Trigger: Calling `livechat:saveDepartment` (or the REST `POST /v1/livechat/department`) with no `_id` while at least one LivechatDepartment document already exists on a server without the livechat-enterprise license module.

Common situations: Community/self-hosted installs where an admin already created a default department and then tries to add a second one; trials where the Enterprise license expired, silently re-enabling the single-department limit; imports/seeds that attempt to insert multiple departments.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/434f9bb495cb58dd. Report an issue: GitHub.