{"record":{"id":"ce1aa0568803ef21","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-sla","errorCode":"error-invalid-sla","errorMessage":"error-invalid-sla","messagePattern":"error-invalid-sla","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts","lineNumber":13,"sourceCode":"import { LivechatInquiry, Users, OmnichannelServiceLevelAgreements } from '@rocket.chat/models';\n\nimport { updateRoomSLA } from './sla';\n\nexport async function setSLAToInquiry({ userId, roomId, sla }: { userId: string; roomId: string; sla?: string }): Promise<void> {\n\tconst inquiry = await LivechatInquiry.findOneByRoomId(roomId, { projection: { status: 1 } });\n\tif (!inquiry || inquiry.status !== 'queued') {\n\t\tthrow new Error('error-invalid-inquiry');\n\t}\n\n\tconst slaData = sla && (await OmnichannelServiceLevelAgreements.findOneByIdOrName(sla));\n\tif (!slaData) {\n\t\tthrow new Error('error-invalid-sla');\n\t}\n\n\tconst user = await Users.findOneById(userId, { projection: { _id: 1, username: 1, name: 1 } });\n\tif (!user?.username) {\n\t\tthrow new Error('error-invalid-user');\n\t}\n\n\tawait updateRoomSLA(\n\t\troomId,\n\t\t{\n\t\t\t_id: user._id,\n\t\t\tname: user.name || '',\n\t\t\tusername: user.username,\n\t\t},\n\t\tslaData,\n\t);\n}\n","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts#L1-L31","documentation":"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.","triggerScenarios":"Passing an SLA name/id that was deleted since it was cached; passing an empty string; calling setSLAToInquiry without the sla parameter at all.","commonSituations":"Hardcoded SLA names deployed to workspaces where that SLA was never seeded; _id vs name confusion; cleanup scripts deleting SLAs still referenced by automation.","solutions":["List configured SLAs (omnichannel SLA endpoints) and pass the exact _id","Create the missing SLA first, then apply it to the inquiry","Ensure the sla parameter is actually provided — undefined fails the same way"],"exampleFix":"// before\nawait setSLAToInquiry({ userId, roomId, sla: 'Platinum' }); // SLA never created on this workspace\n\n// after\nlet sla = await OmnichannelServiceLevelAgreements.findOneByIdOrName('Platinum');\nif (!sla) sla = await createSla({ name: 'Platinum', dueTimeInMinutes: 5 });\nawait setSLAToInquiry({ userId, roomId, sla: sla.name });","handlingStrategy":"validation","validationCode":"import { OmnichannelServiceLevelAgreements } from '@rocket.chat/models';\n\nconst slaData = await OmnichannelServiceLevelAgreements.findOneByIdOrName(sla);\nif (!slaData) {\n  throw new Error(`SLA '${sla}' does not exist - create it before assigning`);\n}\nawait setSLAToInquiry({ userId, roomId, sla: slaData._id });","typeGuard":null,"tryCatchPattern":"try {\n  await setSLAToInquiry({ userId, roomId, sla });\n} catch (error) {\n  if (error instanceof Error && error.message === 'error-invalid-sla') {\n    throw new NotFoundError(`SLA '${sla}' not found - list SLAs and retry with an existing _id`);\n  }\n  throw error;\n}","preventionTips":["Seed SLAs via provisioning before automation references them by name","Pass the SLA _id rather than a display name","Remember: omitting the sla argument fails identically"],"tags":["omnichannel","livechat","sla","not-found"],"backgroundTag":"resource-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"}