: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(messaging): add provider imports api (#124385)
Harley Alexander4453127b899d
diff --git a/posthog/test/repo_invariants/test_pagination_contract.py b/posthog/test/repo_invariants/test_pagination_contract.pyindex 322913cc3835..594686bb86b7 100644--- a/posthog/test/repo_invariants/test_pagination_contract.py+++ b/posthog/test/repo_invariants/test_pagination_contract.py@@ -34,6 +34,8 @@ EXISTING_CUSTOM_LIST_VIEWSETS = {"products.apm.backend.presentation.views.EndpointsHealthViewSet",# Returns one bounded object (capped at MAP_EDGES_LIMIT edges over a bounded trace sample), not a page of rows."products.apm.backend.presentation.views.ServiceMapViewSet",+ # Returns the team's 20 most recent import runs, not a page of rows.+ "products.messaging.backend.presentation.views.provider_imports.ProviderImportViewSet","ee.api.billing.BillingViewset","ee.api.quota_limits.QuotaLimitsViewSet","products.subscriptions.backend.presentation.views.SubscriptionDeliveryViewSet",diff --git a/products/messaging/backend/facade/provider_imports.py b/products/messaging/backend/facade/provider_imports.pynew file mode 100644index 000000000000..54b11b195472--- /dev/null+++ b/products/messaging/backend/facade/provider_imports.py@@ -0,0 +1,155 @@+"""Background imports of opt-outs, suppressions and categories from other messaging tools.++Each run executes in Temporal, so a long provider list does not hit the request timeout. The synchronous+Customer.io import in `customerio.py` stays available next to it.+"""++from datetime import datetime+from typing import Any+from uuid import UUID++from posthog.dataclasses import frozen++from products.messaging.backend.models.provider_import_run import (+ ImportProviderKey,+ ImportStepStatus,+ ProviderImportRun,+ ProviderImportStatus,+)+from products.messaging.backend.provider_imports import runs+from products.messaging.backend.provider_imports.base import (+ ImportCredentialsConflict,+ ImportCredentialsInvalid,+ ImportCredentialsMissing,+ ImportProviderUnavailable,+)+from products.messaging.backend.provider_imports.registry import PROVIDERS, UnknownImportProvider, get_provider++IMPORT_PROVIDER_CHOICES: list[tuple[str, str]] = [(value, str(label)) for value, label in ImportProviderKey.choices]+PROVIDER_IMPORT_STATUS_CHOICES: list[tuple[str, str]] = [+ (value, str(label)) for value, label in ProviderImportStatus.choices+]+IMPORT_STEP_STATUS_CHOICES: list[tuple[str, str]] = [(value, str(label)) for value, label in ImportStepStatus.choices]+++class ProviderImportRejected(Exception):+ """The request can't start an import: unknown provider or step, or missing or invalid credentials."""+++class ProviderImportConflict(Exception):+ """An import is already running, or a different API key is stored."""+++class ProviderImportUnavailable(Exception):+ """The provider did not respond while checking the API key. Starting again later can work."""+++@frozen+class ImportStepOption:+ key: str+ label: str+ description: str+++@frozen+class ImportProviderOption:+ key: str+ label: str+ steps: tuple[ImportStepOption, ...]+++@frozen+class ImportStepProgress:+ key: str+ label: str+ status: str+ processed: int+ imported: int+ warnings: tuple[str, ...]+ last_error: str | None+++@frozen+class ProviderImportRunState:+ id: UUID+ provider: str+ status: str+ steps: tuple[ImportStepProgress, ...]+ created_at: datetime+ started_at: datetime | None+ finished_at: datetime | None+++def list_import_providers() -> list[ImportProviderOption]:+ return [+ ImportProviderOption(+ key=provider.key,+ label=provider.label,+ steps=tuple(+ ImportStepOption(key=spec.key, label=spec.label, description=spec.description)+ for spec in provider.steps+ ),+ )+ for provider in PROVIDERS.values()+ ]+++def start_provider_import(+ team_id: int, provider: str, steps: list[str], api_key: str | None, created_by_id: int | None+) -> ProviderImportRunState:+ """Check the credentials and start a background import of the selected steps.++ Raises ProviderImportRejected for a request that can't work as sent, ProviderImportConflict when an import is+ already running or a different key is stored, and ProviderImportUnavailable when the provider can't check the+ key.+ """+ try:+ run = runs.start_run(team_id, provider, steps, api_key, created_by_id)+ except (UnknownImportProvider, runs.InvalidImportSteps, ImportCredentialsMissing, ImportCredentialsInvalid) as e:+ raise ProviderImportRejected(_rejection_message(e)) from e+ except (runs.ProviderImportAlreadyRunning, ImportCredentialsConflict) as e:+ raise ProviderImportConflict(str(e)) from e+ except ImportProviderUnavailable as e:+ raise ProviderImportUnavailable(f"{e} Try again in a few minutes.") from e+ return _to_state(run)+++def list_provider_import_runs(team_id: int, limit: int = 20) -> list[ProviderImportRunState]:+ """The team's most recent imports, newest first."""+ return [_to_state(run) for run in runs.list_runs(team_id, limit)]+++def get_provider_import_run(team_id: int, run_id: UUID) -> ProviderImportRunState | None:+ run = runs.get_run(team_id, run_id)+ return _to_state(run) if run else None+++def _rejection_message(error: Exception) -> str:+ if isinstance(error, UnknownImportProvider):+ return f"Unknown import provider: {error}."+ return str(error)+++def _to_state(run: ProviderImportRun) -> ProviderImportRunState:+ labels = {spec.key: spec.label for spec in get_provider(run.provider).steps}+ return ProviderImportRunState(+ id=run.id,+ provider=run.provider,+ status=run.status,+ steps=tuple(_step_progress(step, labels.get(step, step), run.progress.get(step, {})) for step in run.steps),+ created_at=run.created_at,+ started_at=run.started_at,+ finished_at=run.finished_at,+ )+++def _step_progress(key: str, label: str, progress: dict[str, Any]) -> ImportStepProgress:+ return ImportStepProgress(+ key=key,+ label=label,+ status=progress.get("status", ImportStepStatus.PENDING.value),+ processed=progress.get("processed", 0),+ imported=progress.get("imported", 0),+ warnings=tuple(progress.get("warnings", [])),+ last_error=progress.get("last_error"),+ )diff --git a/products/messaging/backend/presentation/views/provider_imports.py b/products/messaging/backend/presentation/views/provider_imports.pynew file mode 100644index 000000000000..09ca62a7b475--- /dev/null+++ b/products/messaging/backend/presentation/views/provider_imports.py@@ -0,0 +1,175 @@+from typing import Any, Literal+from uuid import UUID++from drf_spectacular.utils import OpenApiResponse, extend_schema+from rest_framework import serializers, status, viewsets+from rest_framework.decorators import action+from rest_framework.exceptions import APIException, NotFound, PermissionDenied, ValidationError+from rest_framework.request import Request+from rest_framework.response import Response++from posthog.api.documentation import _FallbackSerializer+from posthog.api.mixins import ValidatedRequest, validated_request+from posthog.api.routing import TeamAndOrgViewSetMixin+from posthog.event_usage import report_user_action+from posthog.exceptions import Conflict++from products.messaging.backend.facade.provider_imports import (+ IMPORT_PROVIDER_CHOICES,+ IMPORT_STEP_STATUS_CHOICES,+ PROVIDER_IMPORT_STATUS_CHOICES,+ ProviderImportConflict,+ ProviderImportRejected,+ ProviderImportUnavailable,+ get_provider_import_run,+ list_import_providers,+ list_provider_import_runs,+ start_provider_import,+)+++class ImportStepOptionSerializer(serializers.Serializer):+ key = serializers.CharField(+ help_text="Step key to send in `steps` when starting an import, for example `suppressions`."+ )+ label = serializers.CharField(help_text="Display name of the step.") # type: ignore[assignment] # field named `label` shadows DRF Field.label+ description = serializers.CharField(help_text="What the step imports and where it lands in PostHog.")+++class ImportProviderOptionSerializer(serializers.Serializer):+ key = serializers.ChoiceField(+ choices=IMPORT_PROVIDER_CHOICES, help_text="Provider key to send when starting an import."+ )+ label = serializers.CharField(help_text="Display name of the provider.") # type: ignore[assignment] # field named `label` shadows DRF Field.label+ steps = ImportStepOptionSerializer(many=True, help_text="What the provider can import, in the order the steps run.")+++class ImportStepProgressSerializer(serializers.Serializer):+ key = serializers.CharField(help_text="Step key, for example `suppressions`.")+ label = serializers.CharField(help_text="Display name of the step.") # type: ignore[assignment] # field named `label` shadows DRF Field.label+ status = serializers.ChoiceField(+ choices=IMPORT_STEP_STATUS_CHOICES,+ help_text="`pending` until the step starts, `running` while it imports or waits to retry, then `completed` or `failed`.",+ )+ processed = serializers.IntegerField(help_text="How many records the step read from the provider so far.")+ imported = serializers.IntegerField(+ help_text="How many records the step added or updated in PostHog so far. Records that already existed and need no change may not count."+ )+ warnings = serializers.ListField(+ child=serializers.CharField(), help_text="Problems with single records that did not fail the step."+ )+ last_error = serializers.CharField(+ allow_null=True,+ help_text="The error from the step's most recent failed attempt. A running step retries after an error; a failed step stopped.",+ )+++class ProviderImportRunSerializer(serializers.Serializer):+ id = serializers.UUIDField(help_text="Import run ID.")+ provider = serializers.ChoiceField(choices=IMPORT_PROVIDER_CHOICES, help_text="The provider the run imports from.")+ status = serializers.ChoiceField(+ choices=PROVIDER_IMPORT_STATUS_CHOICES,+ help_text="`queued` until the first step starts, `running`, then `completed` when every step completed or `failed` when any step failed.",+ )+ steps = ImportStepProgressSerializer(many=True, help_text="Progress of each selected step, in run order.")+ created_at = serializers.DateTimeField(help_text="When the run was requested.")+ started_at = serializers.DateTimeField(allow_null=True, help_text="When the first step started.")+ finished_at = serializers.DateTimeField(allow_null=True, help_text="When the last step ended.")+++class StartProviderImportSerializer(serializers.Serializer):+ provider = serializers.ChoiceField(choices=IMPORT_PROVIDER_CHOICES, help_text="The provider to import from.")+ steps = serializers.ListField(+ child=serializers.CharField(max_length=64),+ min_length=1,+ help_text="Keys of the steps to run, from the `providers` endpoint. They run in the provider's order, whatever order you send.",+ )+ api_key = serializers.CharField(+ required=False,+ write_only=True,+ help_text="The provider's API key. For Customer.io, an App API key. Leave it out to reuse the stored key.",+ )+++class ProviderUnavailable(APIException):+ status_code = status.HTTP_503_SERVICE_UNAVAILABLE+ default_code = "provider_unavailable"+++class ProviderImportViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):+ """+ Background imports from other messaging tools, such as Customer.io suppressions and global unsubscribes.++ A run executes outside the request, so a long provider list does not time out. Poll a run to show its progress.+ """++ scope_object = "hog_flow"+ serializer_class = _FallbackSerializer++ @extend_schema(+ responses={200: ProviderImportRunSerializer(many=True)}, summary="List the most recent provider imports"+ )+ def list(self, request: Request, **kwargs: Any) -> Response:+ self._require_project_access("viewer")+ return Response(ProviderImportRunSerializer(list_provider_import_runs(self.team_id), many=True).data)++ @extend_schema(responses={200: ProviderImportRunSerializer}, summary="Get a provider import and its progress")+ def retrieve(self, request: Request, pk: str | None = None, **kwargs: Any) -> Response:+ self._require_project_access("viewer")+ try:+ run = get_provider_import_run(self.team_id, UUID(str(pk)))+ except ValueError:+ run = None+ if run is None:+ raise NotFound("Import not found.")+ return Response(ProviderImportRunSerializer(run).data)++ @validated_request(+ request_serializer=StartProviderImportSerializer,+ responses={+ 201: OpenApiResponse(response=ProviderImportRunSerializer),+ 400: OpenApiResponse(+ description="The provider or a step is unknown, or the API key is missing or rejected."+ ),+ 409: OpenApiResponse(description="An import from this provider is running, or a different key is stored."),+ 503: OpenApiResponse(description="The provider did not respond while checking the API key."),+ },+ summary="Start a background import from another messaging tool",+ )+ def create(self, request: ValidatedRequest, **kwargs: Any) -> Response:+ self._require_project_access("editor")++ data = request.validated_data+ try:+ run = start_provider_import(+ self.team_id, data["provider"], data["steps"], data.get("api_key"), request.user.id+ )+ except ProviderImportRejected as e:+ raise ValidationError(str(e)) from e+ except ProviderImportConflict as e:+ raise Conflict(str(e)) from e+ except ProviderImportUnavailable as e:+ raise ProviderUnavailable(str(e)) from e++ report_user_action(+ request.user,+ "messaging provider import started",+ {"provider": run.provider, "steps": [step.key for step in run.steps]},+ team=self.team,+ request=request,+ )+ return Response(ProviderImportRunSerializer(run).data, status=status.HTTP_201_CREATED)++ @extend_schema(+ responses={200: ImportProviderOptionSerializer(many=True)},+ summary="List the providers and what each can import",+ )+ @action(detail=False, methods=["get"], required_scopes=["hog_flow:read"])+ def providers(self, request: Request, **kwargs: Any) -> Response:+ return Response(ImportProviderOptionSerializer(list_import_providers(), many=True).data)++ def _require_project_access(self, level: Literal["viewer", "editor"]) -> None:+ # Runs cover the whole project, not one workflow. Without this check, access to a single workflow would be+ # enough to read or start every import.+ if not self.user_access_control.check_access_level_for_resource("hog_flow", level):+ raise PermissionDenied(f"You need project-wide workflow {level} access to use messaging imports.")diff --git a/products/messaging/backend/routes.py b/products/messaging/backend/routes.pyindex 05ddff7799e0..87b8d2b8e9ba 100644--- a/products/messaging/backend/routes.py+++ b/products/messaging/backend/routes.py@@ -7,6 +7,7 @@ from products.messaging.backend.presentation.views.message_templates import (MessageTemplatesViewSet,MessagingSendViewSet,)+from products.messaging.backend.presentation.views.provider_imports import ProviderImportViewSetdef register_routes(routers: RouterRegistry) -> None:@@ -24,3 +25,6 @@ def register_routes(routers: RouterRegistry) -> None:r"messaging_suppressions", MessageSuppressionViewSet, "project_messaging_suppressions", ["team_id"])routers.projects.register(r"messaging/send", MessagingSendViewSet, "project_messaging_send", ["team_id"])+ routers.projects.register(+ r"messaging_provider_imports", ProviderImportViewSet, "project_messaging_provider_imports", ["team_id"]+ )diff --git a/products/messaging/backend/tests/api/test_provider_imports.py b/products/messaging/backend/tests/api/test_provider_imports.pynew file mode 100644index 000000000000..20f5d35b34fd--- /dev/null+++ b/products/messaging/backend/tests/api/test_provider_imports.py@@ -0,0 +1,90 @@+from posthog.test.base import APIBaseTest+from unittest.mock import MagicMock, patch++from parameterized import parameterized+from rest_framework import status++from posthog.models.integration import Integration++from products.messaging.backend.services.customerio_client import CustomerIOAPIError+++@patch("products.messaging.backend.provider_imports.runs.start_provider_import_workflow")+@patch("products.messaging.backend.services.customerio_import_service.CustomerIOClient")+class TestProviderImportsAPI(APIBaseTest):+ def _url(self) -> str:+ return f"/api/projects/{self.team.id}/messaging_provider_imports/"++ def test_start_runs_the_selected_steps_in_provider_order(+ self, _mock_client_class: MagicMock, start_workflow: MagicMock+ ) -> None:+ response = self.client.post(+ self._url(), {"provider": "customerio", "steps": ["opt_outs", "suppressions"], "api_key": "app-key"}+ )++ assert response.status_code == status.HTTP_201_CREATED, response.json()+ assert response.json()["status"] == "queued"+ assert [step["key"] for step in response.json()["steps"]] == ["suppressions", "opt_outs"]+ start_workflow.assert_called_once()+ assert start_workflow.call_args.kwargs["steps"] == ["suppressions", "opt_outs"]+ assert Integration.objects.get(team_id=self.team.id, kind="customerio-app").sensitive_config == {+ "app_api_key": "app-key"+ }+ assert self.client.get(f"{self._url()}{response.json()['id']}/").json()["id"] == response.json()["id"]++ def test_rejects_a_second_import_while_one_is_running(+ self, _mock_client_class: MagicMock, _start_workflow: MagicMock+ ) -> None:+ body = {"provider": "customerio", "steps": ["suppressions"]}+ assert self.client.post(self._url(), {**body, "api_key": "app-key"}).status_code == status.HTTP_201_CREATED++ response = self.client.post(self._url(), body)++ assert response.status_code == status.HTTP_409_CONFLICT+ assert "already running" in response.json()["detail"]++ @parameterized.expand(+ [+ ("unknown_step", ["automations"], None, status.HTTP_400_BAD_REQUEST, "no step named automations"),+ (+ "rejected_key",+ ["suppressions"],+ 401,+ status.HTTP_400_BAD_REQUEST,+ "Customer.io rejected the App API key",+ ),+ ("provider_down", ["suppressions"], 503, status.HTTP_503_SERVICE_UNAVAILABLE, "returned HTTP 503"),+ ]+ )+ def test_does_not_start_an_import_that_cannot_run(+ self,+ mock_client_class: MagicMock,+ start_workflow: MagicMock,+ _name: str,+ steps: list[str],+ topics_status: int | None,+ expected_status: int,+ expected_detail: str,+ ) -> None:+ if topics_status is not None:+ mock_client_class.return_value.get_subscription_topics.side_effect = CustomerIOAPIError(+ "Customer.io API error", status_code=topics_status+ )++ response = self.client.post(self._url(), {"provider": "customerio", "steps": steps, "api_key": "app-key"})++ assert response.status_code == expected_status, response.json()+ assert expected_detail in response.json()["detail"]+ start_workflow.assert_not_called()+ assert not Integration.objects.filter(team_id=self.team.id, kind="customerio-app").exists()++ @parameterized.expand([("providers", "providers/"), ("list", "")])+ def test_reads_with_a_personal_api_key(+ self, _mock_client_class: MagicMock, _start_workflow: MagicMock, _name: str, path: str+ ) -> None:+ key = self.create_personal_api_key_with_scopes(["hog_flow:read"])+ self.client.logout()++ response = self.client.get(f"{self._url()}{path}", HTTP_AUTHORIZATION=f"Bearer {key}")++ assert response.status_code == status.HTTP_200_OK, response.json()diff --git a/products/messaging/frontend/generated/api.schemas.ts b/products/messaging/frontend/generated/api.schemas.tsindex 79210791e13f..c2f9677bb93f 100644--- a/products/messaging/frontend/generated/api.schemas.ts+++ b/products/messaging/frontend/generated/api.schemas.ts@@ -236,6 +236,135 @@ export interface WebhookUrlApi {url: string}+/**+ * * `customerio` - Customer.io+ */+export type ImportProviderKeyEnumApi = (typeof ImportProviderKeyEnumApi)[keyof typeof ImportProviderKeyEnumApi]++export const ImportProviderKeyEnumApi = {+ Customerio: 'customerio',+} as const++/**+ * * `queued` - Waiting to start+ * * `running` - Importing+ * * `completed` - Imported+ * * `failed` - Failed+ */+export type ProviderImportStatusEnumApi = (typeof ProviderImportStatusEnumApi)[keyof typeof ProviderImportStatusEnumApi]++export const ProviderImportStatusEnumApi = {+ Queued: 'queued',+ Running: 'running',+ Completed: 'completed',+ Failed: 'failed',+} as const++/**+ * * `pending` - Not started+ * * `running` - Importing+ * * `completed` - Imported+ * * `failed` - Failed+ */+export type ImportStepStatusEnumApi = (typeof ImportStepStatusEnumApi)[keyof typeof ImportStepStatusEnumApi]++export const ImportStepStatusEnumApi = {+ Pending: 'pending',+ Running: 'running',+ Completed: 'completed',+ Failed: 'failed',+} as const++export interface ImportStepProgressApi {+ /** Step key, for example `suppressions`. */+ key: string+ /** Display name of the step. */+ label: string+ /** `pending` until the step starts, `running` while it imports or waits to retry, then `completed` or `failed`.+ *+ * * `pending` - Not started+ * * `running` - Importing+ * * `completed` - Imported+ * * `failed` - Failed */+ status: ImportStepStatusEnumApi+ /** How many records the step read from the provider so far. */+ processed: number+ /** How many records the step added or updated in PostHog so far. Records that already existed and need no change may not count. */+ imported: number+ /** Problems with single records that did not fail the step. */+ warnings: string[]+ /**+ * The error from the step's most recent failed attempt. A running step retries after an error; a failed step stopped.+ * @nullable+ */+ last_error: string | null+}++export interface ProviderImportRunApi {+ /** Import run ID. */+ id: string+ /** The provider the run imports from.+ *+ * * `customerio` - Customer.io */+ provider: ImportProviderKeyEnumApi+ /** `queued` until the first step starts, `running`, then `completed` when every step completed or `failed` when any step failed.+ *+ * * `queued` - Waiting to start+ * * `running` - Importing+ * * `completed` - Imported+ * * `failed` - Failed */+ status: ProviderImportStatusEnumApi+ /** Progress of each selected step, in run order. */+ steps: ImportStepProgressApi[]+ /** When the run was requested. */+ created_at: string+ /**+ * When the first step started.+ * @nullable+ */+ started_at: string | null+ /**+ * When the last step ended.+ * @nullable+ */+ finished_at: string | null+}++export interface StartProviderImportApi {+ /** The provider to import from.+ *+ * * `customerio` - Customer.io */+ provider: ImportProviderKeyEnumApi+ /**+ * Keys of the steps to run, from the `providers` endpoint. They run in the provider's order, whatever order you send.+ * @minItems 1+ * @items.maxLength 64+ */+ steps: string[]+ /** The provider's API key. For Customer.io, an App API key. Leave it out to reuse the stored key. */+ api_key?: string+}++export interface ImportStepOptionApi {+ /** Step key to send in `steps` when starting an import, for example `suppressions`. */+ key: string+ /** Display name of the step. */+ label: string+ /** What the step imports and where it lands in PostHog. */+ description: string+}++export interface ImportProviderOptionApi {+ /** Provider key to send when starting an import.+ *+ * * `customerio` - Customer.io */+ key: ImportProviderKeyEnumApi+ /** Display name of the provider. */+ label: string+ /** What the provider can import, in the order the steps run. */+ steps: ImportStepOptionApi[]+}+export interface AddSuppressionRequestApi {/*** The email address to suppress. Will not receive any messages until removed.diff --git a/products/messaging/frontend/generated/api.ts b/products/messaging/frontend/generated/api.tsindex e867bbf69f03..b8c0fd15c926 100644--- a/products/messaging/frontend/generated/api.ts+++ b/products/messaging/frontend/generated/api.ts@@ -14,6 +14,7 @@ import type {BulkAddOptOutsRequestApi,BulkAddOptOutsResultApi,GenerateLinkRequestApi,+ ImportProviderOptionApi,MakeTransactionalApi,MessageCategoryApi,MessagePreferencesApi,@@ -32,10 +33,12 @@ import type {PatchedMessageCategoryApi,PatchedMessageTemplateApi,PreferencesLinkApi,+ ProviderImportRunApi,RemoveOptOutRequestApi,SendEmailApi,SendTransactionalEmailApi,SendTransactionalEmailResponseApi,+ StartProviderImportApi,WebhookUrlApi,} from './api.schemas'@@ -537,6 +540,90 @@ export const messagingPreferencesWebhookUrlRetrieve = async (})}+export const getMessagingProviderImportsListUrl = (projectId: string) => {+ return `/api/projects/${projectId}/messaging_provider_imports/`+}++/**+ * Background imports from other messaging tools, such as Customer.io suppressions and global unsubscribes.+ *+ * A run executes outside the request, so a long provider list does not time out. Poll a run to show its progress.+ * @summary List the most recent provider imports+ */+export const messagingProviderImportsList = async (+ projectId: string,+ options?: RequestInit+): Promise<ProviderImportRunApi[]> => {+ return apiMutator<ProviderImportRunApi[]>(getMessagingProviderImportsListUrl(projectId), {+ ...options,+ method: 'GET',+ })+}++export const getMessagingProviderImportsCreateUrl = (projectId: string) => {+ return `/api/projects/${projectId}/messaging_provider_imports/`+}++/**+ * Background imports from other messaging tools, such as Customer.io suppressions and global unsubscribes.+ *+ * A run executes outside the request, so a long provider list does not time out. Poll a run to show its progress.+ * @summary Start a background import from another messaging tool+ */+export const messagingProviderImportsCreate = async (+ projectId: string,+ startProviderImportApi: StartProviderImportApi,+ options?: RequestInit+): Promise<ProviderImportRunApi> => {+ return apiMutator<ProviderImportRunApi>(getMessagingProviderImportsCreateUrl(projectId), {+ ...options,+ method: 'POST',+ headers: { 'Content-Type': 'application/json', ...options?.headers },+ body: JSON.stringify(startProviderImportApi),+ })+}++export const getMessagingProviderImportsRetrieveUrl = (projectId: string, id: string) => {+ return `/api/projects/${projectId}/messaging_provider_imports/${id}/`+}++/**+ * Background imports from other messaging tools, such as Customer.io suppressions and global unsubscribes.+ *+ * A run executes outside the request, so a long provider list does not time out. Poll a run to show its progress.+ * @summary Get a provider import and its progress+ */+export const messagingProviderImportsRetrieve = async (+ projectId: string,+ id: string,+ options?: RequestInit+): Promise<ProviderImportRunApi> => {+ return apiMutator<ProviderImportRunApi>(getMessagingProviderImportsRetrieveUrl(projectId, id), {+ ...options,+ method: 'GET',+ })+}++export const getMessagingProviderImportsProvidersListUrl = (projectId: string) => {+ return `/api/projects/${projectId}/messaging_provider_imports/providers/`+}++/**+ * Background imports from other messaging tools, such as Customer.io suppressions and global unsubscribes.+ *+ * A run executes outside the request, so a long provider list does not time out. Poll a run to show its progress.+ * @summary List the providers and what each can import+ */+export const messagingProviderImportsProvidersList = async (+ projectId: string,+ options?: RequestInit+): Promise<ImportProviderOptionApi[]> => {+ return apiMutator<ImportProviderOptionApi[]>(getMessagingProviderImportsProvidersListUrl(projectId), {+ ...options,+ method: 'GET',+ })+}+export const getMessagingSuppressionsAddSuppressionCreateUrl = (projectId: string) => {return `/api/projects/${projectId}/messaging_suppressions/add_suppression/`}diff --git a/products/messaging/frontend/generated/api.zod.ts b/products/messaging/frontend/generated/api.zod.tsindex c0a43b752048..b9c5ae980c9e 100644--- a/products/messaging/frontend/generated/api.zod.ts+++ b/products/messaging/frontend/generated/api.zod.ts@@ -400,6 +400,31 @@ export const MessagingPreferencesRemoveOptOutCreateBody = /* @__PURE__ */ zod.ob),})+/**+ * Background imports from other messaging tools, such as Customer.io suppressions and global unsubscribes.+ *+ * A run executes outside the request, so a long provider list does not time out. Poll a run to show its progress.+ * @summary Start a background import from another messaging tool+ */+export const messagingProviderImportsCreateBodyStepsItemMax = 64++export const MessagingProviderImportsCreateBody = /* @__PURE__ */ zod.object({+ provider: zod+ .enum(['customerio'])+ .describe('\* `customerio` - Customer.io')+ .describe('The provider to import from.\n\n\* `customerio` - Customer.io'),+ steps: zod+ .array(zod.string().max(messagingProviderImportsCreateBodyStepsItemMax))+ .min(1)+ .describe(+ "Keys of the steps to run, from the `providers` endpoint. They run in the provider's order, whatever order you send."+ ),+ api_key: zod+ .string()+ .optional()+ .describe("The provider's API key. For Customer.io, an App API key. Leave it out to reuse the stored key."),+})+/*** Manually suppress an email address so no workflow sends to it.* @summary Manually add an email address to the suppression listdiff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 9fd7d64aa2eb..f610ed08ad6f 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -63774,6 +63774,77 @@ export namespace Schemas {working: ImpactWorking | null;}+ /**+ * * `customerio` - Customer.io+ */+ export type ImportProviderKeyEnum = typeof ImportProviderKeyEnum[keyof typeof ImportProviderKeyEnum];+++ export const ImportProviderKeyEnum = {+ Customerio: 'customerio',+ } as const;++ export interface ImportStepOption {+ /** Step key to send in `steps` when starting an import, for example `suppressions`. */+ key: string;+ /** Display name of the step. */+ label: string;+ /** What the step imports and where it lands in PostHog. */+ description: string;+ }++ export interface ImportProviderOption {+ /** Provider key to send when starting an import.+ *+ * * `customerio` - Customer.io */+ key: ImportProviderKeyEnum;+ /** Display name of the provider. */+ label: string;+ /** What the provider can import, in the order the steps run. */+ steps: ImportStepOption[];+ }++ /**+ * * `pending` - Not started+ * * `running` - Importing+ * * `completed` - Imported+ * * `failed` - Failed+ */+ export type ImportStepStatusEnum = typeof ImportStepStatusEnum[keyof typeof ImportStepStatusEnum];+++ export const ImportStepStatusEnum = {+ Pending: 'pending',+ Running: 'running',+ Completed: 'completed',+ Failed: 'failed',+ } as const;++ export interface ImportStepProgress {+ /** Step key, for example `suppressions`. */+ key: string;+ /** Display name of the step. */+ label: string;+ /** `pending` until the step starts, `running` while it imports or waits to retry, then `completed` or `failed`.+ *+ * * `pending` - Not started+ * * `running` - Importing+ * * `completed` - Imported+ * * `failed` - Failed */+ status: ImportStepStatusEnum;+ /** How many records the step read from the provider so far. */+ processed: number;+ /** How many records the step added or updated in PostHog so far. Records that already existed and need no change may not count. */+ imported: number;+ /** Problems with single records that did not fail the step. */+ warnings: string[];+ /**+ * The error from the step's most recent failed attempt. A running step retries after an error; a failed step stopped.+ * @nullable+ */+ last_error: string | null;+ }+/*** * `signals` - Signals* * `scouts` - Scouts@@ -98170,6 +98241,52 @@ export namespace Schemas {version?: number | null;}+ /**+ * * `queued` - Waiting to start+ * * `running` - Importing+ * * `completed` - Imported+ * * `failed` - Failed+ */+ export type ProviderImportStatusEnum = typeof ProviderImportStatusEnum[keyof typeof ProviderImportStatusEnum];+++ export const ProviderImportStatusEnum = {+ Queued: 'queued',+ Running: 'running',+ Completed: 'completed',+ Failed: 'failed',+ } as const;++ export interface ProviderImportRun {+ /** Import run ID. */+ id: string;+ /** The provider the run imports from.+ *+ * * `customerio` - Customer.io */+ provider: ImportProviderKeyEnum;+ /** `queued` until the first step starts, `running`, then `completed` when every step completed or `failed` when any step failed.+ *+ * * `queued` - Waiting to start+ * * `running` - Importing+ * * `completed` - Imported+ * * `failed` - Failed */+ status: ProviderImportStatusEnum;+ /** Progress of each selected step, in run order. */+ steps: ImportStepProgress[];+ /** When the run was requested. */+ created_at: string;+ /**+ * When the first step started.+ * @nullable+ */+ started_at: string | null;+ /**+ * When the last step ended.+ * @nullable+ */+ finished_at: string | null;+ }+export interface ProvisionWarehouseRequest {/** Name for the new database */database_name: string;@@ -116384,6 +116501,21 @@ export namespace Schemas {readonly installations: readonly StamphogDiscoveredInstallation[];}+ export interface StartProviderImport {+ /** The provider to import from.+ *+ * * `customerio` - Customer.io */+ provider: ImportProviderKeyEnum;+ /**+ * Keys of the steps to run, from the `providers` endpoint. They run in the provider's order, whatever order you send.+ * @minItems 1+ * @items.maxLength 64+ */+ steps: string[];+ /** The provider's API key. For Customer.io, an App API key. Leave it out to reuse the stored key. */+ api_key?: string;+ }+export interface StartTrainingRequest {/*** Iterations for this training run. Defaults to the pipeline's iterations_per_run.