{"record":{"id":"e17557fcbe5286d1","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-integration","errorCode":"error-invalid-integration","errorMessage":"Invalid integration","messagePattern":"Invalid integration","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/integrations/functions/clearIntegrationHistory.ts","lineNumber":24,"sourceCode":"import notifications from '../../notifications/core/lib/Notifications';\nimport { triggerHandler } from '../lib/triggerHandler';\n\nexport const clearIntegrationHistoryMethod = async (userId: string, integrationId: string): Promise<void> => {\n\tlet integration: IIntegration | null = null;\n\n\tif (await hasPermissionAsync(userId, 'manage-outgoing-integrations')) {\n\t\tintegration = await Integrations.findOneById<IIntegration>(integrationId);\n\t} else if (await hasPermissionAsync(userId, 'manage-own-outgoing-integrations')) {\n\t\tintegration = await Integrations.findOne<IIntegration>({\n\t\t\t'_id': integrationId,\n\t\t\t'_createdBy._id': userId,\n\t\t});\n\t} else {\n\t\tthrow new Meteor.Error('not_authorized', 'Unauthorized', { method: 'clearIntegrationHistory' });\n\t}\n\n\tif (!integration) {\n\t\tthrow new Meteor.Error('error-invalid-integration', 'Invalid integration', { method: 'clearIntegrationHistory' });\n\t}\n\n\tawait IntegrationHistory.removeByIntegrationId(integrationId);\n\n\tnotifications.streamIntegrationHistory.emit(integrationId, { type: 'removed', id: integrationId });\n};\n\nexport const replayOutgoingIntegrationMethod = async (\n\tuserId: string,\n\t{ integrationId, historyId }: { integrationId: string; historyId: string },\n): Promise<void> => {\n\tlet integration: IOutgoingIntegration | null = null;\n\n\tif (await hasPermissionAsync(userId, 'manage-outgoing-integrations')) {\n\t\tintegration = await Integrations.findOneById<IOutgoingIntegration>(integrationId);\n\t} else if (await hasPermissionAsync(userId, 'manage-own-outgoing-integrations')) {\n\t\tconst found = await Integrations.findOne<IOutgoingIntegration>({\n\t\t\t'_id': integrationId,","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/integrations/functions/clearIntegrationHistory.ts#L6-L42","documentation":"After the permission check, clearIntegrationHistory could not resolve the integration: with the full permission no document matched the _id, and with the own-permission no document matched both _id and _createdBy._id = userId. The throw happens before any history is removed.","triggerScenarios":"Passing a nonexistent integrationId, or an integration that exists but was created by someone else while the caller only holds manage-own-outgoing-integrations.","commonSituations":"Stale integration list in the UI after the integration was deleted; integration ids copied between environments; integration ownership changed.","solutions":["Verify the integration id in Administration > Integrations and re-select it fresh","With only the 'own' permission, use an integration you created — or request manage-outgoing-integrations"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const integration = (await hasPermissionAsync(userId, 'manage-outgoing-integrations'))\n  ? await Integrations.findOneById(integrationId)\n  : await Integrations.findOne({ '_id': integrationId, '_createdBy._id': userId });\nif (!integration) {\n  // integration missing or not owned: don't invoke the method\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Re-fetch the integration right before acting on it","Refresh integration lists after deletions so stale ids are never submitted"],"tags":["integrations","not-found"],"backgroundTag":"integration-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}