{"record":{"id":"2983613bd68a8b6b","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-post-as-user","errorCode":"error-invalid-post-as-user","errorMessage":"Invalid Post As User","messagePattern":"Invalid Post As User","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/integrations/incoming/updateIncomingIntegration.ts","lineNumber":149,"sourceCode":"\t\t\t\tmethod: 'updateIncomingIntegration',\n\t\t\t});\n\t\t}\n\n\t\tif (\n\t\t\t!(await hasAllPermissionAsync(userId, ['manage-incoming-integrations', 'manage-own-incoming-integrations'])) &&\n\t\t\t!(await Subscriptions.findOneByRoomIdAndUserId(record._id, userId, { projection: { _id: 1 } }))\n\t\t) {\n\t\t\tthrow new Meteor.Error('error-invalid-channel', 'Invalid Channel', {\n\t\t\t\tmethod: 'updateIncomingIntegration',\n\t\t\t});\n\t\t}\n\t}\n\n\tconst username = 'username' in integration ? integration.username : currentIntegration.username;\n\tconst user = await Users.findOneByUsername(username, { projection: { _id: 1, username: 1 } });\n\n\tif (!user) {\n\t\tthrow new Meteor.Error('error-invalid-post-as-user', 'Invalid Post As User', {\n\t\t\tmethod: 'updateIncomingIntegration',\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: 'updateIncomingIntegration',\n\t\t\t},\n\t\t);\n\t}\n\n\tconst updatedIntegration = await Integrations.findOneAndUpdate(\n\t\t{ _id: integrationId },\n\t\t{\n\t\t\t$set: {","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/integrations/incoming/updateIncomingIntegration.ts#L131-L167","documentation":"Thrown by updateIncomingIntegration when the post-as username cannot be resolved to a user. The username is taken from the update payload when the key is present, otherwise from the integration's stored record, then looked up with Users.findOneByUsername. A null result means that username has no account - note this fires even when you did not send a username, if the stored one has since been deleted or renamed. The code differs from the create path ('error-invalid-user') - update uses 'error-invalid-post-as-user'.","triggerScenarios":"Updating any field of an integration whose stored post-as user was deleted; renaming a user account without updating integrations that post as them; sending username: 'CI Bot' (display name) in the update payload.","commonSituations":"Offboarded bot accounts removed by user-lifecycle cleanup; username policy renames; environments re-provisioned without the original bot users.","solutions":["Include a valid 'username' (existing workspace user) in the update payload to migrate the integration to a live account","Or recreate the deleted user with the same username, then retry without changing the payload","Check the exact @username in Administration -> Users - display names never resolve here"],"exampleFix":"// before: stored post-as user was deleted; payload omits username\nawait Meteor.callAsync('updateIncomingIntegration', id, { enabled: true, channel: '#general' }); // -> error-invalid-post-as-user\n// after: re-point the integration at an existing user in the same update\nawait Meteor.callAsync('updateIncomingIntegration', id, { enabled: true, channel: '#general', username: 'ci-bot' });","handlingStrategy":"validation","validationCode":"// before updating, make sure a resolvable post-as user will be used\nconst effectiveUsername = integration.username ?? currentIntegration.username;\nconst res = await fetch(`${root}/api/v1/users.info?username=${encodeURIComponent(effectiveUsername)}`, { headers: authHeaders });\nif (!res.ok) { await Meteor.callAsync('updateIncomingIntegration', integrationId, { ...integration, username: 'ci-bot' }); } // migrate to a live user\nelse { await Meteor.callAsync('updateIncomingIntegration', integrationId, integration); }","typeGuard":null,"tryCatchPattern":"try {\n  await Meteor.callAsync('updateIncomingIntegration', integrationId, integration);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-invalid-post-as-user') { /* resend with a valid username field */ }\n}","preventionTips":["When deleting/renaming users, sweep integrations that post as them","Always include an explicit username when updating integrations you do not own the data of","Keep bot accounts out of user-lifecycle cleanup policies"],"tags":["rocket-chat","incoming-integration","user-not-found","meteor-method"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}