: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(commercetools): sync stores, channels, customer groups and states (#103454)
Tom Owers61906971ae01
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex 1eed14fc6392..e950e3b5ee10 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -1904,16 +1904,16 @@ Note: coinmarketcap.com/api/documentation is a client-rendered zudoku app, but e## Commercetools — gaps-Today (8): `carts`, `categories`, `customers`, `discount_codes`, `inventory`, `orders`, `payments`, `product_projections`+Today (12): `carts`, `categories`, `channels`, `customer_groups`, `customers`, `discount_codes`, `inventory`, `orders`, `payments`, `product_projections`, `states`, `stores`Diffed against: <https://raw.githubusercontent.com/commercetools/commercetools-api-reference/main/oas/api/openapi.yaml>- [ ] `/{projectKey}/messages` — the change-event stream (OrderStateChanged, PaymentStatusChanged, CustomerCreated...) - state and transition history for everything we already sync (high)- [ ] `/{projectKey}/product-types` — lookup resolving the productType id carried on every synced product projection (high)-- [ ] `/{projectKey}/states` — lookup resolving the state ids on orders, payments, products and reviews; without it order state is an opaque uuid (high)-- [ ] `/{projectKey}/customer-groups` — lookup resolving customerGroup on customers, carts and orders - the standard segmentation dimension (high)-- [ ] `/{projectKey}/channels` — lookup resolving supplyChannel and distributionChannel ids on the inventory and orders we sync (high)-- [ ] `/{projectKey}/stores` — lookup resolving the store on orders and carts; required for any per-store revenue breakdown (high)+- [x] `/{projectKey}/states` — lookup resolving the state ids on orders, payments, products and reviews; without it order state is an opaque uuid (high)+- [x] `/{projectKey}/customer-groups` — lookup resolving customerGroup on customers, carts and orders - the standard segmentation dimension (high)+- [x] `/{projectKey}/channels` — lookup resolving supplyChannel and distributionChannel ids on the inventory and orders we sync (high)+- [x] `/{projectKey}/stores` — lookup resolving the store on orders and carts; required for any per-store revenue breakdown (high)- [ ] `/{projectKey}/shipping-methods` — lookup resolving the shipping method id on orders, plus its zone and rate structure (medium)- [ ] `/{projectKey}/products` — full product master data including staged versus current, which product-projections flattens away (medium)- [ ] `/{projectKey}/cart-discounts` — resolves the discount ids applied to synced carts and orders; discount_codes alone does not explain the discount (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/canonical_descriptions.pyindex 420dfb103ab4..adc447eb9c74 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/canonical_descriptions.py@@ -135,4 +135,49 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {expectedDelivery="Date and time when restocked items are expected to arrive.",),},+ "stores": {+ "description": "A store, modelling the physical or digital context a customer shops in. Orders and carts reference the store they belong to.",+ "docs_url": "https://docs.commercetools.com/api/projects/stores",+ "columns": _columns(+ name="Localized name of the store.",+ languages="Languages configured for the store, as IETF language tags.",+ countries="Countries the store ships to or operates in.",+ distributionChannels="References to the channels the store distributes products through.",+ supplyChannels="References to the channels the store sources inventory from.",+ productSelections="Product selections that control which products the store offers.",+ storefront="Storefront configuration for the store, such as its URLs.",+ ),+ },+ "channels": {+ "description": "A channel, representing a source or destination such as a warehouse or a physical store. Inventory entries and orders reference channels as supply and distribution channels.",+ "docs_url": "https://docs.commercetools.com/api/projects/channels",+ "columns": _columns(+ name="Localized name of the channel.",+ description="Localized description of the channel.",+ roles="Roles the channel can take (InventorySupply, ProductDistribution, OrderExport, OrderImport, Primary).",+ address="Physical address of the channel.",+ geoLocation="Geographic location of the channel, as a GeoJSON point.",+ reviewRatingStatistics="Aggregated review ratings for the channel.",+ ),+ },+ "customer_groups": {+ "description": "A customer group used to segment customers, for example for group-specific prices. Customers, carts and orders reference the group they belong to.",+ "docs_url": "https://docs.commercetools.com/api/projects/customerGroups",+ "columns": _columns(+ name="Unique name of the customer group.",+ ),+ },+ "states": {+ "description": "A state in a custom state machine, used to model the lifecycle of orders, line items, products, reviews and payments.",+ "docs_url": "https://docs.commercetools.com/api/projects/states",+ "columns": _columns(+ type="Resource the state applies to (OrderState, LineItemState, ProductState, ReviewState, PaymentState, QuoteState and others).",+ name="Localized name of the state.",+ description="Localized description of the state.",+ initial="Whether the state is the initial state of its state machine.",+ builtIn="Whether the state is a built-in state that cannot be deleted.",+ roles="Roles the state carries (ReviewIncludedInStatistics, Return).",+ transitions="References to the states this state can transition to. An empty list means no transitions are allowed; absent means all are.",+ ),+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/settings.pyindex 5789e84ba6ac..085ede6975e2 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/settings.py@@ -67,6 +67,26 @@ COMMERCETOOLS_ENDPOINTS: dict[str, CommercetoolsEndpointConfig] = {path="/inventory",scope="view_products",),+ "stores": CommercetoolsEndpointConfig(+ name="stores",+ path="/stores",+ scope="view_stores",+ ),+ "channels": CommercetoolsEndpointConfig(+ name="channels",+ path="/channels",+ scope="view_channels",+ ),+ "customer_groups": CommercetoolsEndpointConfig(+ name="customer_groups",+ path="/customer-groups",+ scope="view_customer_groups",+ ),+ "states": CommercetoolsEndpointConfig(+ name="states",+ path="/states",+ scope="view_states",+ ),}ENDPOINTS = tuple(COMMERCETOOLS_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/source.pyindex 63a98ad78eb2..91e833620681 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/source.py@@ -75,7 +75,7 @@ class CommercetoolsSource(ResumableSource[CommercetoolsSourceConfig, Commercetoolabel="commercetools",caption="""Enter your commercetools API client credentials to pull your commerce data into the PostHog Data warehouse.-Create an API client in the Merchant Center under Settings > Developer settings with the view scopes for the datasets you want to sync (`view_orders`, `view_customers`, `view_payments`, `view_products`, `view_categories`, `view_discount_codes`). Your project key and region are shown alongside the generated credentials.""",+Create an API client in the Merchant Center under Settings > Developer settings with the view scopes for the datasets you want to sync (`view_orders`, `view_customers`, `view_payments`, `view_products`, `view_categories`, `view_discount_codes`, `view_stores`, `view_channels`, `view_customer_groups`, `view_states`). Your project key and region are shown alongside the generated credentials.""",iconPath="/static/services/commercetools.png",docsUrl="https://posthog.com/docs/cdp/sources/commercetools",releaseStatus=ReleaseStatus.ALPHA,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/tests/test_commercetools.py b/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/tests/test_commercetools.pyindex fca82a081837..bf07ec6ab46c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/tests/test_commercetools.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/commercetools/tests/test_commercetools.py@@ -277,3 +277,10 @@ class TestCommercetoolsSourceResponse:@pytest.mark.parametrize("config", list(COMMERCETOOLS_ENDPOINTS.values()))def test_partition_keys_are_stable_creation_fields(self, config):assert config.partition_key == "createdAt"++ @pytest.mark.parametrize("config", list(COMMERCETOOLS_ENDPOINTS.values()))+ def test_paths_are_kebab_case_resource_paths(self, config):+ # Schema names are snake_case but commercetools resource paths are kebab-case,+ # so a path derived from the name (/customer_groups) 404s at sync time.+ assert config.path.startswith("/")+ assert "_" not in config.path