Skip to content

fix(api): add missing tRPC route handlers for apiKeys, payments, and filterSegments#29482

Closed
Suraj-kummar wants to merge 2 commits into
calcom:mainfrom
Suraj-kummar:fix/missing-trpc-api-routes
Closed

fix(api): add missing tRPC route handlers for apiKeys, payments, and filterSegments#29482
Suraj-kummar wants to merge 2 commits into
calcom:mainfrom
Suraj-kummar:fix/missing-trpc-api-routes

Conversation

@Suraj-kummar
Copy link
Copy Markdown

Summary

Fixes #29475

Three tRPC endpoints were listed in the ENDPOINTS array in packages/trpc/react/shared.ts but had no corresponding Next.js API route file, causing Next.js to return an HTML 404 page instead of a JSON tRPC response.

The tRPC client then tried to parse the HTML as JSON, producing:

Unexpected token '<', "<!DOCTYPE "... is not valid JSON

Root Cause

The tRPC client's resolveEndpoint() function maps a call like viewer.apiKeys.create (3 path segments) to the standalone endpoint /api/trpc/apiKeys/create. Since apiKeys (and payments, filterSegments) existed in ENDPOINTS but had no matching directory/[trpc].ts file under apps/web/pages/api/trpc/, Next.js returned a 404 HTML page.

Changes

New files

  • apps/web/pages/api/trpc/apiKeys/[trpc].ts — exposes apiKeysRouter (fixes the reported issue)
  • apps/web/pages/api/trpc/payments/[trpc].ts — exposes paymentsRouter
  • apps/web/pages/api/trpc/filterSegments/[trpc].ts — exposes filterSegmentsRouter

Fixed

  • apps/web/app/(use-page-wrapper)/settings/(settings-layout)/developer/api-keys/actions.ts — removed invalid second argument "max" from revalidateTag() (it only accepts one argument)

Testing

  1. Deploy a Cal.diy production build
  2. Go to /settings/developer/api-keys
  3. Click Create API Key -- should now succeed without the JSON parse error

PR Checklist

  • Title follows conventional commits
  • Biome lint passes
  • No secrets committed
  • Diff is small and focused (4 files, 13 insertions, 1 deletion)

Fixes critical parseInt misclassification bug, adds inviteEmail to Zod
schema, skips membership check for invite entries in eventOwnerProcedure,
swaps Select for CreatableSelect with (Invite) badge visual feedback.

Closes calcom#26850
…filterSegments

The tRPC client resolves viewer.apiKeys.*, viewer.payments.*, and
viewer.filterSegments.* calls to standalone endpoints at
/api/trpc/<endpoint>/[trpc] based on the ENDPOINTS array in
packages/trpc/react/shared.ts. These three endpoints were listed
in ENDPOINTS but had no corresponding Next.js API route file,
causing Next.js to return an HTML 404 page instead of JSON.

The tRPC client then tried to parse the HTML as JSON, producing:
  Unexpected token '<', "<!DOCTYPE "... is not valid JSON

Fixes: calcom#29475

Also fix revalidateTag call in api-keys/actions.ts which was
passing an invalid second argument "max" -- revalidateTag only
accepts a single string tag argument.
@github-actions
Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @Suraj-kummar! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

@github-actions github-actions Bot added the 🐛 bug Something isn't working label May 29, 2026
@bandhan-majumder
Copy link
Copy Markdown
Member

Thank you for your contributions. Going with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HIGH: API key creation returns HTML 404, causing Unexpected token '<' ... is not valid JSON

2 participants