{"record":{"id":"c6cd421a6fdee94d","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-sla-c6cd42","errorCode":"error-invalid-sla","errorMessage":"Invalid sla","messagePattern":"Invalid sla","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/hooks/omnichannel/beforeNewInquiry.ts","lineNumber":21,"sourceCode":"import { Meteor } from 'meteor/meteor';\n\nimport { callbacks } from '../../../../server/lib/callbacks';\n\ncallbacks.add(\n\t'livechat.beforeInquiry',\n\tasync (extraData) => {\n\t\tconst { sla: slaSearchTerm, priority: prioritySearchTerm, ...props } = extraData;\n\t\tif (!slaSearchTerm && !prioritySearchTerm) {\n\t\t\treturn extraData;\n\t\t}\n\t\tlet sla: IOmnichannelServiceLevelAgreements | null = null;\n\t\tlet priority: ILivechatPriority | null = null;\n\t\tif (slaSearchTerm) {\n\t\t\tsla = await OmnichannelServiceLevelAgreements.findOneByIdOrName(slaSearchTerm, {\n\t\t\t\tprojection: { dueTimeInMinutes: 1 },\n\t\t\t});\n\t\t\tif (!sla) {\n\t\t\t\tthrow new Meteor.Error('error-invalid-sla', 'Invalid sla', {\n\t\t\t\t\tfunction: 'livechat.beforeInquiry',\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (prioritySearchTerm) {\n\t\t\tpriority = await LivechatPriority.findOneByIdOrName(prioritySearchTerm, {\n\t\t\t\tprojection: { _id: 1, sortItem: 1 },\n\t\t\t});\n\t\t\tif (!priority) {\n\t\t\t\tthrow new Meteor.Error('error-invalid-priority', 'Invalid priority', {\n\t\t\t\t\tfunction: 'livechat.beforeInquiry',\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tconst ts = new Date();\n\t\tconst changes: Partial<ILivechatInquiryRecord> = {\n\t\t\tts,\n\t\t};","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/hooks/omnichannel/beforeNewInquiry.ts#L3-L39","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the SLA exists: GET /api/v1/livechat/sla (or check Administration > Omnichannel > SLA) and use its exact _id or name","Recreate the deleted SLA or update the caller to a current SLA identifier","Omit the sla field entirely if no SLA should apply"],"exampleFix":"// before: sending an unvalidated SLA reference into inquiry creation\nawait createInquiry({ ...data, sla: slaTerm });\n\n// after: resolve it first, exactly like the hook does\nconst sla = await OmnichannelServiceLevelAgreements.findOneByIdOrName(slaTerm, {\n  projection: { dueTimeInMinutes: 1 },\n});\nif (!sla) throw new Error('Unknown SLA: ' + slaTerm);\nawait createInquiry({ ...data, sla: slaTerm });","handlingStrategy":"validation","validationCode":"const slaExists = async (term: string): Promise<boolean> =>\n  Boolean(await OmnichannelServiceLevelAgreements.findOneByIdOrName(term, { projection: { _id: 1 } }));","typeGuard":null,"tryCatchPattern":"try {\n  await createInquiry({ ...data, sla: slaTerm });\n} catch (err: any) {\n  if (err?.error === 'error-invalid-sla') {\n    // refresh SLA list and resend with a valid id/name\n  }\n  throw err;\n}","preventionTips":["Cache the SLA list per session but revalidate ids before submitting inquiries","When deleting SLAs, scrub configurations (triggers, widgets) that reference them","Prefer stable SLA ids over names in integrations"],"tags":["omnichannel","livechat","sla","entity-not-found"],"backgroundTag":"sla-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}