Skip to content

: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.

feat(kustomer): add companies, sub_statuses and satisfaction_forms tables (#113860)

Tom Owers1ff284d4dcd0
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.md
index 2440129c7be3..2f45d3a9e542 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
@@ -4905,10 +4905,10 @@ Today (6): `brands`, `conversations`, `customers`, `tags`, `teams`, `users`
Diffed against: <https://developer.kustomer.com/sitemap.xml>
- [ ] `GET /v1/messages (getmessages)` — the message body of every conversation; conversations without messages cannot answer response-content questions (high)
-- [ ] `GET /v1/customers/{id}/events (getallcustomerevents) and GET /v1/conversations/{id}/events (getconversationevents)` — state-transition history for the conversations and customers already synced (high)
-- [ ] `GET /v1/satisfaction and satisfaction responses (getsatisfaction, getsatisfactionresponse)` — CSAT is the headline support metric and is entirely absent (high)
-- [ ] `GET /v1/companies (getcompanies)` — lookup resolving the company a customer belongs to for account-level support reporting (high)
-- [ ] `GET /v1/substatuses (getsubstatuses)` — lookup resolving the sub-status id carried on every conversation row (high)
+- [ ] `GET /v1/customers/{id}/events (getallcustomerevents) and GET /v1/conversations/{id}/events (getconversationevents)` — state-transition history for the conversations and customers already synced (high). Not added: `getallcustomerevents` is deprecated and returns 404, and `getconversationevents` is per conversation with no updated-since filter on the parent list, so every full-refresh sync would make one or more requests per conversation against the org's shared rate limit.
+- [x] `GET /v1/satisfaction and satisfaction responses (getsatisfaction, getsatisfactionresponse)` — CSAT is the headline support metric and is entirely absent (high). Added as `satisfaction_forms` (`GET /v1/satisfaction` lists survey forms, not responses). `getsatisfactionresponse` skipped: it reads one response by id and there is no list endpoint.
+- [x] `GET /v1/companies (getcompanies)` — lookup resolving the company a customer belongs to for account-level support reporting (high) → `companies`
+- [x] `GET /v1/substatuses (getsubstatuses)` — lookup resolving the sub-status id carried on every conversation row (high) → `sub_statuses` (the real path is `GET /v1/sub-statuses?resource=conversation`)
- [ ] `GET /v1/queues (getqueues) and queue metrics (queuemetrics)` — lookup for routing queues plus the queue-depth metric behind SLA reporting (medium)
- [ ] `GET /v1/notes (getnotesfororg)` — internal agent notes attached to conversations and customers (medium)
- [ ] `GET /v1/work-items (getworkitems) and work sessions (getworksessions)` — agent handling time and routing assignment history (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/canonical_descriptions.py
index 385855cee334..d99359f9dbee 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/canonical_descriptions.py
@@ -100,4 +100,41 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
domains="Domains associated with the brand.",
),
},
+ "companies": {
+ "description": "A company (business account) that customers can be associated with, used for account-level reporting.",
+ "docs_url": "https://developer.kustomer.com/kustomer-api-docs/reference/getcompanies",
+ "columns": _columns(
+ name="The company's name.",
+ externalId="Your own external identifier for the company, if set.",
+ tags="Tags applied to the company.",
+ modifiedAt="Time at which the company was last modified by a user.",
+ ),
+ },
+ "sub_statuses": {
+ "description": "A conversation sub-status, a finer-grained state nested under a conversation status.",
+ "docs_url": "https://developer.kustomer.com/kustomer-api-docs/reference/getsubstatuses",
+ "columns": _columns(
+ label="The sub-status's display label.",
+ description="Description of what the sub-status means.",
+ parentStatus="The conversation status this sub-status belongs to (e.g. open, snoozed, done).",
+ resourceType="Resource type the sub-status applies to (always 'conversation' for this table).",
+ default="Whether this is the default sub-status for its parent status.",
+ ),
+ },
+ "satisfaction_forms": {
+ "description": "A satisfaction (CSAT) survey form, defining when and how customers are asked to rate a conversation.",
+ "docs_url": "https://developer.kustomer.com/kustomer-api-docs/reference/getsatisfaction",
+ "columns": _columns(
+ name="The form's name.",
+ formType="Type of survey form (e.g. csat).",
+ enabled="Whether the form is currently sent to customers.",
+ channel="Channel the survey is sent on (e.g. email, chat).",
+ description="Description of the form.",
+ delayTime="Delay before the survey is sent.",
+ scale="Rating scale settings, such as the number of options and the low and high labels.",
+ ratingPrompt="The rating question shown to the customer.",
+ questions="Follow-up questions on the form.",
+ criteria="Conditions a conversation must meet for the survey to be sent.",
+ ),
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/kustomer.py b/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/kustomer.py
index d32618a0583c..5e88b75f06c3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/kustomer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/kustomer.py
@@ -125,7 +125,7 @@ def kustomer_source(
"name": endpoint,
"endpoint": {
"path": config.path,
- "params": {"page[size]": PAGE_SIZE},
+ "params": {"page[size]": PAGE_SIZE, **config.params},
# JSON:API rows live under `data`. A missing key is a legit
# zero-row page (the hand-rolled loop used `.get("data", [])`),
# so this is NOT required — it stops rather than failing loud.
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.py
index 8c580349475d..4f6671ff79ce 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
@@ -1,19 +1,20 @@
-from dataclasses import dataclass
+from dataclasses import dataclass, field
from products.warehouse_sources.backend.types import IncrementalField
-@dataclass
+@dataclass(frozen=True)
class KustomerEndpointConfig:
path: str
primary_key: str = "id"
+ params: dict[str, str] = field(default_factory=dict)
# Kustomer's GET list endpoints have no updated-since filter (incremental needs
# 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
+# These 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"),
@@ -22,6 +23,11 @@ KUSTOMER_ENDPOINTS: dict[str, KustomerEndpointConfig] = {
"teams": KustomerEndpointConfig(path="/v1/teams"),
"tags": KustomerEndpointConfig(path="/v1/tags"),
"brands": KustomerEndpointConfig(path="/v1/brands"),
+ "companies": KustomerEndpointConfig(path="/v1/companies"),
+ # `resource` is required; conversation sub-statuses resolve the sub-status id on conversation rows.
+ "sub_statuses": KustomerEndpointConfig(path="/v1/sub-statuses", params={"resource": "conversation"}),
+ # Satisfaction (CSAT) form definitions. Responses are only readable one id at a time.
+ "satisfaction_forms": KustomerEndpointConfig(path="/v1/satisfaction"),
}
ENDPOINTS = tuple(KUSTOMER_ENDPOINTS.keys())
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.py
index 2c375e0a0be4..021ed06b725b 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
@@ -36,7 +36,7 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
@SourceRegistry.register
class KustomerSource(ResumableSource[KustomerSourceConfig, KustomerResumeConfig]):
# 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/`
+ # 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).
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/tests/test_kustomer.py b/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/tests/test_kustomer.py
index 360ac397833e..a237db8e630c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/tests/test_kustomer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/kustomer/tests/test_kustomer.py
@@ -1,5 +1,6 @@
import json
from typing import Any
+from urllib.parse import urlparse
import pytest
from unittest import mock
@@ -104,6 +105,19 @@ class TestValidateCredentials:
mock_session.return_value.get.assert_not_called()
+class TestRequestParams:
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_sub_statuses_requests_conversation_resource(self, MockSession):
+ # The sub-statuses list rejects requests without the `resource` filter.
+ session = MockSession.return_value
+ urls = _wire(session, [_response([])])
+
+ _rows(_source("myorg", "key", "sub_statuses", _make_manager()))
+
+ assert urlparse(urls[0]).path == "/v1/sub-statuses"
+ assert session.prepare_request.call_args.args[0].params["resource"] == "conversation"
+
+
class TestPagination:
@mock.patch(CLIENT_SESSION_PATCH)
def test_paginates_via_links_next_and_absolutizes(self, MockSession):
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.py
index 380f06241a0f..c6b9f6ca51bb 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
@@ -17,6 +17,18 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.kustomer.s
# The REST framework builds its session via make_tracked_session in the rest_client module.
CLIENT_SESSION_PATCH = "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.rest_client.make_tracked_session"
+EXPECTED_PATHS = {
+ "customers": "/v1/customers",
+ "conversations": "/v1/conversations",
+ "users": "/v1/users",
+ "teams": "/v1/teams",
+ "tags": "/v1/tags",
+ "brands": "/v1/brands",
+ "companies": "/v1/companies",
+ "sub_statuses": "/v1/sub-statuses",
+ "satisfaction_forms": "/v1/satisfaction",
+}
+
class TestKustomerSource:
def setup_method(self):
@@ -59,8 +71,8 @@ class TestKustomerSource:
@mock.patch(CLIENT_SESSION_PATCH)
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.
+ # must not switch to /v2/, which would 404 the stream. Covering every endpoint
+ # also guards against a per-resource /v2/ typo in the endpoint catalog.
session = mock_session.return_value
session.headers = {}
captured: list[str] = []
@@ -87,4 +99,4 @@ class TestKustomerSource:
list(cast(Iterable[Any], response.items()))
assert captured, "expected at least one request"
- assert urlparse(captured[0]).path == f"/v1/{endpoint}"
+ assert urlparse(captured[0]).path == EXPECTED_PATHS[endpoint]