{"record":{"id":"95d28dacfd8c3615","repo":"hcengineering/platform","slug":"target-workspace-not-found-or-not-accessible","errorCode":null,"errorMessage":"Target workspace not found or not accessible","messagePattern":"Target workspace not found or not accessible","errorType":"http","errorClass":"ApiError","httpStatus":404,"severity":"error","filePath":"services/export/pod-export/src/server.ts","lineNumber":519,"sourceCode":"        }\n        if (includeAttachments !== undefined && typeof includeAttachments !== 'boolean') {\n          measureCtx.warn(`Invalid includeAttachments: ${String(includeAttachments)}`)\n          throw new ApiError(400, 'Invalid includeAttachments. Must be boolean')\n        }\n\n        decodedToken = decodeToken(token)\n        if (decodedToken.extra?.readonly !== undefined) {\n          throw new ApiError(403, 'Forbidden: read-only token')\n        }\n\n        // Get target workspace info\n        const accountClient = getClient(envConfig.AccountsUrl, token)\n        const targetWsLoginInfo = await accountClient.getLoginWithWorkspaceInfo()\n\n        const targetWsInfo = targetWsLoginInfo.workspaces[targetWorkspace]\n        if (targetWsInfo === undefined) {\n          measureCtx.warn(`Target workspace not found or not accessible: ${targetWorkspace}`)\n          throw new ApiError(404, 'Target workspace not found or not accessible')\n        }\n\n        // Verify user has write access to target workspace\n        const isAdmin: boolean = decodedToken.extra?.admin === 'true'\n        if (!isAdmin && targetWsInfo.role !== AccountRole.Owner) {\n          measureCtx.warn(\n            `User does not have write access to target workspace: ${targetWorkspace}, role: ${targetWsInfo.role}`\n          )\n          throw new ApiError(403, 'You do not have write access to the target workspace. Owner role required.')\n        }\n\n        const targetWsIds: WorkspaceIds = {\n          uuid: targetWorkspace,\n          dataId: targetWsInfo.dataId,\n          url: targetWsInfo.url\n        }\n\n        const targetToken = generateToken(decodedToken.account, targetWorkspace, {","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/export/pod-export/src/server.ts#L501-L537","documentation":"The pod-export server looks up the target workspace by ID in the caller's workspace login info returned by the accounts service. This HTTP 404 error means `targetWsLoginInfo.workspaces[targetWorkspace]` was undefined — the authenticated user has no membership/visibility of that workspace, so export cannot proceed.","triggerScenarios":"Passing a targetWorkspace (workspace UUID) that does not exist, was deleted, or that the token's account is not a member of; calling getLoginWithWorkspaceInfo and finding no matching key in the workspaces map.","commonSituations":"Stale workspace IDs from old configs after a workspace was removed; typos in the UUID; exporting with a user account that was never invited to the destination workspace; environment mismatch (pointing at a workspace ID from another environment).","solutions":["Verify the target workspace UUID and that it still exists in the target environment.","Ensure the user behind the token is a member of the target workspace (accept the invite / add the account).","Call the accounts service getLoginWithWorkspaceInfo yourself and pick the ID from the returned workspaces map.","Check you are not mixing workspace IDs across environments/dev vs prod."],"exampleFix":"// before\ntargetWorkspace = '1234abcd-old-id'\n// after\nconst info = await accountClient.getLoginWithWorkspaceInfo()\ntargetWorkspace = Object.keys(info.workspaces).find(w => info.workspaces[w].url === 'target-ws-url')","handlingStrategy":"validation","validationCode":"const info = await accountClient.getLoginWithWorkspaceInfo()\nif (!(targetWorkspace in info.workspaces)) {\n  throw new Error(`Workspace ${targetWorkspace} not accessible to this account; available: ${Object.keys(info.workspaces).join(', ')}`)\n}","typeGuard":"function isAccessibleWorkspace(info: LoginWithWorkspaceInfo, wsId: string): boolean {\n  return info.workspaces[wsId] !== undefined\n}","tryCatchPattern":"try {\n  await exportPod({ targetWorkspace })\n} catch (err) {\n  if (err instanceof ApiError && err.status === 404 && /Target workspace/.test(err.message)) {\n    const info = await accountClient.getLoginWithWorkspaceInfo()\n    console.error(`Use one of: ${Object.keys(info.workspaces).join(', ')}`)\n  } else throw err\n}","preventionTips":["Resolve workspace IDs dynamically from getLoginWithWorkspaceInfo instead of hardcoding UUIDs.","Verify membership/invitation status of the service account in the target workspace.","Keep per-environment workspace configs and validate them at script startup."],"tags":["http-404","workspace","authorization"],"backgroundTag":"workspace-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}