{"record":{"id":"ec1055a07f278eb9","repo":"RocketChat/Rocket.Chat","slug":"error-cannot-delete-team-channel","errorCode":"error-cannot-delete-team-channel","errorMessage":"Cannot delete a team channel","messagePattern":"Cannot delete a team channel","errorType":"exception","errorClass":"Meteor.Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/api/v1/rooms.ts","lineNumber":212,"sourceCode":"\t\t\t\tadditionalProperties: false,\n\t\t\t}),\n\t\t\t400: validateBadRequestErrorResponse,\n\t\t\t401: validateUnauthorizedErrorResponse,\n\t\t},\n\t},\n\tasync function action() {\n\t\tconst { roomId } = this.bodyParams;\n\n\t\tconst room = await Rooms.findOneById(roomId);\n\n\t\tif (!room) {\n\t\t\tthrow new MeteorError('error-invalid-room', 'Invalid room', {\n\t\t\t\tmethod: 'eraseRoom',\n\t\t\t});\n\t\t}\n\n\t\tif (room.teamMain) {\n\t\t\tthrow new Meteor.Error('error-cannot-delete-team-channel', 'Cannot delete a team channel', {\n\t\t\t\tmethod: 'eraseRoom',\n\t\t\t});\n\t\t}\n\n\t\tawait eraseRoom(room, this.user);\n\n\t\treturn API.v1.success();\n\t},\n);\n\nAPI.v1.get(\n\t'rooms.get',\n\t{\n\t\tauthRequired: true,\n\t\tresponse: {\n\t\t\t200: ajv.compile<{ update: IRoom[]; remove: IRoom[] }>({\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: {","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/e4b8178b205510181a96ceefee043d0abcd13e5a/apps/meteor/server/api/v1/rooms.ts#L194-L230","documentation":"Thrown by POST /api/v1/rooms.delete when the resolved room has teamMain set, i.e. it is the main channel of a Teams team. Deleting it would orphan the team's channels and members, so the endpoint refuses with details.method 'eraseRoom'. The team must be removed through the teams API instead.","triggerScenarios":"POST rooms.delete with the roomId of a channel created as a team's main channel (rooms with teamId set and teamMain true); a cleanup script that iterates all rooms and hits team main channels.","commonSituations":"Workspace migrations sweeping channels without accounting for Teams; scripts written before Teams existed; users confusing a team's main channel with an ordinary channel; provisioning cleanup that deletes rooms by creation date.","solutions":["Delete the whole team instead: POST /api/v1/teams.remove with the team's teamId or teamName","Filter team main channels out of bulk room-deletion lists (rooms.info exposes teamMain/teamId)","If the channel must go but the team stays, convert the setup so the team has a different main channel first"],"exampleFix":"// before\nawait sdk.post('rooms.delete', { roomId }); // teamMain channel -> error-cannot-delete-team-channel\n\n// after\nconst { room } = await sdk.get('rooms.info', { roomId });\nif (room.teamMain) {\n  await sdk.post('teams.remove', { teamName: room.name }); // removes team and its main channel\n  return;\n}\nawait sdk.post('rooms.delete', { roomId });","handlingStrategy":"validation","validationCode":"const { room } = await sdk.get('rooms.info', { roomId });\nif (room.teamMain) throw new Error('delete the team instead: POST teams.remove');","typeGuard":null,"tryCatchPattern":"try {\n  await sdk.post('rooms.delete', { roomId });\n} catch (e: any) {\n  if (e?.response?.data?.errorType === 'error-cannot-delete-team-channel') {\n    await sdk.post('teams.remove', { roomId }); // escalate to team deletion\n    return;\n  }\n  throw e;\n}","preventionTips":["Filter teamMain rooms out of bulk channel deletions","Read teamId/teamMain from rooms.info before destructive sweeps","Use the teams API for anything created as a team"],"tags":["rooms","teams","delete","rest-api"],"backgroundTag":"protected-resource-delete","analyzedSha":"e4b8178b205510181a96ceefee043d0abcd13e5a","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}