{"record":{"id":"b8e48b5dff74109a","repo":"calcom/cal.diy","slug":"user-with-username-body-username-not-found","errorCode":null,"errorMessage":"User with username ${body.username} not found","messagePattern":"User with username (.+?) not found","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"apps/api/v2/src/platform/bookings/2024-08-13/services/bookings.service.ts","lineNumber":194,"sourceCode":"      throw new UnauthorizedException(\n        \"checkBookingRequiresAuthentication - request must be authenticated by passing credentials belonging to event type owner, host or team or org admin or owner.\"\n      );\n    }\n\n    if (!userIsEventTypeAdminOrOwner) {\n      throw new ForbiddenException(\n        \"checkBookingRequiresAuthentication - user is not authorized to access this event type. User has to be either event type owner, host, team admin or owner or org admin or owner.\"\n      );\n    }\n  }\n\n  async getBookedEventType(body: CreateBookingInput) {\n    if (body.eventTypeId) {\n      return await this.eventTypesRepository.getEventTypeByIdWithOwnerAndTeam(body.eventTypeId);\n    } else if (body.username && body.eventTypeSlug) {\n      const user = await this.usersRepository.findByUsername(body.username, body.organizationSlug);\n      if (!user) {\n        throw new NotFoundException(`User with username ${body.username} not found`);\n      }\n      return await this.eventTypesRepository.getUserEventTypeBySlugWithOwnerAndTeam(\n        user.id,\n        body.eventTypeSlug\n      );\n    } else if (body.teamSlug && body.eventTypeSlug) {\n      const team = await this.getBookedEventTypeTeam(body.teamSlug);\n      if (!team) {\n        throw new NotFoundException(`Team with slug ${body.teamSlug} not found`);\n      }\n      return await this.teamsEventTypesRepository.getEventTypeByTeamIdAndSlugWithOwnerAndTeam(\n        team.id,\n        body.eventTypeSlug\n      );\n    }\n    return null;\n  }\n","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/platform/bookings/2024-08-13/services/bookings.service.ts#L176-L212","documentation":"Thrown in getBookedEventType when resolving an event type by username + eventTypeSlug (instead of eventTypeId) and usersRepository.findByUsername returns no user. The lookup is optionally scoped by organizationSlug, so a username existing in another org also misses. HTTP 404.","triggerScenarios":"POST /v2/bookings with body.username + body.eventTypeSlug where the username does not resolve to a user (or does not exist within the supplied organizationSlug).","commonSituations":"Typo in username; user renamed/deleted; organizationSlug mismatch (user exists but in a different org); cross-environment username; passing an email instead of the username.","solutions":["Verify the username exists (and within the correct organizationSlug) before booking.","If you have it, book by eventTypeId instead of username/eventTypeSlug to avoid username resolution.","Double-check spelling and that the value is the username, not the email or display name."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before booking by username/slug, confirm the user exists (within the org if applicable).\nconst user = await api.get(`/v2/users/${encodeURIComponent(username)}${orgSlug ? `?org=${orgSlug}` : ''}`).catch(() => null);\nif (!user) throw new Error(`Username ${username} not found${orgSlug ? ` in org ${orgSlug}` : ''}`);\n// Prefer booking by eventTypeId once known.","typeGuard":null,"tryCatchPattern":"try {\n  await api.post('/v2/bookings', { username, eventTypeSlug, organizationSlug });\n} catch (err) {\n  if (err.status === 404 && /username .* not found/.test(err.message)) {\n    // verify the username/org, or switch to booking by eventTypeId\n  }\n  throw err;\n}","preventionTips":["Verify the username exists (and in the right organizationSlug) before booking.","Prefer eventTypeId over username/eventTypeSlug when available.","Pass the username, not the email or display name."],"tags":["user","not-found","booking","event-type"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}