: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(warehouse_sources): support Courier API version 2.0.0 (#74150)
Tom Owersea20948d1137
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/courier/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/courier/settings.pyindex 563302f1f99d..096bdf3893af 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/courier/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/courier/settings.py@@ -1,11 +1,22 @@from dataclasses import dataclass, fieldfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import SortMode+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import UNVERSIONED_API_VERSIONfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.schema import incremental_fieldfrom products.warehouse_sources.backend.types import IncrementalFieldCOURIER_BASE_URL = "https://api.courier.com"+# Courier's REST API is unversioned on the wire: one https://api.courier.com host, Bearer auth, and+# no version header or path segment (per the vendor API reference). "1.0.0" and "2.0.0" are+# documentation-site labels — the 1.0.0 reference now redirects to 2.0.0. UNVERSIONED_API_VERSION+# ("v1") is the framework placeholder pre-versioning rows carry, and it already hits the same live+# API the 2.0.0 docs describe. Both labels therefore resolve to identical requests, so nothing+# branches on the version — these are declared for source pinning and the default only.+COURIER_API_VERSION_2_0_0 = "2.0.0"+SUPPORTED_VERSIONS = (UNVERSIONED_API_VERSION, COURIER_API_VERSION_2_0_0)+DEFAULT_VERSION = COURIER_API_VERSION_2_0_0+# Courier's default page size is small (~10 messages/page per the vendor docs); raising `limit`# cuts the round-trips a full backfill needs. No documented maximum, so we stay conservative.COURIER_PAGE_SIZE = 100diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/courier/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/courier/source.pyindex b30c14f8730e..189c8a3fda4a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/courier/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/courier/source.py@@ -29,8 +29,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.courier.covalidate_credentials as validate_courier_credentials,)from products.warehouse_sources.backend.temporal.data_imports.sources.courier.settings import (+ DEFAULT_VERSION,ENDPOINTS,INCREMENTAL_FIELDS,+ SUPPORTED_VERSIONS,)from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.courier import (CourierSourceConfig,@@ -42,6 +44,8 @@ from products.warehouse_sources.backend.types import ExternalDataSourceTypeclass CourierSource(ResumableSource[CourierSourceConfig, CourierResumeConfig]):lists_tables_without_credentials = True # static endpoint catalog — safe for public docsapi_docs_url = "https://www.courier.com/docs/reference/get-started/"+ supported_versions = SUPPORTED_VERSIONS+ default_version = DEFAULT_VERSION@propertydef source_type(self) -> ExternalDataSourceType:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/courier/tests/test_courier_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/courier/tests/test_courier_source.pyindex 67309c5fb105..2f11df2f33da 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/courier/tests/test_courier_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/courier/tests/test_courier_source.py@@ -6,9 +6,13 @@ from parameterized import parameterizedfrom posthog.schema import DataWarehouseSourceCategory, ReleaseStatus, SourceFieldInputConfig+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import UNVERSIONED_API_VERSIONfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.courier.courier import CourierResumeConfig-from products.warehouse_sources.backend.temporal.data_imports.sources.courier.settings import ENDPOINTS+from products.warehouse_sources.backend.temporal.data_imports.sources.courier.settings import (+ COURIER_API_VERSION_2_0_0,+ ENDPOINTS,+)from products.warehouse_sources.backend.temporal.data_imports.sources.courier.source import CourierSourcefrom products.warehouse_sources.backend.types import ExternalDataSourceType@@ -41,6 +45,14 @@ class TestSourceConfig:errors = CourierSource().get_non_retryable_errors()assert any("403" in key for key in errors)+ def test_supports_legacy_and_2_0_0_with_2_0_0_default(self) -> None:+ # 2.0.0 is Courier's current API reference and the new default for new sources; the legacy+ # placeholder stays supported so existing pinned rows keep resolving to the same unversioned+ # wire behaviour (Courier's API has no version header/path, so both labels hit one API).+ source = CourierSource()+ assert source.supported_versions == (UNVERSIONED_API_VERSION, COURIER_API_VERSION_2_0_0)+ assert source.default_version == COURIER_API_VERSION_2_0_0+class TestGetSchemas:def test_only_server_side_filtered_endpoints_are_incremental(self) -> None: