: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: Add list endpoint for file download batch exports (#60247)
Tomás Farías Santana5197bf72254a
diff --git a/posthog/batch_exports/api/file_download.py b/posthog/batch_exports/api/file_download.pyindex e53da14ffa17..b9f9273b7681 100644--- a/posthog/batch_exports/api/file_download.py+++ b/posthog/batch_exports/api/file_download.py@@ -148,6 +148,16 @@ class CreateOutputSerializer(serializers.Serializer):id = serializers.UUIDField()+class ListOutputSerializer(serializers.Serializer):+ """Typed output for view set `list`."""++ id = serializers.UUIDField(help_text="ID of the file download batch export run.")+ status = serializers.ChoiceField(+ choices=BatchExportRun.Status.choices,+ help_text="Current status of the file download batch export run.",+ )++class RetrieveBasicOutputSerializer(serializers.Serializer):"""Typed output for view set `retrieve` with any of the statuses without extra output."""@@ -193,7 +203,12 @@ class TooManyConcurrentFileDownloads(APIException):@extend_schema(tags=["batch_exports"])class FileDownloadBatchExportOnDemandViewSet(- TeamAndOrgViewSetMixin, LogEntryMixin, mixins.CreateModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet+ TeamAndOrgViewSetMixin,+ LogEntryMixin,+ mixins.CreateModelMixin,+ mixins.RetrieveModelMixin,+ mixins.ListModelMixin,+ viewsets.GenericViewSet,):scope_object = "batch_export"queryset = (@@ -208,6 +223,12 @@ class FileDownloadBatchExportOnDemandViewSet(# Not linked directly with a team, we need to go through batch exportfilter_rewrite_rules = {"team_id": "batch_export_on_demand__team_id"}+ def get_serializer_class(self) -> type[serializers.Serializer]:+ if self.action == "list":+ return ListOutputSerializer++ return FileDownloadBatchExportOnDemandSerializer+@extend_schema(request=PolymorphicProxySerializer(component_name="CreateFileDownloadRequest",@@ -297,7 +318,7 @@ class FileDownloadBatchExportOnDemandViewSet(},)def retrieve(self, *args, **kwargs) -> response.Response:- """Get a run of a batch export on demand.+ """Get a batch export on demand run.If the underlying batch export run has completed, we return keys to thegenerated file downloads so that users may download them by making a requestdiff --git a/posthog/settings/web.py b/posthog/settings/web.pyindex afe9edadf6f3..f149c470a4cf 100644--- a/posthog/settings/web.py+++ b/posthog/settings/web.py@@ -471,6 +471,7 @@ SPECTACULAR_SETTINGS = {"ObservationTriggerEnum": "products.replay_vision.backend.models.replay_observation.ObservationTrigger","AutonomyPriorityEnum": "products.signals.backend.models.AutonomyPriority","UserInterviewSearchDocumentTypeEnum": "products.user_interviews.backend.facade.enums.SEARCH_DOCUMENT_TYPES",+ "BatchExportRunStatusEnum": "posthog.batch_exports.models.BatchExportRun.Status",# --- Inline value lists (type-hint enums, no x-spec-enum-id) ---"PropertyGroupOperator": ["AND", "OR"],"PropertyFilterTypeEnum": [diff --git a/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_api.py b/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_api.pyindex be035e0137db..6afb753f8552 100644--- a/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_api.py+++ b/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_api.py@@ -359,6 +359,50 @@ async def test_file_download_create_rejects_when_concurrency_limit_reached(mock_start.assert_not_called()[email protected]_db(transaction=True)+async def test_file_download_list_returns_run_ids_and_statuses(+ async_client: AsyncClient,+ team,+ user,+ data_interval_start,+ data_interval_end,+):+ destination = await BatchExportDestination.objects.acreate(+ type=BatchExportDestination.Destination.FILE_DOWNLOAD, config={}+ )+ with team_scope(team_id=team.pk, canonical=True):+ batch_export = await BatchExportOnDemand.objects.acreate(team=team, destination=destination, model="events")+ running_run = await BatchExportRun.objects.acreate(+ batch_export_on_demand=batch_export,+ data_interval_start=data_interval_start,+ data_interval_end=data_interval_end,+ status=BatchExportRun.Status.RUNNING,+ )+ completed_run = await BatchExportRun.objects.acreate(+ batch_export_on_demand=batch_export,+ data_interval_start=data_interval_start,+ data_interval_end=data_interval_end,+ status=BatchExportRun.Status.COMPLETED,+ )++ running_run.created_at = dt.datetime(2026, 1, 1, 1, 1, 0, tzinfo=dt.UTC)+ await running_run.asave(update_fields=["created_at"])+ completed_run.created_at = dt.datetime(2026, 1, 1, 1, 1, 1, tzinfo=dt.UTC)+ await completed_run.asave(update_fields=["created_at"])++ await async_client.aforce_login(user)++ response = await async_client.get(f"/api/projects/{team.pk}/file_download_batch_exports")++ assert response.status_code == status.HTTP_200_OK, response.json()+ data = response.json()+ assert data["count"] == 2+ assert data["results"] == [+ {"id": str(completed_run.id), "status": BatchExportRun.Status.COMPLETED},+ {"id": str(running_run.id), "status": BatchExportRun.Status.RUNNING},+ ]++@pytest.mark.usefixtures("override_file_download_settings")@pytest.mark.django_db(transaction=True)async def test_file_download_end_to_end(diff --git a/products/batch_exports/frontend/generated/api.schemas.ts b/products/batch_exports/frontend/generated/api.schemas.tsindex c6065bd245ae..449e7019fb57 100644--- a/products/batch_exports/frontend/generated/api.schemas.ts+++ b/products/batch_exports/frontend/generated/api.schemas.ts@@ -1295,6 +1295,36 @@ export interface PatchedBatchExportRequestApi {offset_hour?: number | null}+/**+ * Typed output for view set `list`.+ */+export interface ListOutputApi {+ /** ID of the file download batch export run. */+ id: string+ /** Current status of the file download batch export run.++ * `Cancelled` - Cancelled+ * `Completed` - Completed+ * `ContinuedAsNew` - Continued As New+ * `Failed` - Failed+ * `FailedRetryable` - Failed Retryable+ * `FailedBilling` - Failed Billing+ * `Terminated` - Terminated+ * `TimedOut` - Timedout+ * `Running` - Running+ * `Starting` - Starting */+ status: BatchExportRunStatusEnumApi+}++export interface PaginatedListOutputListApi {+ count: number+ /** @nullable */+ next?: string | null+ /** @nullable */+ previous?: string | null+ results: ListOutputApi[]+}+/*** Typed configuration for a FileDownload batch-export destination.*/@@ -1665,6 +1695,17 @@ export type BatchExportsLogsRetrieveParams = {search?: string}+export type FileDownloadBatchExportsListParams = {+ /**+ * Number of results to return per page.+ */+ limit?: number+ /**+ * The initial index from which to return the results.+ */+ offset?: number+}+export type FileDownloadBatchExportsLogsRetrieveParams = {/*** Only return entries after this ISO 8601 timestamp.diff --git a/products/batch_exports/frontend/generated/api.ts b/products/batch_exports/frontend/generated/api.tsindex 2d3c00574a18..1786b484fc03 100644--- a/products/batch_exports/frontend/generated/api.ts+++ b/products/batch_exports/frontend/generated/api.ts@@ -21,10 +21,12 @@ import type {CreateFileDownloadRequestApi,CreateOutputApi,FileDownloadBatchExportOnDemandApi,+ FileDownloadBatchExportsListParams,FileDownloadBatchExportsLogsRetrieveParams,PaginatedBatchExportBackfillListApi,PaginatedBatchExportListApi,PaginatedBatchExportRunListApi,+ PaginatedListOutputListApi,PatchedBatchExportRequestApi,RetrieveFileDownloadResponseApi,} from './api.schemas'@@ -505,6 +507,33 @@ export const batchExportsTestRetrieve = async (projectId: string, options?: Requ})}+export const getFileDownloadBatchExportsListUrl = (projectId: string, params?: FileDownloadBatchExportsListParams) => {+ const normalizedParams = new URLSearchParams()++ Object.entries(params || {}).forEach(([key, value]) => {+ if (value !== undefined) {+ normalizedParams.append(key, value === null ? 'null' : value.toString())+ }+ })++ const stringifiedParams = normalizedParams.toString()++ return stringifiedParams.length > 0+ ? `/api/projects/${projectId}/file_download_batch_exports/?${stringifiedParams}`+ : `/api/projects/${projectId}/file_download_batch_exports/`+}++export const fileDownloadBatchExportsList = async (+ projectId: string,+ params?: FileDownloadBatchExportsListParams,+ options?: RequestInit+): Promise<PaginatedListOutputListApi> => {+ return apiMutator<PaginatedListOutputListApi>(getFileDownloadBatchExportsListUrl(projectId, params), {+ ...options,+ method: 'GET',+ })+}+export const getFileDownloadBatchExportsCreateUrl = (projectId: string) => {return `/api/projects/${projectId}/file_download_batch_exports/`}@@ -530,7 +559,7 @@ export const getFileDownloadBatchExportsRetrieveUrl = (projectId: string, id: st}/**- * Get a run of a batch export on demand.+ * Get a batch export on demand run.If the underlying batch export run has completed, we return keys to thegenerated file downloads so that users may download them by making a requestdiff --git a/products/batch_exports/mcp/tools.yaml b/products/batch_exports/mcp/tools.yamlindex 745e67d677d4..0227162d6be1 100644--- a/products/batch_exports/mcp/tools.yaml+++ b/products/batch_exports/mcp/tools.yaml@@ -208,6 +208,9 @@ tools:file-download-batch-exports-download-retrieve:operation: file_download_batch_exports_download_retrieveenabled: false+ file-download-batch-exports-list:+ operation: file_download_batch_exports_list+ enabled: falsefile-download-batch-exports-logs-retrieve:operation: file_download_batch_exports_logs_retrieveenabled: falsediff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 12ae1dfb745c..26c3eda162f4 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -20430,6 +20430,27 @@ export namespace Schemas {PosthogAi: 'posthog_ai',} as const;+ /**+ * Typed output for view set `list`.+ */+ export interface ListOutput {+ /** ID of the file download batch export run. */+ id: string;+ /** Current status of the file download batch export run.++ * `Cancelled` - Cancelled+ * `Completed` - Completed+ * `ContinuedAsNew` - Continued As New+ * `Failed` - Failed+ * `FailedRetryable` - Failed Retryable+ * `FailedBilling` - Failed Billing+ * `Terminated` - Terminated+ * `TimedOut` - Timedout+ * `Running` - Running+ * `Starting` - Starting */+ status: BatchExportRunStatusEnum;+ }+export interface LiveDebuggerBreakpoint {readonly id: string;/** @nullable */@@ -23029,6 +23050,15 @@ export namespace Schemas {results: LegalDocumentDTO[];}+ export interface PaginatedListOutputList {+ count: number;+ /** @nullable */+ next?: string | null;+ /** @nullable */+ previous?: string | null;+ results: ListOutput[];+ }+export interface PaginatedLiveDebuggerBreakpointList {count: number;/** @nullable */@@ -38959,6 +38989,17 @@ export namespace Schemas {search?: string;};+ export type EnvironmentsFileDownloadBatchExportsListParams = {+ /**+ * Number of results to return per page.+ */+ limit?: number;+ /**+ * The initial index from which to return the results.+ */+ offset?: number;+ };+export type EnvironmentsFileDownloadBatchExportsLogsRetrieveParams = {/*** Only return entries after this ISO 8601 timestamp.@@ -44261,6 +44302,17 @@ export namespace Schemas {groups?: string;};+ export type FileDownloadBatchExportsListParams = {+ /**+ * Number of results to return per page.+ */+ limit?: number;+ /**+ * The initial index from which to return the results.+ */+ offset?: number;+ };+export type FileDownloadBatchExportsLogsRetrieveParams = {/*** Only return entries after this ISO 8601 timestamp.diff --git a/services/mcp/src/generated/batch_exports/api.ts b/services/mcp/src/generated/batch_exports/api.tsindex 5c104fec556d..adf1333f2de5 100644--- a/services/mcp/src/generated/batch_exports/api.ts+++ b/services/mcp/src/generated/batch_exports/api.ts@@ -514,7 +514,7 @@ export const FileDownloadBatchExportsCreateBody = /* @__PURE__ */ zod.union([])/**- * Get a run of a batch export on demand.+ * Get a batch export on demand run.If the underlying batch export run has completed, we return keys to thegenerated file downloads so that users may download them by making a request