{"record":{"id":"a7fdb8abdfebe89c","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-integration-a7fdb8","errorCode":"error-invalid-integration","errorMessage":"Invalid integration","messagePattern":"Invalid integration","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/integrations/incoming/updateIncomingIntegration.ts","lineNumber":68,"sourceCode":"\tconst channels = validateChannels(integration.channel);\n\n\tlet currentIntegration;\n\n\tif (await hasPermissionAsync(userId, 'manage-incoming-integrations')) {\n\t\tcurrentIntegration = await Integrations.findOneById(integrationId);\n\t} else if (await hasPermissionAsync(userId, 'manage-own-incoming-integrations')) {\n\t\tcurrentIntegration = await Integrations.findOne({\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', {\n\t\t\tmethod: 'updateIncomingIntegration',\n\t\t});\n\t}\n\n\tif (!currentIntegration) {\n\t\tthrow new Meteor.Error('error-invalid-integration', 'Invalid integration', {\n\t\t\tmethod: 'updateIncomingIntegration',\n\t\t});\n\t}\n\n\tconst oldScriptEngine = currentIntegration.scriptEngine;\n\tconst scriptEngine = integration.scriptEngine ?? oldScriptEngine ?? 'isolated-vm';\n\tif (\n\t\tintegration.script?.trim() &&\n\t\t(scriptEngine !== oldScriptEngine || integration.script?.trim() !== currentIntegration.script?.trim())\n\t) {\n\t\twrapExceptions(() => validateScriptEngine(scriptEngine)).catch((e) => {\n\t\t\tthrow new Meteor.Error(e.message);\n\t\t});\n\t}\n\n\tconst isFrozen = isScriptEngineFrozen(scriptEngine);\n\n\t// Default to transpiling with Babel for backwards compatibility; integrations","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/integrations/incoming/updateIncomingIntegration.ts#L50-L86","documentation":"Thrown by updateIncomingIntegration when the current integration record cannot be loaded. With 'manage-incoming-integrations' the lookup is Integrations.findOneById(integrationId); with 'manage-own-incoming-integrations' it additionally filters '_createdBy._id': userId. So it fires for a nonexistent id, an already-deleted integration, or an existing integration created by somebody else while the caller holds only the manage-own permission.","triggerScenarios":"Updating with a stale id after the integration was deleted elsewhere; manage-own user editing a teammate's webhook; id copied with a typo or trailing whitespace.","commonSituations":"Two admins editing concurrently (one deletes, the other saves); integrations list screens holding stale data after a workspace restore; cross-team ownership boundaries.","solutions":["Re-fetch the integration list (GET /api/v1/integrations.list) and confirm the id still exists before updating","If you hold only manage-own, edit only integrations you created; route other edits through an admin","Treat as 'already removed' and refresh the UI if the record was deleted concurrently"],"exampleFix":"// before\nawait Meteor.callAsync('updateIncomingIntegration', staleId, payload); // -> error-invalid-integration\n// after\nconst fresh = await Meteor.callAsync('listIncomingIntegrations');\nconst current = fresh.integrations?.find((i) => i._id === integrationId);\nif (current) await Meteor.callAsync('updateIncomingIntegration', current._id, { ...payload, channel: current.channel.join(',') });","handlingStrategy":"validation","validationCode":"const { integrations } = await Meteor.callAsync('listIncomingIntegrations');\nconst target = integrations.find((i) => i._id === integrationId);\nif (!target) throw new Error('integration missing or not owned by caller');\nawait Meteor.callAsync('updateIncomingIntegration', integrationId, { ...integration, channel: integration.channel ?? target.channel.join(',') });","typeGuard":null,"tryCatchPattern":"try {\n  await Meteor.callAsync('updateIncomingIntegration', integrationId, integration);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-invalid-integration') { /* refresh list; record deleted or owned by someone else */ }\n}","preventionTips":["Refresh the record before editing (optimistic-concurrency style)","For manage-own users, filter lists to createdBy = current user","Copy ids programmatically, never by hand"],"tags":["rocket-chat","incoming-integration","not-found","meteor-method"],"backgroundTag":"integration-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}