{"record":{"id":"ec7cf78c08233aeb","repo":"calcom/cal.diy","slug":"user-with-username-input-username-not-found","errorCode":null,"errorMessage":"User with username ${input.username} not found","messagePattern":"User with username (.+?) not found","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"apps/api/v2/src/modules/slots/slots-2024-09-04/services/slots-input.service.ts","lineNumber":102,"sourceCode":"    const baseTransformation = await this.transformGetSlotsQuery(baseQuery);\n\n    return {\n      ...baseTransformation,\n      routedTeamMemberIds: routedTeamMemberIds || null,\n      skipContactOwner: skipContactOwner || false,\n      teamMemberEmail: teamMemberEmail || null,\n    };\n  }\n\n  private async getEventType(input: GetSlotsInput_2024_09_04) {\n    if (input.type === ById_2024_09_04_type) {\n      return this.eventTypeRepository.getEventTypeById(input.eventTypeId);\n    }\n\n    if (input.type === ByUsernameAndEventTypeSlug_2024_09_04_type) {\n      const user = await this.getEventTypeUser(input);\n      if (!user) {\n        throw new NotFoundException(`User with username ${input.username} not found`);\n      }\n      return this.eventTypeRepository.getUserEventTypeBySlug(user.id, input.eventTypeSlug);\n    }\n\n    if (input.type === ByTeamSlugAndEventTypeSlug_2024_09_04_type) {\n      const team = await this.getEventTypeTeam(input);\n      if (!team) {\n        throw new NotFoundException(`Team with slug ${input.teamSlug} not found`);\n      }\n      return this.teamsEventTypesRepository.getEventTypeByTeamIdAndSlug(team.id, input.eventTypeSlug);\n    }\n\n    return input.duration ? { ...dynamicEvent, length: input.duration } : dynamicEvent;\n  }\n\n  private async getEventTypeUser(input: ByUsernameAndEventTypeSlug_2024_09_04) {\n    return await this.usersRepository.findByUsername(input.username);\n  }","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/modules/slots/slots-2024-09-04/services/slots-input.service.ts#L84-L120","documentation":"A NestJS NotFoundException (HTTP 404) thrown by SlotsInputService_2024_09_04.getEventType when the request resolves an event type by username + event-type slug. The usersRepository.findByUsername(input.username) lookup returned null, so no user matches the supplied username. The error echoes the offending username so you can identify the bad reference.","triggerScenarios":"Calling GET /v2/slots/2024-09-04 with type === \"usernameAndEventTypeSlug\" where the `username` field does not match any user record (typo, deleted user, unverified account, wrong org scope, or username moved to an organization subdomain).","commonSituations":"Hardcoding a username in an integration that was later renamed or deleted; passing the user's email instead of their username; querying before the user finished sign-up; username lives under an org slug that was not supplied via organizationSlug.","solutions":["Verify the username exists in the Cal.com app under /users or via the users API before calling slots.","Confirm you are passing the `username` field (not email, not display name) and that it matches the user's profile slug exactly (case-sensitive).","If the user belongs to an organization, pass the correct organizationSlug so the lookup hits the right tenant.","Catch HTTP 404 in the client and surface a 'user not found' message to the end user with a prompt to re-check the link."],"exampleFix":"// before\nconst res = await fetch(`/v2/slots?username=${email}&eventTypeSlug=30min`);\n\n// after — use the actual username slug and validate first\nconst user = await calApi.getUserByUsername(username);\nif (!user) throw new ClientError(`Unknown username: ${username}`);\nconst res = await fetch(`/v2/slots?username=${encodeURIComponent(user.username)}&eventTypeSlug=30min`);","handlingStrategy":"validation","validationCode":"import { DateTime } from 'luxon';\n\nfunction assertUsernameResolvable(username: unknown): string {\n  if (typeof username !== 'string' || username.trim() === '') {\n    throw new TypeError('username must be a non-empty string');\n  }\n  // usernames are slugs — reject emails / display names early\n  if (/@\\s|\\s/.test(username)) {\n    throw new TypeError('Pass the username slug, not an email or display name');\n  }\n  return username.trim();\n}\n// Optional: confirm via GET /v2/users or the app before slots\nconst username = assertUsernameResolvable(input.username);\nconst user = await cal.users.getByUsername(username);\nif (!user) throw new ClientError(`User '${username}' not found`);","typeGuard":"function isByUsernameAndSlug(value: unknown): value is { username: string; eventTypeSlug: string } {\n  return typeof value === 'object' && value !== null\n    && typeof (value as any).username === 'string'\n    && typeof (value as any).eventTypeSlug === 'string';\n}","tryCatchPattern":"try {\n  await cal.slots.list({ type: 'usernameAndEventTypeSlug', username, eventTypeSlug, start, end });\n} catch (e) {\n  if (e instanceof HttpError && e.statusCode === 404) {\n    // user does not exist — re-prompt, don't retry blindly\n    throw new UserFacingError('Booking link is invalid — user not found');\n  }\n  throw e;\n}","preventionTips":["Resolve and cache the username from the user API rather than accepting free text.","Pass organizationSlug when the user belongs to an org.","URL-encode the username in query strings.","Treat 404 as terminal for that link — do not auto-retry the same username."],"tags":["calcom-api","slots","not-found","nest","username-lookup"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}