calcom/cal.diy · error · NotFoundException

User with username "${username}" not found

Error message

User with username "${username}" not found

What it means

Thrown by EventTypesService_2024_04_15.getEventTypesPublicByUsername (GET /v2/event-types/:username/public) when usersRepository.findByUsername returns null — no user exists with that username. The endpoint is public/unauthenticated, so the username is the only key and a miss is a hard 404.

Source

Thrown at apps/api/v2/src/platform/event-types/event-types_2024_04_15/services/event-types.service.ts:112

    const eventType = await this.eventTypesRepository.getUserEventTypeForAtom(
      user,
      isUserOrganizationAdmin,
      eventTypeId
    );

    if (!eventType) {
      return null;
    }

    this.checkUserOwnsEventType(user.id, eventType.eventType);
    return eventType as { eventType: EventTypeOutput };
  }

  async getEventTypesPublicByUsername(username: string): Promise<EventTypesPublic> {
    const user = await this.usersRepository.findByUsername(username);
    if (!user) {
      throw new NotFoundException(`User with username "${username}" not found`);
    }

    return await getEventTypesPublic(user.id);
  }

  async createUserDefaultEventTypes(userId: number) {
    const { sixtyMinutes, sixtyMinutesVideo, thirtyMinutes, thirtyMinutesVideo } = DEFAULT_EVENT_TYPES;

    const defaultEventTypes = await Promise.all([
      this.eventTypesRepository.createUserEventType(userId, thirtyMinutes),
      this.eventTypesRepository.createUserEventType(userId, sixtyMinutes),
      this.eventTypesRepository.createUserEventType(userId, thirtyMinutesVideo),
      this.eventTypesRepository.createUserEventType(userId, sixtyMinutesVideo),
    ]);

    return defaultEventTypes;
  }

View on GitHub (pinned to 176037d0af)

Solutions

  1. Confirm the username via the authenticated GET /v2/event-types or the user profile endpoint before calling the public route.
  2. For organization users, supply the org context required by your deployment (subdomain or org query param).
  3. Normalize the username to lowercase only if the repository lookup is case-insensitive — otherwise preserve exact casing.
  4. Cache the list of valid usernames if you poll this endpoint frequently.

Example fix

// before
const list = await api.get(`/v2/event-types/${username}/public`);
// after
const profile = await api.get('/v2/me'); // confirms the authenticated user's username
if (profile.username !== username) throw new Error('username mismatch');
const list = await api.get(`/v2/event-types/${username}/public`);
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the username exists via an authenticated profile lookup
const me = await api.get('/v2/me');
if (me.username !== username) {
  // either wrong user or not the authenticated user — check source of `username`
  throw new Error(`username ${username} does not match an existing user`);
}

Type guard

function isUsernameString(v: unknown): v is string {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  return await api.get(`/v2/event-types/${username}/public`);
} catch (e) {
  if (e.response?.status === 404) {
    // no such user — prompt the user to correct the username
  } else throw e;
}

Prevention

When it happens

Trigger: GET /v2/event-types/janedoe/public where no user has username 'janedoe'; the username is correct but belongs to an organization and the org-scoped lookup requires a different path; username casing mismatch (the lookup may be case-sensitive depending on DB collation).

Common situations: Renamed or deleted users; typo in the username pulled from a URL or config; username includes the org prefix incorrectly; the user exists only in a different deployment (staging vs production).

Related errors


AI-assisted analysis of calcom/cal.diy@176037d0af (2026-08-12). Data as JSON: /api/errors/22fa330e329b15cb. Report an issue: GitHub.