RocketChat/Rocket.Chat · error · Meteor.Error
error-cannot-delete-team-channel
error-cannot-delete-team-channel
Error message
Cannot delete a team channel
What it means
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.
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
Example fix
// before
await sdk.post('rooms.delete', { roomId }); // teamMain channel -> error-cannot-delete-team-channel
// after
const { room } = await sdk.get('rooms.info', { roomId });
if (room.teamMain) {
await sdk.post('teams.remove', { teamName: room.name }); // removes team and its main channel
return;
}
await sdk.post('rooms.delete', { roomId }); Defensive patterns
Strategy: validation
Validate before calling
const { room } = await sdk.get('rooms.info', { roomId });
if (room.teamMain) throw new Error('delete the team instead: POST teams.remove'); Try / catch
try {
await sdk.post('rooms.delete', { roomId });
} catch (e: any) {
if (e?.response?.data?.errorType === 'error-cannot-delete-team-channel') {
await sdk.post('teams.remove', { roomId }); // escalate to team deletion
return;
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- error-invalid-room
- error-action-not-allowed
- error-invalid-subscription
- error-invalid-subscription
- error-invalid-team-no-main-room
AI-assisted analysis of RocketChat/Rocket.Chat@e4b8178b20 (2026-08-18).
Data as JSON: /api/errors/ec1055a07f278eb9.
Report an issue: GitHub.
Appendix: source
Thrown at apps/meteor/server/api/v1/rooms.ts:212
additionalProperties: false,
}),
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
},
},
async function action() {
const { roomId } = this.bodyParams;
const room = await Rooms.findOneById(roomId);
if (!room) {
throw new MeteorError('error-invalid-room', 'Invalid room', {
method: 'eraseRoom',
});
}
if (room.teamMain) {
throw new Meteor.Error('error-cannot-delete-team-channel', 'Cannot delete a team channel', {
method: 'eraseRoom',
});
}
await eraseRoom(room, this.user);
return API.v1.success();
},
);
API.v1.get(
'rooms.get',
{
authRequired: true,
response: {
200: ajv.compile<{ update: IRoom[]; remove: IRoom[] }>({
type: 'object',
properties: {View on GitHub (pinned to e4b8178b20)