{"record":{"id":"2eb8769b2f678430","repo":"n8n-io/n8n","slug":"404-2eb876","errorCode":"404","errorMessage":"Credential not found","messagePattern":"Credential not found","errorType":"exception","errorClass":"NotFoundError","httpStatus":404,"severity":"error","filePath":"packages/cli/src/credentials/credentials.service.ee.ts","lineNumber":53,"sourceCode":"\t\tprivate readonly credentialsFinderService: CredentialsFinderService,\n\t\tprivate readonly roleService: RoleService,\n\t\tprivate readonly externalSecretsConfig: ExternalSecretsConfig,\n\t\tprivate readonly externalSecretsProviderAccessCheckService: SecretsProviderAccessCheckService,\n\t\tprivate readonly licenseState: LicenseState,\n\t\tprivate readonly connectionStatusProxy: CredentialConnectionStatusProxy,\n\t) {}\n\n\tasync shareWithProjects(\n\t\tuser: User,\n\t\tcredentialId: string,\n\t\tshareWithIds: string[],\n\t\tentityManager?: EntityManager,\n\t) {\n\t\tconst em = entityManager ?? this.sharedCredentialsRepository.manager;\n\t\tconst canShare = await em.exists(CredentialsEntity, {\n\t\t\twhere: { id: credentialId, usageScope: 'project' },\n\t\t});\n\t\tif (!canShare) throw new NotFoundError('Credential not found');\n\n\t\tconst roles = await this.roleService.rolesWithScope('project', ['project:list']);\n\n\t\tlet projects = await em.find(Project, {\n\t\t\twhere: [\n\t\t\t\t{\n\t\t\t\t\tid: In(shareWithIds),\n\t\t\t\t\ttype: 'team',\n\t\t\t\t\t// if user can see all projects, don't check project access\n\t\t\t\t\t// if they can't, find projects they can list\n\t\t\t\t\t...(hasGlobalScope(user, 'project:list')\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tprojectRelations: {\n\t\t\t\t\t\t\t\t\tuserId: user.id,\n\t\t\t\t\t\t\t\t\trole: In(roles),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}),","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/credentials/credentials.service.ee.ts#L35-L71","documentation":"Thrown by EnterpriseCredentialsService.shareWithProjects when em.exists(CredentialsEntity, { id: credentialId, usageScope: 'project' }) is false. The credential either does not exist at all or is an instance (provider) credential (usageScope !== 'project'), which cannot be shared with projects via this path.","triggerScenarios":"Calling shareWithProjects with a credentialId that is missing or whose usageScope is 'instance'. Typically reached transitively through PUT /credentials/:id/share when the credential was converted to an instance credential or deleted.","commonSituations":"Race between a share request and a delete/transfer. Attempting to share an instance/provider connection as if it were a project credential.","solutions":["Confirm the credentialId exists and usageScope === 'project' before sharing.","If the credential is an instance credential, use the instance-credential management path instead.","Reload the credential list to discard stale IDs."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const cred = await axios.get(`/credentials/${id}`).then(r => r.data).catch(() => null);\nif (!cred || cred.usageScope !== 'project') {\n  throw new Error('Only project-scoped credentials can be shared with projects.');\n}\nawait shareWithProjects(user, id, projectIds);","typeGuard":"function isProjectCredential(c: { usageScope?: string }): boolean {\n  return c?.usageScope === 'project';\n}","tryCatchPattern":null,"preventionTips":["Share only project-scoped credentials via shareWithProjects.","Route instance/provider connections through instance-credential endpoints.","Refresh the credential list if a 404 appears mid-share (deleted concurrently)."],"tags":["credentials","sharing","instance-credentials","enterprise"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}