RocketChat/Rocket.Chat · warning · Meteor.Error

error-room-param-not-provided

error-room-param-not-provided

Error message

Query param "roomId" or "username" is required

What it means

Thrown by the findDirectMessageRoom helper in im.ts (lines 49-52) which backs the im.* DM endpoints. The helper picks roomId if the key is present, otherwise username; if the resulting value is not a string (i.e. neither roomId nor username was supplied, or it was undefined), it rejects with error-room-param-not-provided. This is a client input error: a DM target was not provided at all.

Source

Thrown at apps/meteor/server/api/v1/im.ts:51

import { getChannelHistory } from '../../meteor-methods/messages/getChannelHistory';
import { hideRoomMethod } from '../../meteor-methods/rooms/hideRoom';
import { leaveRoomMethod } from '../../meteor-methods/rooms/leaveRoom';
import { saveRoomSettings } from '../../meteor-methods/rooms/saveRoomSettings';
import { settings } from '../../settings';
import type { ExtractRoutesFromAPI } from '../ApiClass';
import { API } from '../api';
import type { TypedAction } from '../definition';
import { addUserToFileObj } from '../lib/addUserToFileObj';
import { composeRoomWithLastMessage } from '../lib/composeRoomWithLastMessage';
import { getPaginationItems } from '../lib/getPaginationItems';

const findDirectMessageRoom = async (
	keys: { roomId?: string; username?: string },
	uid: string,
): Promise<{ room: IRoom; subscription: ISubscription | null }> => {
	const nameOrId = 'roomId' in keys ? keys.roomId : keys.username;
	if (typeof nameOrId !== 'string') {
		throw new Meteor.Error('error-room-param-not-provided', 'Query param "roomId" or "username" is required');
	}

	const user = await Users.findOneById(uid);
	if (!user) {
		throw new Meteor.Error('error-invalid-user', 'Invalid user', {
			method: 'findDirectMessageRoom',
		});
	}

	const room = await getRoomByNameOrIdWithOptionToJoin({
		user,
		nameOrId,
		type: 'd',
	});

	if (!room || room?.t !== 'd') {
		throw new Meteor.Error('error-room-not-found', 'The required "roomId" param provided does not match any direct message');
	}

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Always supply roomId (preferred for existing DMs) or username (to resolve/create the DM) on im.* calls.
  2. Guard the call site: skip the request when neither identifier is available.
  3. Use username when creating/opening a DM by counterpart; use roomId for subsequent operations.
  4. Confirm the field is named exactly 'roomId' or 'username'.

Example fix

// before
await GET('/api/v1/im.info', {}); // no roomId/username -> error-room-param-not-provided

// after
const target = roomId ?? `@${username}`;
await GET('/api/v1/im.info', roomId ? { roomId } : { username });
Defensive patterns

Strategy: validation

Validate before calling

// Require a non-empty DM target before calling im.* endpoints.
const target = {};
if (typeof roomId === 'string' && roomId.trim()) target.roomId = roomId;
else if (typeof username === 'string' && username.trim()) target.username = username;
else throw new Error('roomId or username is required');
await api.get('/api/v1/im.info', target);

Type guard

function hasDmTarget(p) {
  return (typeof p?.roomId === 'string' && p.roomId.trim() !== '') ||
         (typeof p?.username === 'string' && p.username.trim() !== '');
}

Try / catch

try {
  await api.get('/api/v1/im.info', target);
} catch (e) {
  if (isMeteorError(e) && e.reason === 'error-room-param-not-provided') {
    showFormError('Select a contact first');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling any im.* endpoint routed through findDirectMessageRoom (e.g. im.info, im.files, im.history variants) without both roomId and username in the query/body, so nameOrId resolves to undefined.

Common situations: A client opens a DM screen before the counterpart is selected (username undefined) and before a roomId exists. A bot calls im.* with neither identifier. Query string built from null variables.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12). Data as JSON: /api/errors/6b503de3dda3d01d. Report an issue: GitHub.