Skip to content

Scheduling infrastructure for absolutely everyone.

refactor: companion event type query parameters (#27125)

Dhairyashil Shindea63bf11c3fe1
diff --git a/companion/extension/entrypoints/background/index.ts b/companion/extension/entrypoints/background/index.ts
index 203a6a445e1..db4af166fac 100644
--- a/companion/extension/entrypoints/background/index.ts
+++ b/companion/extension/entrypoints/background/index.ts
@@ -933,34 +933,9 @@ async function getAuthHeader(): Promise<string> {
async function fetchEventTypes(): Promise<unknown[]> {
const authHeader = await getAuthHeader();
- const userResponse = await fetchWithTimeout(`${API_BASE_URL}/me`, {
- headers: {
- Authorization: authHeader,
- "Content-Type": "application/json",
- "cal-api-version": "2024-06-11",
- },
- });
-
- if (!userResponse.ok) {
- throw new Error(`Failed to get user: ${userResponse.statusText}`);
- }
-
- const userData = await userResponse.json();
- const username = userData?.data?.username as string | undefined;
- // For org users, include org slug to avoid username collisions across orgs
- const orgSlug = userData?.data?.organization?.slug as string | undefined;
-
- const params = new URLSearchParams();
- if (username) {
- params.append("username", username);
- }
- if (orgSlug) {
- params.append("orgSlug", orgSlug);
- }
- const queryString = params.toString();
- const endpoint = `${API_BASE_URL}/event-types${queryString ? `?${queryString}` : ""}`;
-
- const response = await fetchWithTimeout(endpoint, {
+ // For authenticated users, no username/orgSlug params needed - API uses auth token
+ // This also ensures hidden event types are returned (they're filtered out when username is provided)
+ const response = await fetchWithTimeout(`${API_BASE_URL}/event-types`, {
headers: {
Authorization: authHeader,
"Content-Type": "application/json",
diff --git a/companion/services/calcom.ts b/companion/services/calcom.ts
index be26d6e4583..422233c13aa 100644
--- a/companion/services/calcom.ts
+++ b/companion/services/calcom.ts
@@ -862,36 +862,10 @@ async function getTranscripts(bookingUid: string): Promise<BookingTranscript[]>
}
async function getEventTypes(): Promise<EventType[]> {
- // Get cached user profile to extract username and org slug (uses in-flight deduplication)
- let username: string | undefined;
- let orgSlug: string | undefined;
- try {
- const userProfile = await getUserProfile();
- // Extract username from response
- if (userProfile?.username) {
- username = userProfile.username;
- }
- // For org users, include org slug to avoid username collisions across orgs
- if (userProfile?.organization?.slug) {
- orgSlug = userProfile.organization.slug;
- }
- } catch (_error) {}
-
- // Build query string with username, orgSlug, and sorting
- const params = new URLSearchParams();
- if (username) {
- params.append("username", username);
- }
- if (orgSlug) {
- params.append("orgSlug", orgSlug);
- }
+ // For authenticated users, no username/orgSlug params needed - API uses auth token
+ // This also ensures hidden event types are returned (they're filtered out when username is provided)
// Sort by creation date descending (newer first) to match main codebase behavior
- // Main codebase uses position: "desc", id: "desc" - since API doesn't expose position,
- // we use sortCreatedAt: "desc" for similar behavior (newer event types first)
- params.append("sortCreatedAt", "desc");
-
- const queryString = params.toString();
- const endpoint = `/event-types${queryString ? `?${queryString}` : ""}`;
+ const endpoint = `/event-types?sortCreatedAt=desc`;
const response = await makeRequest<unknown>(endpoint, {}, "2024-06-14");