{"record":{"id":"829cf1d55257a90c","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-priority","errorCode":"error-invalid-priority","errorMessage":"error-invalid-priority","messagePattern":"error-invalid-priority","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/ee/server/api/v1/omnichannel/lib/priorities.ts","lineNumber":75,"sourceCode":"\t\tthrow Error('error-unable-to-update-priority');\n\t}\n\n\treturn createdResult;\n}\n\nexport const updateRoomPriority = async (\n\trid: string,\n\tuser: Required<Pick<IUser, '_id' | 'username' | 'name'>>,\n\tpriorityId: string,\n): Promise<void> => {\n\tconst room = await LivechatRooms.findOneById(rid);\n\tif (!room) {\n\t\tthrow new Error('error-room-does-not-exist');\n\t}\n\n\tconst priority = await LivechatPriority.findOneById(priorityId);\n\tif (!priority) {\n\t\tthrow new Error('error-invalid-priority');\n\t}\n\n\tawait Promise.all([\n\t\tLivechatRooms.setPriorityByRoomId(rid, priority),\n\t\tLivechatInquiry.setPriorityForRoom(rid, priority),\n\t\taddPriorityChangeHistoryToRoom(room._id, user, priority),\n\t]);\n\n\tvoid notifyOnRoomChanged({ ...room, priorityId: priority._id, priorityWeight: priority.sortItem }, 'updated');\n\tvoid notifyOnLivechatInquiryChangedByRoom(rid, 'updated');\n};\n\nexport const removePriorityFromRoom = async (rid: string, user: Required<Pick<IUser, '_id' | 'username' | 'name'>>): Promise<void> => {\n\tconst room = await LivechatRooms.findOneById<Omit<IOmnichannelRoom, 'priorityId' | 'priorityWeight'>>(rid, {\n\t\tprojection: { priorityId: 0, priorityWeight: 0 },\n\t});\n\tif (!room) {\n\t\tthrow new Error('error-room-does-not-exist');","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/api/v1/omnichannel/lib/priorities.ts#L57-L93","documentation":"In updateRoomPriority (POST livechat/room/:rid/priority), after the room is found the requested priorityId is resolved with LivechatPriority.findOneById; a miss throws error-invalid-priority. Nothing is written when this fires, so room and inquiry stay consistent.","triggerScenarios":"POST /api/v1/livechat/room/<rid>/priority with a priorityId that is not the _id of a LivechatPriority document: a hand-typed id, the priority's display name or i18n key instead of its _id, or a priority an admin deleted.","commonSituations":"Using the priority name ('Urgent') instead of its _id; referencing a priority deleted while a client tab still had it selected; ids invalidated after priorities were reset to defaults via livechat/priorities.reset.","solutions":["GET /api/v1/livechat/priorities and use the exact _id field of the priority you want.","Re-fetch the list immediately before assigning if priorities may have been edited or reset concurrently.","If the priority was deleted, recreate it (or run priorities.reset to restore defaults) and retry with the new _id."],"exampleFix":"// before\nawait api.post(`/v1/livechat/room/${rid}/priority`, { priorityId: 'Urgent' }); // name, not _id\n\n// after\nconst { priorities } = await api.get('/v1/livechat/priorities', { params: { count: 0 } });\nconst urgent = priorities.find((p) => p.name === 'Urgent');\nif (urgent) await api.post(`/v1/livechat/room/${rid}/priority`, { priorityId: urgent._id });","handlingStrategy":"validation","validationCode":"const { priorities } = await api.get('/v1/livechat/priorities', { params: { count: 0 } });\nconst target = priorities.find((p) => p._id === priorityId);\nif (!target) throw new Error(`Priority ${priorityId} not found; refusing to assign`);\nawait api.post(`/v1/livechat/room/${rid}/priority`, { priorityId: target._id });","typeGuard":null,"tryCatchPattern":"try {\n  await api.post(`/v1/livechat/room/${rid}/priority`, { priorityId });\n} catch (e) {\n  if (e?.response?.data?.errorType === 'error-invalid-priority') {\n    // refresh the priorities list and re-select a valid _id\n  } else throw e;\n}","preventionTips":["Store and send the priority _id, never its display name or i18n key.","Refresh the priorities list after admins edit or reset priorities.","Treat 'error-invalid-priority' as a signal your reference data is stale."],"tags":["omnichannel","livechat-priorities","invalid-id","rest-api"],"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-14T05:17:10.506Z"}