: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(kustomer): support Kustomer API version v2 (#71663)
Tom Owers4f3aa740eae8
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/settings.pyindex f2c80f5bd6cf..96df6191a693 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/settings.py@@ -11,6 +11,8 @@ class KustomerEndpointConfig:# the POST search API with updatedAt windows — a possible follow-up), so every# stream is an honest full refresh. JSON:API rows nest fields under# `attributes`, so no top-level timestamp is available for partitioning.+# These six resources are served under `/v1/` regardless of the vendor version+# pin — the "v2" API-reference toggle still documents them at `/v1/`.KUSTOMER_ENDPOINTS: dict[str, KustomerEndpointConfig] = {"customers": KustomerEndpointConfig(path="/v1/customers"),"conversations": KustomerEndpointConfig(path="/v1/conversations"),diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/source.pyindex 42c9776668af..887c47cde770 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/source.py@@ -32,7 +32,14 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType@SourceRegistry.registerclass KustomerSource(ResumableSource[KustomerSourceConfig, KustomerResumeConfig]):- supported_versions = ("v1",)+ # Kustomer exposes both a v1.0 and a v2 API version, but the resources we sync+ # (customers, conversations, users, teams, tags, brands) are served under `/v1/`+ # for both — the "v2" docs toggle keeps these list endpoints at `/v1/`. So the+ # version is a pin recorded on the source, not a request-layer branch: every+ # version resolves to the same `/v1/<resource>` requests (see settings.py).+ # v2 stays declared-but-dormant and the default remains v1 until a `/v2/<resource>`+ # endpoint is confirmed to serve these resources, rather than 404.+ supported_versions = ("v1", "v2")default_version = "v1"api_docs_url = "https://developer.kustomer.com"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/tests/test_kustomer_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/tests/test_kustomer_source.pyindex 235acff22584..2497bca2b8e2 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/tests/test_kustomer_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/tests/test_kustomer_source.py@@ -1,3 +1,7 @@+from collections.abc import Iterable+from typing import Any, cast+from urllib.parse import urlparse+import pytestfrom unittest import mock@@ -105,6 +109,12 @@ class TestKustomerSource:assert isinstance(manager, ResumableSourceManager)assert manager._data_class is KustomerResumeConfig+ def test_version_declaration_keeps_v1_default_with_v2_supported(self):+ # v2 is declared but dormant; new sources stay stamped v1 until a /v2/ path is confirmed live.+ assert self.source.supported_versions == ("v1", "v2")+ assert self.source.default_version == "v1"+ assert self.source.deprecated_versions == ()+@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.kustomer.source.kustomer_source")def test_source_for_pipeline_plumbs_arguments(self, mock_kustomer_source):inputs = mock.MagicMock()@@ -119,3 +129,28 @@ class TestKustomerSource:assert kwargs["api_key"] == "api-key"assert kwargs["endpoint"] == "customers"assert kwargs["resumable_source_manager"] is manager++ @pytest.mark.parametrize("pinned_version", [None, "v1", "v2"])+ @pytest.mark.parametrize("endpoint", ENDPOINTS)+ @mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.kustomer.kustomer.make_tracked_session"+ )+ def test_source_requests_v1_rest_paths_for_every_version(self, mock_session, endpoint, pinned_version):+ # Every list resource is served at /v1/ for both vendor versions; a v2 pin+ # must not switch to /v2/, which would 404 the stream. Covering all six also+ # guards against a per-resource /v2/ typo in the endpoint catalog.+ page = mock.MagicMock(status_code=200, ok=True)+ page.json.return_value = {"data": [], "links": {}}+ mock_session.return_value.get.return_value = page++ inputs = mock.MagicMock()+ inputs.schema_name = endpoint+ inputs.api_version = pinned_version+ manager = mock.MagicMock()+ manager.can_resume.return_value = False++ response = self.source.source_for_pipeline(self.config, manager, inputs)+ list(cast(Iterable[Any], response.items()))++ url = mock_session.return_value.get.call_args.args[0]+ assert urlparse(url).path == f"/v1/{endpoint}"