:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(api): migrate remaining product API routes to product-local registration (#62089)
Julian Bezee1520217e8e
diff --git a/ee/urls.py b/ee/urls.pyindex 69ca8a93c24e..847f93480ecf 100644--- a/ee/urls.py+++ b/ee/urls.py@@ -23,25 +23,14 @@ from ee.api.vercel import vercel_connect, vercel_sso, vercel_webhooksfrom ee.middleware import admin_oauth2_callbackfrom ee.support_sidebar_max.views import MaxChatViewSet-from .api import (- authentication,- billing,- conversation,- core_memory,- dashboard_collaborator,- license,- sentry_stats,- subscription,-)+from .api import authentication, billing, conversation, core_memory, license, sentry_stats, subscriptionfrom .api.rbac import rolefrom .api.scim import views as scim_viewsdef extend_api_router() -> None:from posthog.api import (- environment_dashboards_router,environments_router,- legacy_project_dashboards_router,organizations_router,register_legacy_dual_route_team_nested_viewset,router as root_router,@@ -66,19 +55,6 @@ def extend_api_router() -> None:)register_legacy_dual_route_team_nested_viewset(r"hooks", hooks.HookViewSet, "environment_hooks", ["team_id"])- environment_dashboards_router.register(- r"collaborators",- dashboard_collaborator.DashboardCollaboratorViewSet,- "environment_dashboard_collaborators",- ["project_id", "dashboard_id"],- )- legacy_project_dashboards_router.register(- r"collaborators",- dashboard_collaborator.DashboardCollaboratorViewSet,- "project_dashboard_collaborators",- ["project_id", "dashboard_id"],- )-_, env_subscriptions_router = register_legacy_dual_route_team_nested_viewset(r"subscriptions", subscription.SubscriptionViewSet, "environment_subscriptions", ["team_id"])diff --git a/posthog/api/__init__.py b/posthog/api/__init__.pyindex 4c9528d0dcc7..5f0dc9bf6373 100644--- a/posthog/api/__init__.py+++ b/posthog/api/__init__.py@@ -18,17 +18,6 @@ from posthog.api.wizard import http as wizardfrom posthog.approvals import api as approval_apifrom posthog.settings import EE_AVAILABLE-import products.alerts.backend.api.alert as alert-from products.annotations.backend.api import annotation-from products.batch_exports.backend.api import (- batch_export as batch_exports,- file_download,-)-from products.dashboards.backend.api import dashboard, dashboard_templates-from products.exports.backend.api import exports-from products.managed_migrations.backend.api.batch_imports import BatchImportViewSet-from products.notebooks.backend.api.notebook import NotebookViewSet-from ee.api.quota_limits import QuotaLimitsViewSetfrom ee.api.session_summaries import SessionGroupSummaryViewSet, SingleSessionSummaryViewSetfrom ee.api.vercel import vercel_installation, vercel_product, vercel_proxy, vercel_resource@@ -104,19 +93,12 @@ router = DefaultRouterPlusPlus()routers = RouterRegistry()routers.set_root(router)-# Legacy endpoints shared (to be removed eventually)-router.register(r"dashboard", dashboard.LegacyDashboardsViewSet, "legacy_dashboards") # Should be completely unused now-router.register(- r"dashboard_item", dashboard.LegacyInsightViewSet, "legacy_insights"-) # To be deleted - unified into insight viewset-# Nested endpoints sharedprojects_router = routers.add("projects", router.register(r"projects", project.RootProjectViewSet, "projects"))projects_router.register(r"environments", team.ProjectEnvironmentsViewSet, "project_environments", ["project_id"])environments_router = routers.add("environments", router.register(r"environments", team.RootTeamViewSet, "environments"))-project_notebooks_router = projects_router.register(r"notebooks", NotebookViewSet, "project_notebooks", ["project_id"])def register_legacy_dual_route_team_nested_viewset(@@ -157,7 +139,6 @@ def register_legacy_dual_route_team_nested_viewset(return routers.register_legacy_dual_route(prefix, viewset, basename, parents_query_lookups)-projects_router.register(r"annotations", annotation.AnnotationsViewSet, "project_annotations", ["project_id"])projects_router.register(r"sdk_health", SdkHealthViewSet, "project_sdk_health", ["project_id"])projects_router.register(r"activity_log",@@ -192,17 +173,6 @@ projects_router.register(["team_id"],)-# product-local route registration via RouterRegistry).-projects_router.register(- r"dashboard_templates",- dashboard_templates.DashboardTemplateViewSet,- "project_dashboard_templates",- ["project_id"],-)-legacy_project_dashboards_router, environment_dashboards_router = register_legacy_dual_route_team_nested_viewset(- r"dashboards", dashboard.DashboardsViewSet, "environment_dashboards", ["team_id"]-)-register_legacy_dual_route_team_nested_viewset(r"column_configurations",ColumnConfigurationViewSet,@@ -232,9 +202,6 @@ register_legacy_dual_route_team_nested_viewset()-register_legacy_dual_route_team_nested_viewset(- r"exports", exports.ExportedAssetViewSet, "environment_exports", ["team_id"]-)register_legacy_dual_route_team_nested_viewset(r"integrations", integration.IntegrationViewSet, "environment_integrations", ["team_id"])@@ -307,38 +274,6 @@ register_legacy_dual_route_team_nested_viewset(["team_id"],)-legacy_project_batch_exports_router, environment_batch_exports_router = register_legacy_dual_route_team_nested_viewset(- r"batch_exports", batch_exports.BatchExportViewSet, "environment_batch_exports", ["team_id"]-)--register_legacy_dual_route_team_nested_viewset(- r"file_download_batch_exports",- file_download.FileDownloadBatchExportOnDemandViewSet,- "environment_file_download_batch_exports",- ["team_id"],-)--environment_batch_exports_router.register(- r"runs", batch_exports.BatchExportRunViewSet, "environment_batch_export_runs", ["team_id", "batch_export_id"]-)-legacy_project_batch_exports_router.register(- r"runs", batch_exports.BatchExportRunViewSet, "project_batch_export_runs", ["team_id", "batch_export_id"]-)--environment_batch_exports_router.register(- r"backfills",- batch_exports.BatchExportBackfillViewSet,- "environment_batch_export_backfills",- ["team_id", "batch_export_id"],-)-legacy_project_batch_exports_router.register(- r"backfills",- batch_exports.BatchExportBackfillViewSet,- "project_batch_export_backfills",- ["team_id", "batch_export_id"],-)--projects_router.register(r"event_definitions",event_definition.EventDefinitionViewSet,@@ -394,9 +329,6 @@ organizations_router.register("organization_oauth_applications",["organization_id"],)-organizations_router.register(- r"batch_exports", batch_exports.BatchExportOrganizationViewSet, "batch_exports", ["organization_id"]-)organizations_router.register(r"members",organization_member.OrganizationMemberViewSet,@@ -503,9 +435,6 @@ from posthog.api.event import EventViewSet, LegacyEventViewSet # noqa: E402from posthog.api.person import LegacyPersonViewSet, PersonViewSet # noqa: E402from posthog.api.web_experiment import WebExperimentViewSet # noqa: E402-from products.product_analytics.backend.api.insight import InsightViewSet # noqa: E402-from products.product_analytics.backend.api.insight_variable import InsightVariableViewSet # noqa: E402-# Legacy endpoints CH (to be removed eventually)router.register(r"cohort", LegacyCohortViewSet, basename="cohort")router.register(r"element", LegacyElementViewSet, basename="element")@@ -549,21 +478,9 @@ register_legacy_dual_route_team_nested_viewset(register_legacy_dual_route_team_nested_viewset(r"sessions", SessionViewSet, "environment_sessions", ["team_id"])if EE_AVAILABLE:- from products.experiments.backend.presentation.views import EnterpriseExperimentsViewSet-- from ee.clickhouse.views.experiment_holdouts import ExperimentHoldoutViewSet- from ee.clickhouse.views.experiment_saved_metrics import ExperimentSavedMetricViewSetfrom ee.clickhouse.views.groups import GroupsTypesViewSet, GroupsViewSet, GroupUsageMetricViewSet- from ee.clickhouse.views.insights import EnterpriseInsightsViewSetfrom ee.clickhouse.views.person import EnterprisePersonViewSet, LegacyEnterprisePersonViewSet- projects_router.register(r"experiments", EnterpriseExperimentsViewSet, "project_experiments", ["project_id"])- projects_router.register(- r"experiment_holdouts", ExperimentHoldoutViewSet, "project_experiment_holdouts", ["project_id"]- )- projects_router.register(- r"experiment_saved_metrics", ExperimentSavedMetricViewSet, "project_experiment_saved_metrics", ["project_id"]- )register_legacy_dual_route_team_nested_viewset(r"groups", GroupsViewSet, "environment_groups", ["team_id"])group_types_router = projects_router.register(r"groups_types", GroupsTypesViewSet, "project_groups_types", ["project_id"]@@ -571,9 +488,6 @@ if EE_AVAILABLE:group_types_router.register(r"metrics", GroupUsageMetricViewSet, "project_groups_metrics", ["project_id", "group_type_index"])- legacy_project_insights_router, environment_insights_router = register_legacy_dual_route_team_nested_viewset(- r"insights", EnterpriseInsightsViewSet, "environment_insights", ["team_id"]- )register_legacy_dual_route_team_nested_viewset(r"persons", EnterprisePersonViewSet, "environment_persons", ["team_id"])@@ -601,51 +515,11 @@ if EE_AVAILABLE:)else:- legacy_project_insights_router, environment_insights_router = register_legacy_dual_route_team_nested_viewset(- r"insights", InsightViewSet, "environment_insights", ["team_id"]- )register_legacy_dual_route_team_nested_viewset(r"persons", PersonViewSet, "environment_persons", ["team_id"])router.register(r"person", LegacyPersonViewSet, "persons")-environment_dashboards_router.register(- r"sharing",- sharing.SharingConfigurationViewSet,- "environment_dashboard_sharing",- ["team_id", "dashboard_id"],-)-legacy_project_dashboards_router.register(- r"sharing",- sharing.SharingConfigurationViewSet,- "project_dashboard_sharing",- ["team_id", "dashboard_id"],-)--environment_insights_router.register(- r"sharing",- sharing.SharingConfigurationViewSet,- "environment_insight_sharing",- ["team_id", "insight_id"],-)-legacy_project_insights_router.register(- r"sharing",- sharing.SharingConfigurationViewSet,- "project_insight_sharing",- ["team_id", "insight_id"],-)--environment_insights_router.register(- "thresholds",- alert.ThresholdViewSet,- "environment_insight_thresholds",- ["team_id", "insight_id"],-)-legacy_project_insights_router.register(- "thresholds",- alert.ThresholdViewSet,- "project_insight_thresholds",- ["team_id", "insight_id"],-)-+# session_recordings sharing nest stays central — the session_recordings viewsets+# still live under posthog/session_recordings/ rather than in a product folder.environment_sessions_recordings_router.register(r"sharing",sharing.SharingConfigurationViewSet,@@ -659,14 +533,6 @@ legacy_project_session_recordings_router.register(["team_id", "recording_id"],)--project_notebooks_router.register(- r"sharing",- sharing.SharingConfigurationViewSet,- "project_notebook_sharing",- ["project_id", "notebook_id"],-)-projects_router.register(r"session_group_summaries",SessionGroupSummaryViewSet,@@ -697,13 +563,6 @@ projects_router.register()-projects_router.register(- r"managed_migrations",- BatchImportViewSet,- "project_managed_migrations",- ["project_id"],-)-projects_router.register(r"hog",hog.HogViewSet,@@ -718,20 +577,6 @@ register_legacy_dual_route_team_nested_viewset(["team_id"],)-register_legacy_dual_route_team_nested_viewset(- r"insight_variables",- InsightVariableViewSet,- "environment_insight_variables",- ["team_id"],-)--register_legacy_dual_route_team_nested_viewset(- r"alerts",- alert.AlertViewSet,- "environment_alerts",- ["team_id"],-)-projects_router.register(r"search", search.SearchViewSet, "project_search", ["project_id"])register_legacy_dual_route_team_nested_viewset(diff --git a/products/alerts/backend/routes.py b/products/alerts/backend/routes.pynew file mode 100644index 000000000000..44ecb56fb5ec--- /dev/null+++ b/products/alerts/backend/routes.py@@ -0,0 +1,14 @@+from posthog.api.routing import RouterRegistry++import products.alerts.backend.api.alert as alert+++def register_routes(routers: RouterRegistry) -> None:+ routers.register_legacy_dual_route(+ r"alerts",+ alert.AlertViewSet,+ "environment_alerts",+ ["team_id"],+ )+ # ThresholdViewSet is registered as a sub-route under insights/<id>/thresholds+ # by products.product_analytics.backend.routes — it imports alert.ThresholdViewSet.diff --git a/products/annotations/backend/routes.py b/products/annotations/backend/routes.pynew file mode 100644index 000000000000..a91199fb9fdf--- /dev/null+++ b/products/annotations/backend/routes.py@@ -0,0 +1,7 @@+from posthog.api.routing import RouterRegistry++from products.annotations.backend.api import annotation+++def register_routes(routers: RouterRegistry) -> None:+ routers.projects.register(r"annotations", annotation.AnnotationsViewSet, "project_annotations", ["project_id"])diff --git a/products/batch_exports/backend/routes.py b/products/batch_exports/backend/routes.pynew file mode 100644index 000000000000..3af912a03662--- /dev/null+++ b/products/batch_exports/backend/routes.py@@ -0,0 +1,46 @@+from posthog.api.routing import RouterRegistry++from products.batch_exports.backend.api import (+ batch_export as batch_exports,+ file_download,+)+++def register_routes(routers: RouterRegistry) -> None:+ legacy_project_batch_exports_router, environment_batch_exports_router = routers.register_legacy_dual_route(+ r"batch_exports", batch_exports.BatchExportViewSet, "environment_batch_exports", ["team_id"]+ )++ routers.register_legacy_dual_route(+ r"file_download_batch_exports",+ file_download.FileDownloadBatchExportOnDemandViewSet,+ "environment_file_download_batch_exports",+ ["team_id"],+ )++ environment_batch_exports_router.register(+ r"runs", batch_exports.BatchExportRunViewSet, "environment_batch_export_runs", ["team_id", "batch_export_id"]+ )+ legacy_project_batch_exports_router.register(+ r"runs", batch_exports.BatchExportRunViewSet, "project_batch_export_runs", ["team_id", "batch_export_id"]+ )++ environment_batch_exports_router.register(+ r"backfills",+ batch_exports.BatchExportBackfillViewSet,+ "environment_batch_export_backfills",+ ["team_id", "batch_export_id"],+ )+ legacy_project_batch_exports_router.register(+ r"backfills",+ batch_exports.BatchExportBackfillViewSet,+ "project_batch_export_backfills",+ ["team_id", "batch_export_id"],+ )++ routers.organizations.register(+ r"batch_exports",+ batch_exports.BatchExportOrganizationViewSet,+ "batch_exports",+ ["organization_id"],+ )diff --git a/products/dashboards/backend/routes.py b/products/dashboards/backend/routes.pynew file mode 100644index 000000000000..da162d5e4d15--- /dev/null+++ b/products/dashboards/backend/routes.py@@ -0,0 +1,56 @@+from posthog.api import sharing+from posthog.api.routing import RouterRegistry+from posthog.settings import EE_AVAILABLE++from products.dashboards.backend.api import dashboard, dashboard_templates+++def register_routes(routers: RouterRegistry) -> None:+ # Legacy flat endpoints — should be unused, but kept until callers are confirmed dead.+ routers.root.register(r"dashboard", dashboard.LegacyDashboardsViewSet, "legacy_dashboards")+ routers.root.register(r"dashboard_item", dashboard.LegacyInsightViewSet, "legacy_insights")++ routers.projects.register(+ r"dashboard_templates",+ dashboard_templates.DashboardTemplateViewSet,+ "project_dashboard_templates",+ ["project_id"],+ )++ legacy_project_dashboards_router, environment_dashboards_router = routers.register_legacy_dual_route(+ r"dashboards", dashboard.DashboardsViewSet, "environment_dashboards", ["team_id"]+ )++ # SharingConfigurationViewSet is shared (core), but the route lives under+ # dashboards/<id>/sharing — the dashboards product owns the sub-route.+ environment_dashboards_router.register(+ r"sharing",+ sharing.SharingConfigurationViewSet,+ "environment_dashboard_sharing",+ ["team_id", "dashboard_id"],+ )+ legacy_project_dashboards_router.register(+ r"sharing",+ sharing.SharingConfigurationViewSet,+ "project_dashboard_sharing",+ ["team_id", "dashboard_id"],+ )++ # EE-only collaborator sub-route. Previously registered in ee/urls.py against+ # the (now product-local) dashboards routers — co-locating it here removes+ # ee/urls.py's coupling to dashboards' router handles.+ if EE_AVAILABLE:+ from ee.api import dashboard_collaborator++ environment_dashboards_router.register(+ r"collaborators",+ dashboard_collaborator.DashboardCollaboratorViewSet,+ "environment_dashboard_collaborators",+ ["project_id", "dashboard_id"],+ )+ legacy_project_dashboards_router.register(+ r"collaborators",+ dashboard_collaborator.DashboardCollaboratorViewSet,+ "project_dashboard_collaborators",+ ["project_id", "dashboard_id"],+ )diff --git a/products/experiments/backend/routes.py b/products/experiments/backend/routes.pynew file mode 100644index 000000000000..926772c543a0--- /dev/null+++ b/products/experiments/backend/routes.py@@ -0,0 +1,23 @@+from posthog.api.routing import RouterRegistry+from posthog.settings import EE_AVAILABLE+++def register_routes(routers: RouterRegistry) -> None:+ # All experiments viewsets currently live in `ee/clickhouse/views/` and+ # `products/experiments/backend/presentation/views.py` — both unavailable+ # without EE installed, so the entire surface is EE-gated.+ if not EE_AVAILABLE:+ return++ from products.experiments.backend.presentation.views import EnterpriseExperimentsViewSet++ from ee.clickhouse.views.experiment_holdouts import ExperimentHoldoutViewSet+ from ee.clickhouse.views.experiment_saved_metrics import ExperimentSavedMetricViewSet++ routers.projects.register(r"experiments", EnterpriseExperimentsViewSet, "project_experiments", ["project_id"])+ routers.projects.register(+ r"experiment_holdouts", ExperimentHoldoutViewSet, "project_experiment_holdouts", ["project_id"]+ )+ routers.projects.register(+ r"experiment_saved_metrics", ExperimentSavedMetricViewSet, "project_experiment_saved_metrics", ["project_id"]+ )diff --git a/products/exports/backend/routes.py b/products/exports/backend/routes.pynew file mode 100644index 000000000000..17937daf0e85--- /dev/null+++ b/products/exports/backend/routes.py@@ -0,0 +1,7 @@+from posthog.api.routing import RouterRegistry++from products.exports.backend.api import exports+++def register_routes(routers: RouterRegistry) -> None:+ routers.register_legacy_dual_route(r"exports", exports.ExportedAssetViewSet, "environment_exports", ["team_id"])diff --git a/products/managed_migrations/backend/routes.py b/products/managed_migrations/backend/routes.pynew file mode 100644index 000000000000..c00c9c695b11--- /dev/null+++ b/products/managed_migrations/backend/routes.py@@ -0,0 +1,12 @@+from posthog.api.routing import RouterRegistry++from products.managed_migrations.backend.api.batch_imports import BatchImportViewSet+++def register_routes(routers: RouterRegistry) -> None:+ routers.projects.register(+ r"managed_migrations",+ BatchImportViewSet,+ "project_managed_migrations",+ ["project_id"],+ )diff --git a/products/notebooks/backend/routes.py b/products/notebooks/backend/routes.pynew file mode 100644index 000000000000..ebf868ca22a4--- /dev/null+++ b/products/notebooks/backend/routes.py@@ -0,0 +1,19 @@+from posthog.api import sharing+from posthog.api.routing import RouterRegistry++from products.notebooks.backend.api.notebook import NotebookViewSet+++def register_routes(routers: RouterRegistry) -> None:+ project_notebooks_router = routers.projects.register(+ r"notebooks", NotebookViewSet, "project_notebooks", ["project_id"]+ )++ # SharingConfigurationViewSet is shared (core), but the route lives under+ # notebooks/<id>/sharing — the notebooks product owns the sub-route.+ project_notebooks_router.register(+ r"sharing",+ sharing.SharingConfigurationViewSet,+ "project_notebook_sharing",+ ["project_id", "notebook_id"],+ )diff --git a/products/product_analytics/backend/routes.py b/products/product_analytics/backend/routes.pynew file mode 100644index 000000000000..51c7c6c0d4c2--- /dev/null+++ b/products/product_analytics/backend/routes.py@@ -0,0 +1,60 @@+from posthog.api import sharing+from posthog.api.routing import RouterRegistry+from posthog.settings import EE_AVAILABLE++import products.alerts.backend.api.alert as alert+from products.product_analytics.backend.api.insight import InsightViewSet+from products.product_analytics.backend.api.insight_variable import InsightVariableViewSet+++def register_routes(routers: RouterRegistry) -> None:+ # EE installs override the insights viewset with EnterpriseInsightsViewSet.+ # The non-EE InsightViewSet is the fallback. Either way, the route name and+ # nested sub-routes (sharing, thresholds) stay identical.+ insights_viewset: type[InsightViewSet]+ if EE_AVAILABLE:+ from ee.clickhouse.views.insights import EnterpriseInsightsViewSet++ insights_viewset = EnterpriseInsightsViewSet+ else:+ insights_viewset = InsightViewSet++ legacy_project_insights_router, environment_insights_router = routers.register_legacy_dual_route(+ r"insights", insights_viewset, "environment_insights", ["team_id"]+ )++ # SharingConfigurationViewSet is shared (core); the route lives under+ # insights/<id>/sharing — product_analytics owns the sub-route.+ environment_insights_router.register(+ r"sharing",+ sharing.SharingConfigurationViewSet,+ "environment_insight_sharing",+ ["team_id", "insight_id"],+ )+ legacy_project_insights_router.register(+ r"sharing",+ sharing.SharingConfigurationViewSet,+ "project_insight_sharing",+ ["team_id", "insight_id"],+ )++ # ThresholdViewSet is owned by the alerts product but nests under insights.+ environment_insights_router.register(+ "thresholds",+ alert.ThresholdViewSet,+ "environment_insight_thresholds",+ ["team_id", "insight_id"],+ )+ legacy_project_insights_router.register(+ "thresholds",+ alert.ThresholdViewSet,+ "project_insight_thresholds",+ ["team_id", "insight_id"],+ )++ routers.register_legacy_dual_route(+ r"insight_variables",+ InsightVariableViewSet,+ "environment_insight_variables",+ ["team_id"],+ )