{"record":{"id":"185690aa905de919","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-username","errorCode":"error-invalid-username","errorMessage":"Invalid username","messagePattern":"Invalid username","errorType":"validation","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/integrations/lib/validateOutgoingIntegration.ts","lineNumber":28,"sourceCode":"import { hasPermissionAsync, hasAllPermissionAsync } from '../../authorization/hasPermission';\n\nconst scopedChannels = ['all_public_channels', 'all_private_groups', 'all_direct_messages'];\nconst validChannelChars = ['@', '#'];\n\nfunction _verifyRequiredFields(integration: INewOutgoingIntegration | IUpdateOutgoingIntegration): void {\n\tif (\n\t\t!integration.event ||\n\t\t!Match.test(integration.event, String) ||\n\t\tintegration.event.trim() === '' ||\n\t\t!outgoingEvents[integration.event]\n\t) {\n\t\tthrow new Meteor.Error('error-invalid-event-type', 'Invalid event type', {\n\t\t\tfunction: 'validateOutgoing._verifyRequiredFields',\n\t\t});\n\t}\n\n\tif (!integration.username || !Match.test(integration.username, String) || integration.username.trim() === '') {\n\t\tthrow new Meteor.Error('error-invalid-username', 'Invalid username', {\n\t\t\tfunction: 'validateOutgoing._verifyRequiredFields',\n\t\t});\n\t}\n\n\tif (outgoingEvents[integration.event].use.targetRoom && !integration.targetRoom) {\n\t\tthrow new Meteor.Error('error-invalid-targetRoom', 'Invalid Target Room', {\n\t\t\tfunction: 'validateOutgoing._verifyRequiredFields',\n\t\t});\n\t}\n\n\tif (!Match.test(integration.urls, [String])) {\n\t\tthrow new Meteor.Error('error-invalid-urls', 'Invalid URLs', {\n\t\t\tfunction: 'validateOutgoing._verifyRequiredFields',\n\t\t});\n\t}\n\n\tintegration.urls = integration.urls.filter((url) => url && url.trim() !== '');\n","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/integrations/lib/validateOutgoingIntegration.ts#L10-L46","documentation":"Thrown by _verifyRequiredFields when validating an outgoing integration whose `username` is missing, not a string, or blank after trimming. This username selects the 'post as' user for integration output (commonly rocket.cat) and later gets resolved against the Users collection, so a shape failure is rejected immediately with Meteor.Error code 'error-invalid-username'.","triggerScenarios":"POST /api/v1/integrations.create with type 'webhook-outgoing' and no username field, username: '' or '   ', or username passed as a user _id / object instead of the username string.","commonSituations":"Forms that submit before the 'Post as' field is chosen; scripts that build the payload from optional environment variables that are unset; confusion between userId and username in the payload.","solutions":["Include a non-empty string username, usually 'rocket.cat' or a dedicated bot account","Trim the input client-side and reject blank values before calling the API","Make sure you send the username (e.g. 'rocket.cat'), not the user _id"],"exampleFix":"// before\n{ type: 'webhook-outgoing', event: 'sendMessage', username: '', urls: [...] }\n\n// after\n{ type: 'webhook-outgoing', event: 'sendMessage', username: 'rocket.cat', urls: [...] }","handlingStrategy":"validation","validationCode":"if (typeof integration.username !== 'string' || integration.username.trim() === '') {\n  throw new TypeError('outgoing integrations need a non-empty username (post-as user)');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default the post-as field to 'rocket.cat' in integration forms","Send the username string, never a user _id or object"],"tags":["integrations","outgoing-webhook","validation","username"],"backgroundTag":"missing-required-field","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}