{"record":{"id":"c5ad3e2def159671","repo":"calcom/cal.diy","slug":"getorgid-decorator-organization-id-not-found","errorCode":null,"errorMessage":"GetOrgId decorator: Organization ID not found","messagePattern":"GetOrgId decorator: Organization ID not found","errorType":"exception","errorClass":"UnauthorizedException","httpStatus":401,"severity":"error","filePath":"apps/api/v2/src/modules/auth/decorators/get-org-id/get-org-id.decorator.ts","lineNumber":8,"sourceCode":"import { createParamDecorator, ExecutionContext, UnauthorizedException } from \"@nestjs/common\";\n\nexport const GetOrgId = createParamDecorator((_: unknown, ctx: ExecutionContext): number => {\n  const request = ctx.switchToHttp().getRequest();\n  const organizationId = request.organizationId;\n\n  if (!organizationId) {\n    throw new UnauthorizedException(\"GetOrgId decorator: Organization ID not found\");\n  }\n\n  return organizationId;\n});\n","sourceCodeStart":1,"sourceCodeEnd":13,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/modules/auth/decorators/get-org-id/get-org-id.decorator.ts#L1-L13","documentation":"UnauthorizedException from the @GetOrgId() param decorator when request.organizationId is falsy at the time the route handler resolves. The decorator expects a prior middleware/guard to have attached organizationId onto the request; if none did, no org-scoped route can run. This is a wiring/config error, not a user-input error.","triggerScenarios":"Hitting any controller method that uses @GetOrgId() without an upstream OrganizationGuard/middleware (e.g. ParseOrgIdMiddleware) that sets req.organizationId — typically because the route module omits the guard, the org id header/param is missing, or the guard ran but set nothing.","commonSituations":"New route added with @GetOrgId() but the APP_GUARD or per-controller guard that populates organizationId isn't wired; the request path bypasses the org middleware (wrong module scope); test harness invokes the handler directly without simulating the middleware; orgId header was removed.","solutions":["Ensure the controller/module registers the guard or middleware that sets req.organizationId (e.g. OrganizationGuard / ParseOrgIdMiddleware) before the handler runs.","Confirm the client is sending the org-identifying header/param the middleware reads (e.g. cal-api-version, org slug, or path orgId).","In tests, mock req.organizationId on the ExecutionContext before invoking the handler."],"exampleFix":"// before — handler runs with no org guard\n@Get('members')\nas members(@GetOrgId() orgId: number) { ... }\n\n// after — ensure the guard populates request.organizationId first\n@UseGuards(OrganizationGuard)\n@Get('members')\nas members(@GetOrgId() orgId: number) { ... }","handlingStrategy":"validation","validationCode":"// In tests or middleware stacks, ensure req.organizationId is set\nconst orgId = request.organizationId;\nif (!orgId) throw new UnauthorizedException('GetOrgId decorator: Organization ID not found');","typeGuard":"function hasOrgIdOnRequest(req: unknown): req is { organizationId: number } {\n  return typeof req === 'object' && req !== null &&\n    typeof (req as any).organizationId === 'number' && (req as any).organizationId > 0;\n}","tryCatchPattern":null,"preventionTips":["Always pair @GetOrgId() with the guard/middleware that populates request.organizationId.","In unit tests, assign mockReq.organizationId before invoking the handler."],"tags":["auth","nestjs","decorator","organization","wiring"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}