{"record":{"id":"a395e9e0316150e8","repo":"RocketChat/Rocket.Chat","slug":"error-user-param-not-provided","errorCode":"error-user-param-not-provided","errorMessage":"The required \"userId\" or \"username\" param was not provided","messagePattern":"The required \"userId\" or \"username\" param was not provided","errorType":"validation","errorClass":"Meteor.Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/api/lib/getUserFromParams.ts","lineNumber":31,"sourceCode":"\tfull?: T,\n): Promise<\n\tT extends true\n\t\t? IUser\n\t\t: Pick<IUser, '_id' | 'username' | 'name' | 'status' | 'statusDefault' | 'statusText' | 'statusSource' | 'statusExpiresAt' | 'roles'>\n> {\n\tlet user;\n\n\tconst projection = full\n\t\t? {}\n\t\t: { username: 1, name: 1, status: 1, statusDefault: 1, statusText: 1, statusSource: 1, statusExpiresAt: 1, roles: 1 };\n\tif (params.userId?.trim()) {\n\t\tuser = await Users.findOneById(params.userId, { projection });\n\t} else if (params.username?.trim()) {\n\t\tuser = await Users.findOneByUsernameIgnoringCase(params.username, { projection });\n\t} else if (params.user?.trim()) {\n\t\tuser = await Users.findOneByUsernameIgnoringCase(params.user, { projection });\n\t} else {\n\t\tthrow new Meteor.Error('error-user-param-not-provided', 'The required \"userId\" or \"username\" param was not provided');\n\t}\n\n\tif (!user) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'The required \"userId\" or \"username\" param provided does not match any users');\n\t}\n\n\treturn user;\n}\n\nexport async function getUserListFromParams(params: {\n\tuserId?: string;\n\tusername?: string;\n\tuser?: string;\n\tuserIds?: string[];\n\tusernames?: string[];\n}): Promise<Pick<IUser, '_id' | 'username'>[]> {\n\t// if params.userId is provided, include it as well\n\tconst soleUser = params.userId || params.username || params.user;","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/api/lib/getUserFromParams.ts#L13-L49","documentation":"getUserFromParams is the shared resolver for REST endpoints that reference a user; it requires at least one non-blank userId, username or user param (values are .trim()ed, so whitespace-only counts as missing). When none is provided it throws error-user-param-not-provided; the sibling error-invalid-user covers values that are provided but match no user.","triggerScenarios":"Calling user-scoped REST routes (users.info, users.getAvatar, etc.) with none of userId/username/user in the query or body — e.g. dynamically built queries that end up with empty strings, blank form fields, or misspelled param names (user_name instead of username).","commonSituations":"Clients building query strings from optional inputs without dropping empties, typos in param names, whitespace from copy-paste.","solutions":["Pass userId or username as a non-empty string in the query/body.","Trim inputs client-side and omit the parameter entirely when empty rather than sending blank values.","Double-check the accepted param names (userId, username, user) against the endpoint docs."],"exampleFix":"// before\napi.get('/v1/users.info', { params: { user: '   ' } }); // whitespace-only\n\n// after\napi.get('/v1/users.info', { params: { username: 'rocket.cat' } });","handlingStrategy":"validation","validationCode":"const ident = params.userId?.trim() || params.username?.trim() || params.user?.trim();\nif (!ident) {\n\t// do not call the endpoint: require userId or username from the caller\n}","typeGuard":"function hasUserIdentifier(p: { userId?: string; username?: string; user?: string }): boolean {\n\treturn Boolean(p.userId?.trim() || p.username?.trim() || p.user?.trim());\n}","tryCatchPattern":"try {\n\tawait api.get('/v1/users.info', { params });\n} catch (e: any) {\n\tif (e?.error === 'error-user-param-not-provided') {\n\t\t// prompt for/attach userId or username, then retry\n\t}\n\tthrow e;\n}","preventionTips":["Omit empty query params instead of sending blank strings","Trim user input before building query strings","Use the exact param names the endpoint accepts (userId, username, user)"],"tags":["rest-api","users","query-params","validation"],"backgroundTag":"missing-required-parameter","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}