RocketChat/Rocket.Chat · error · Error

error-invalid-sla

error-invalid-sla

Error message

error-invalid-sla

What it means

The sla argument of setSLAToInquiry must resolve through OmnichannelServiceLevelAgreements.findOneByIdOrName — matching _id OR name. A deleted or mistyped SLA throws 'error-invalid-sla'; note that omitting sla entirely also throws, because slaData is then falsy.

Solutions

  1. List configured SLAs (omnichannel SLA endpoints) and pass the exact _id
  2. Create the missing SLA first, then apply it to the inquiry
  3. Ensure the sla parameter is actually provided — undefined fails the same way

Example fix

// before
await setSLAToInquiry({ userId, roomId, sla: 'Platinum' }); // SLA never created on this workspace

// after
let sla = await OmnichannelServiceLevelAgreements.findOneByIdOrName('Platinum');
if (!sla) sla = await createSla({ name: 'Platinum', dueTimeInMinutes: 5 });
await setSLAToInquiry({ userId, roomId, sla: sla.name });
Defensive patterns

Strategy: validation

Validate before calling

import { OmnichannelServiceLevelAgreements } from '@rocket.chat/models';

const slaData = await OmnichannelServiceLevelAgreements.findOneByIdOrName(sla);
if (!slaData) {
  throw new Error(`SLA '${sla}' does not exist - create it before assigning`);
}
await setSLAToInquiry({ userId, roomId, sla: slaData._id });

Try / catch

try {
  await setSLAToInquiry({ userId, roomId, sla });
} catch (error) {
  if (error instanceof Error && error.message === 'error-invalid-sla') {
    throw new NotFoundError(`SLA '${sla}' not found - list SLAs and retry with an existing _id`);
  }
  throw error;
}

Prevention

When it happens

Trigger: Passing an SLA name/id that was deleted since it was cached; passing an empty string; calling setSLAToInquiry without the sla parameter at all.

Common situations: Hardcoded SLA names deployed to workspaces where that SLA was never seeded; _id vs name confusion; cleanup scripts deleting SLAs still referenced by automation.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts:13

import { LivechatInquiry, Users, OmnichannelServiceLevelAgreements } from '@rocket.chat/models';

import { updateRoomSLA } from './sla';

export async function setSLAToInquiry({ userId, roomId, sla }: { userId: string; roomId: string; sla?: string }): Promise<void> {
	const inquiry = await LivechatInquiry.findOneByRoomId(roomId, { projection: { status: 1 } });
	if (!inquiry || inquiry.status !== 'queued') {
		throw new Error('error-invalid-inquiry');
	}

	const slaData = sla && (await OmnichannelServiceLevelAgreements.findOneByIdOrName(sla));
	if (!slaData) {
		throw new Error('error-invalid-sla');
	}

	const user = await Users.findOneById(userId, { projection: { _id: 1, username: 1, name: 1 } });
	if (!user?.username) {
		throw new Error('error-invalid-user');
	}

	await updateRoomSLA(
		roomId,
		{
			_id: user._id,
			name: user.name || '',
			username: user.username,
		},
		slaData,
	);
}

View on GitHub (pinned to b2c16d5842)