{"record":{"id":"3f01e1a9ffdfdba9","repo":"n8n-io/n8n","slug":"400-3f01e1","errorCode":"400","errorMessage":"Provider connection type cannot be changed. Create a new connection instead.","messagePattern":"Provider connection type cannot be changed\\. Create a new connection instead\\.","errorType":"exception","errorClass":"BadRequestError","httpStatus":400,"severity":"error","filePath":"packages/cli/src/credentials/credentials.service.ts","lineNumber":1053,"sourceCode":"\t\toptions: InstanceCredentialWriteOptions = {},\n\t): Promise<CredentialsEntity> {\n\t\tif (!hasGlobalScope(user, 'credential:manageInstance')) {\n\t\t\tthrow new ForbiddenError('You do not have permission to update provider connections');\n\t\t}\n\n\t\tconst credential = await this.credentialsRepository.findInstanceCredentialById(\n\t\t\tcredentialId,\n\t\t\tctx,\n\t\t);\n\t\tif (!credential) {\n\t\t\tthrow new NotFoundError(`Credential with ID \"${credentialId}\" could not be found.`);\n\t\t}\n\n\t\tconst prepared = await this.prepareUpdateData(user, data, credential, {\n\t\t\toperationContext: ctx,\n\t\t});\n\t\tif (prepared.type !== credential.type) {\n\t\t\tthrow new BadRequestError(\n\t\t\t\t'Provider connection type cannot be changed. Create a new connection instead.',\n\t\t\t);\n\t\t}\n\t\tconst decryptedData = prepared.data as unknown as ICredentialDataDecryptedObject;\n\t\tconst encrypted =\n\t\t\toptions.encryptedData ??\n\t\t\t(await this.createEncryptedData({\n\t\t\t\tid: credential.id,\n\t\t\t\tname: prepared.name,\n\t\t\t\ttype: prepared.type,\n\t\t\t\tdata: decryptedData,\n\t\t\t}));\n\t\tif (!options.skipExternalHooks) {\n\t\t\tawait this.externalHooks.run('credentials.update', [encrypted]);\n\t\t}\n\t\tconst hookedData = await this.getValidatedInstanceCredentialHookData(\n\t\t\tencrypted,\n\t\t\tcredential.id,","sourceCodeStart":1035,"sourceCodeEnd":1071,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/credentials/credentials.service.ts#L1035-L1071","documentation":"Thrown by CredentialsService.updateInstanceCredential when the prepared update data has a type different from the existing credential's type. Instance/provider connections are immutable in type: changing auth method (e.g. service-account -> OAuth) requires creating a new connection. This is the service-level duplicate of the controller-level check at credentials.controller.ts:266.","triggerScenarios":"Calling updateInstanceCredential with a body whose type differs from the stored credential.type — e.g. sending 'googleOAuth2Api' for a credential stored as 'googleApi'.","commonSituations":"Frontend reuses an edit form that allows type changes for project credentials against an instance credential. Migration script attempting to normalize credential types in place.","solutions":["Omit the type field from the update (keep the existing type).","If a different auth method is required, create a new instance credential of the new type and delete the old one.","Validate that body.type === credential.type before sending."],"exampleFix":"// before\nawait updateInstanceCredential(id, { type: 'googleOAuth2Api', ... });\n\n// after\nif (body.type && body.type !== existing.type) {\n  await createInstanceCredential({ type: body.type, ... });\n} else {\n  await updateInstanceCredential(id, { ...body, type: undefined });\n}","handlingStrategy":"validation","validationCode":"if (body.type && body.type !== existing.type) {\n  throw new Error('Type change not allowed for instance credentials — create new.');\n}\nconst patch = { ...body, type: existing.type };\nawait updateInstanceCredential(user, id, patch, ctx);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the type to the existing value when updating instance credentials.","Create a new credential to switch auth methods.","Disable type editing in the form for instance/provider connections."],"tags":["credentials","instance-credentials","validation","api"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}