RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-sla

error-invalid-sla

Error message

Invalid sla

What it means

Thrown by the 'livechat.beforeNewInquiry' hook when extraData.sla is provided but OmnichannelServiceLevelAgreements.findOneByIdOrName cannot resolve it to an existing SLA (neither by _id nor by name). The hook needs a valid SLA to stamp slaId and estimated waiting time on the new inquiry, so an unresolvable reference aborts inquiry creation.

Solutions

  1. Verify the SLA exists: GET /api/v1/livechat/sla (or check Administration > Omnichannel > SLA) and use its exact _id or name
  2. Recreate the deleted SLA or update the caller to a current SLA identifier
  3. Omit the sla field entirely if no SLA should apply

Example fix

// before: sending an unvalidated SLA reference into inquiry creation
await createInquiry({ ...data, sla: slaTerm });

// after: resolve it first, exactly like the hook does
const sla = await OmnichannelServiceLevelAgreements.findOneByIdOrName(slaTerm, {
  projection: { dueTimeInMinutes: 1 },
});
if (!sla) throw new Error('Unknown SLA: ' + slaTerm);
await createInquiry({ ...data, sla: slaTerm });
Defensive patterns

Strategy: validation

Validate before calling

const slaExists = async (term: string): Promise<boolean> =>
  Boolean(await OmnichannelServiceLevelAgreements.findOneByIdOrName(term, { projection: { _id: 1 } }));

Try / catch

try {
  await createInquiry({ ...data, sla: slaTerm });
} catch (err: any) {
  if (err?.error === 'error-invalid-sla') {
    // refresh SLA list and resend with a valid id/name
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling the inquiry creation path (e.g. livechat visitor starting a chat with routed SLA data) with a stale or typo'd SLA id/name; SLA was deleted after clients cached its id; passing an SLA name with different casing/whitespace.

Common situations: SLA records removed during workspace cleanup while frontends still send the old identifier; integrations hard-coding SLA names that were renamed; seed scripts referencing SLAs created later.

Related errors


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

Appendix: source

Thrown at apps/meteor/ee/server/hooks/omnichannel/beforeNewInquiry.ts:21

import { Meteor } from 'meteor/meteor';

import { callbacks } from '../../../../server/lib/callbacks';

callbacks.add(
	'livechat.beforeInquiry',
	async (extraData) => {
		const { sla: slaSearchTerm, priority: prioritySearchTerm, ...props } = extraData;
		if (!slaSearchTerm && !prioritySearchTerm) {
			return extraData;
		}
		let sla: IOmnichannelServiceLevelAgreements | null = null;
		let priority: ILivechatPriority | null = null;
		if (slaSearchTerm) {
			sla = await OmnichannelServiceLevelAgreements.findOneByIdOrName(slaSearchTerm, {
				projection: { dueTimeInMinutes: 1 },
			});
			if (!sla) {
				throw new Meteor.Error('error-invalid-sla', 'Invalid sla', {
					function: 'livechat.beforeInquiry',
				});
			}
		}
		if (prioritySearchTerm) {
			priority = await LivechatPriority.findOneByIdOrName(prioritySearchTerm, {
				projection: { _id: 1, sortItem: 1 },
			});
			if (!priority) {
				throw new Meteor.Error('error-invalid-priority', 'Invalid priority', {
					function: 'livechat.beforeInquiry',
				});
			}
		}
		const ts = new Date();
		const changes: Partial<ILivechatInquiryRecord> = {
			ts,
		};

View on GitHub (pinned to b2c16d5842)