{"record":{"id":"bb3c0507726dc02d","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-bb3c05","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/integrations/incoming/addIncomingIntegration.ts","lineNumber":88,"sourceCode":"\t\t\t\tmethod: 'updateIncomingIntegration',\n\t\t\t});\n\t\t}\n\t}\n\n\tif (!integration.username || typeof integration.username.valueOf() !== 'string' || integration.username.trim() === '') {\n\t\tthrow new Meteor.Error('error-invalid-username', 'Invalid username', {\n\t\t\tmethod: 'addIncomingIntegration',\n\t\t});\n\t}\n\n\tif (integration.script?.trim()) {\n\t\tvalidateScriptEngine(integration.scriptEngine ?? 'isolated-vm');\n\t}\n\n\tconst user = await Users.findOneByUsername(integration.username, { projection: { _id: 1 } });\n\n\tif (!user) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\tmethod: 'addIncomingIntegration',\n\t\t});\n\t}\n\n\tif (!(await hasPermissionAsync(user._id, 'message-impersonate'))) {\n\t\tthrow new Meteor.Error(\n\t\t\t'error-user-lacks-message-impersonate-permission',\n\t\t\t\"User selected for the incoming integration lacks the 'message-impersonate' permission.\",\n\t\t\t{\n\t\t\t\tmethod: 'addIncomingIntegration',\n\t\t\t},\n\t\t);\n\t}\n\n\t// Default to transpiling with Babel for backwards compatibility; integrations\n\t// can opt-out per-record by setting `skipTranspile: true` (removed in 9.0.0).\n\tconst skipTranspile = integration.skipTranspile === true;\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/integrations/incoming/addIncomingIntegration.ts#L70-L106","documentation":"Thrown by addIncomingIntegration when Users.findOneByUsername(integration.username) returns null: no user with that exact username exists in this workspace. Lookup happens before any permission checks on the target user, so a typo fails here rather than as a permission error. Usernames are matched exactly (case-sensitive) against the Users collection.","triggerScenarios":"username: 'CI Bot' (display name instead of username), 'john.doe' after the user renamed to 'john.doe2', a user deleted from the workspace, or the account existing only on a different server/deployment.","commonSituations":"Copy-pasting the visible name from the UI instead of the @username; hard-coded bot username that was never provisioned on this environment; multi-environment configs where the bot exists in staging but not production.","solutions":["Copy the exact username from Administration -> Users (the @handle, not the display name)","Create the bot user first (Administration -> Users -> New) and retry with its username","If provisioning via API, verify with GET /api/v1/users.info?username=... before creating the integration"],"exampleFix":"// before\nMeteor.callAsync('addIncomingIntegration', { ...integration, username: 'CI Bot' }); // display name -> no such user\n// after\nMeteor.callAsync('addIncomingIntegration', { ...integration, username: 'ci.bot' }); // exact username from Users admin","handlingStrategy":"validation","validationCode":"// server-side / REST caller: confirm the user exists before the DDP/method call\nconst res = await fetch(`${root}/api/v1/users.info?username=${encodeURIComponent(integration.username)}`, { headers: authHeaders });\nif (!res.ok) throw new Error(`post-as user '${integration.username}' does not exist`);\nawait Meteor.callAsync('addIncomingIntegration', integration);","typeGuard":"const isUsernameOfExistingUser = (username: string, known: { username: string }[]) => known.some((u) => u.username === username);","tryCatchPattern":"try {\n  await Meteor.callAsync('addIncomingIntegration', integration);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-invalid-user') { /* surface 'user not found', offer user picker */ }\n}","preventionTips":["Use a user picker fed by the live directory rather than typed names","Provision the bot user before the integration in setup scripts","Re-verify hard-coded usernames when promoting between environments"],"tags":["rocket-chat","incoming-integration","meteor-method","user-not-found"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}