: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(capsule-crm): add entries, boards, stages and tag tables (#101611)
Tom Owersa22fabeb6744
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 7e956c146a15..96761402a61b 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@@ -1262,15 +1262,15 @@ Note: Roadmaps are documented as an object but Canny explicitly says roadmap dat## CapsuleCRM — gaps-Today (9): `categories`, `kases`, `lost_reasons`, `milestones`, `opportunities`, `parties`, `pipelines`, `tasks`, `users`+Today (15): `boards`, `categories`, `entries`, `kase_tags`, `kases`, `lost_reasons`, `milestones`, `opportunities`, `opportunity_tags`, `parties`, `party_tags`, `pipelines`, `stages`, `tasks`, `users`Diffed against: <https://developer.capsulecrm.com/v2/operations/Party>-- [ ] `Entry (GET /api/v2/entries/filter or listEntriesByDate)` — the notes, emails and activity timeline on parties, opportunities and projects - the main behavioral history in Capsule (high)-- [ ] `Tag (GET /api/v2/tags, listTags tag definitions)` — lookup resolving the tag IDs embedded on parties, opportunities and kases we already sync (high)-- [ ] `Stage (GET /api/v2/stages, listStages)` — lookup for the board stage IDs carried on opportunities and projects (high)+- [x] `Entry (GET /api/v2/entries/filter or listEntriesByDate)` — the notes, emails and activity timeline on parties, opportunities and projects - the main behavioral history in Capsule (high). Added as `entries` via `listEntriesByDate` (`GET /api/v2/entries`); `/api/v2/entries/filter` does not exist, and the Filter API covers parties, opportunities and kases only.+- [x] `Tag (GET /api/v2/tags, listTags tag definitions)` — lookup resolving the tag IDs embedded on parties, opportunities and kases we already sync (high). There is no top-level `/api/v2/tags`; tag definitions are scoped per entity, so this landed as `party_tags`, `opportunity_tags` and `kase_tags`.+- [x] `Stage (GET /api/v2/stages, listStages)` — lookup for the board stage IDs carried on opportunities and projects (high). Stages belong to project boards; opportunities carry milestones, which are already synced.- [ ] `Custom Field (GET /api/v2/fields/definitions, listFields)` — field-definition lookup that names the custom field values embedded in parties/opportunities (medium)-- [ ] `Board (GET /api/v2/boards, listBoards)` — lookup that groups stages, needed to interpret stage-level funnel data (medium)+- [x] `Board (GET /api/v2/boards, listBoards)` — lookup that groups stages, needed to interpret stage-level funnel data (medium)- [ ] `Team (GET /api/v2/teams, listTeams)` — lookup resolving team ownership on users, tasks and opportunities (medium)- [ ] `Goal (GET /api/v2/goals, listGoals + listGoalPeriods)` — sales targets per user/period - the denominator for quota attainment reporting (medium)- [ ] `Track (GET /api/v2/tracks, listTrack)` — lookup for the task-sequence templates that generate the tasks we sync (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/canonical_descriptions.pyindex 0e66468110bb..39529e376baf 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/canonical_descriptions.py@@ -151,4 +151,79 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"name": "The lost reason's text.",},},+ "entries": {+ "description": "An item on the activity timeline - a note, an email, or a completed task - attached to a party, opportunity or project.",+ "docs_url": "https://developer.capsulecrm.com/v2/operations/Entry",+ "columns": {+ "id": "Unique identifier for the entry.",+ "type": "The kind of entry: 'note', 'email' or 'task'.",+ "subject": "The subject line (email entries only).",+ "content": "The body text of the entry.",+ "entryAt": "Time the entry happened, which the user can change.",+ "creator": "The user who created the entry.",+ "activityType": "The activity type of the entry, such as Note or Email sent.",+ "party": "The party the entry is attached to.",+ "parties": "The parties an email entry was exchanged with.",+ "kase": "The project the entry is on.",+ "opportunity": "The opportunity the entry is on.",+ "attachments": "Files attached to the entry, with filename, content type and size.",+ "participants": "Email participants, each with an address, name and FROM or TO role.",+ "createdAt": "Time the entry was created.",+ "updatedAt": "Time the entry was last updated.",+ },+ },+ "boards": {+ "description": "A project board that groups the stages a project moves through. Includes archived boards.",+ "docs_url": "https://developer.capsulecrm.com/v2/operations/Board",+ "columns": {+ "id": "Unique identifier for the board.",+ "name": "The board's name.",+ "description": "Free-text description of the board.",+ "createdAt": "Time the board was created.",+ "updatedAt": "Time the board was last updated.",+ },+ },+ "stages": {+ "description": "A stage on a project board. Resolves the stage a project is currently in. Includes archived stages and stages on archived boards.",+ "docs_url": "https://developer.capsulecrm.com/v2/operations/Stage",+ "columns": {+ "id": "Unique identifier for the stage.",+ "name": "The stage's name.",+ "description": "Free-text description of the stage.",+ "board": "The board this stage belongs to.",+ "displayOrder": "Position of the stage on its board.",+ "createdAt": "Time the stage was created.",+ "updatedAt": "Time the stage was last updated.",+ },+ },+ "party_tags": {+ "description": "A tag definition that can be applied to parties. Resolves the tag IDs embedded on the parties table.",+ "docs_url": "https://developer.capsulecrm.com/v2/operations/Tag",+ "columns": {+ "id": "Unique identifier for the tag.",+ "name": "The tag's name.",+ "description": "Free-text description of the tag.",+ "dataTag": "Whether the tag is a data tag, which carries its own custom fields.",+ },+ },+ "opportunity_tags": {+ "description": "A tag definition that can be applied to opportunities. Resolves the tag IDs embedded on the opportunities table.",+ "docs_url": "https://developer.capsulecrm.com/v2/operations/Tag",+ "columns": {+ "id": "Unique identifier for the tag.",+ "name": "The tag's name.",+ "description": "Free-text description of the tag.",+ "dataTag": "Whether the tag is a data tag, which carries its own custom fields.",+ },+ },+ "kase_tags": {+ "description": "A tag definition that can be applied to projects. Resolves the tag IDs embedded on the kases table.",+ "docs_url": "https://developer.capsulecrm.com/v2/operations/Tag",+ "columns": {+ "id": "Unique identifier for the tag.",+ "name": "The tag's name.",+ "description": "Free-text description of the tag.",+ "dataTag": "Whether the tag is a data tag, which carries its own custom fields.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/capsule-crm.mdx b/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/capsule-crm.mdxindex f24a87155d7f..ac77f807a7fc 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/capsule-crm.mdx+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/capsule-crm.mdx@@ -15,7 +15,7 @@ import AlphaRelease from '../_snippets/alpha-release.mdx'<AlphaRelease />-Capsule CRM is a CRM for small and medium businesses covering contacts, the sales pipeline, and project management. This connector syncs your Capsule contacts, opportunities, projects, tasks, and supporting reference data into the PostHog data warehouse so you can join CRM records with your product and revenue data.+Capsule CRM is a CRM for small and medium businesses covering contacts, the sales pipeline, and project management. This connector syncs your Capsule contacts, opportunities, projects, tasks, activity timeline, and supporting reference data into the PostHog data warehouse so you can join CRM records with your product and revenue data.## Prerequisites@@ -37,7 +37,9 @@ Capsule's API is rate limited to roughly 4,000 requests per hour per user, so ve<SyncModes />-Parties, opportunities, and projects support **incremental** syncs using Capsule's `since` change filter (tracked on `updatedAt`), so ongoing syncs only pull records that changed since the last run. The remaining tables (tasks, users, milestones, pipelines, categories, and lost reasons) are full refresh only, since Capsule does not expose a server-side change filter for them.+Parties, opportunities, and projects support **incremental** syncs using Capsule's `since` change filter (tracked on `updatedAt`), so ongoing syncs only pull records that changed since the last run. The remaining tables (entries, tasks, users, milestones, pipelines, categories, lost reasons, boards, stages, and the tag tables) are full refresh only, since Capsule does not expose a server-side change filter for them.++The `entries` table holds your activity timeline: notes, emails, and completed tasks. It's usually the largest table in a Capsule account, and Capsule has no change filter for it, so every sync pulls the full history. Sync it on a schedule that suits its size.## Configurationdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/capsule_crm.py b/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/capsule_crm.pyindex 8d93bbd49006..c71ece7d38ba 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/capsule_crm.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/capsule_crm.py@@ -113,7 +113,7 @@ def capsule_crm_source() -> SourceResponse:config = CAPSULE_CRM_ENDPOINTS[endpoint]- params: dict[str, Any] = {"perPage": PAGE_SIZE}+ params: dict[str, Any] = {"perPage": PAGE_SIZE, **config.extra_params}if config.embed:params["embed"] = config.embedif config.supports_since and should_use_incremental_field and db_incremental_field_last_value is not None:@@ -181,7 +181,7 @@ def capsule_crm_source(# Capsule does not document an ordering guarantee for `since`, but the ResumableSource# next-URL state (not the watermark) drives mid-sync resume, so the dominant interruption# path is order-independent. `asc` matches the framework's default incremental checkpointing.- sort_mode="asc",+ sort_mode=config.sort_mode,)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/settings.pyindex 3d9029f4b3b3..205b7267d579 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/settings.py@@ -1,10 +1,11 @@from dataclasses import dataclass, field-from typing import Optional+from typing import Any, Optional+from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SortModefrom products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType-@dataclass+@dataclass(frozen=True)class CapsuleCRMEndpointConfig:name: strpath: str@@ -19,6 +20,11 @@ class CapsuleCRMEndpointConfig:partition_key: Optional[str] = None# Comma-separated `embed` values folded into each request to pull related data in one round-trip.embed: Optional[str] = None+ # Extra query params folded into every request for this endpoint.+ extra_params: dict[str, Any] = field(default_factory=dict)+ # Order rows arrive in. Capsule documents no ordering for most list endpoints; `entries` is the+ # one that explicitly returns newest first.+ sort_mode: SortMode = "asc"primary_keys: list[str] = field(default_factory=lambda: ["id"])should_sync_default: bool = True@@ -100,6 +106,53 @@ CAPSULE_CRM_ENDPOINTS: dict[str, CapsuleCRMEndpointConfig] = {data_key="lostReasons",incremental_fields=[],),+ "entries": CapsuleCRMEndpointConfig(+ name="entries",+ path="/entries",+ data_key="entries",+ partition_key="createdAt",+ # `listEntriesByDate` omits the associations and the creator/type lookups unless they are+ # embedded, and without them a row cannot be joined back to the record it belongs to.+ embed="party,kase,opportunity,creator,activityType",+ # Documented as "descending order starting with the most recent entry date first".+ sort_mode="desc",+ incremental_fields=[],+ ),+ "boards": CapsuleCRMEndpointConfig(+ name="boards",+ path="/boards",+ data_key="boards",+ # `status` defaults to `active`, which would drop archived boards that historic projects+ # still point at.+ extra_params={"status": "all"},+ incremental_fields=[],+ ),+ "stages": CapsuleCRMEndpointConfig(+ name="stages",+ path="/stages",+ data_key="stages",+ # Same reasoning as boards: a stage on an archived board still needs to resolve.+ extra_params={"status": "all", "includeOnDeletedBoard": "true"},+ incremental_fields=[],+ ),+ "party_tags": CapsuleCRMEndpointConfig(+ name="party_tags",+ path="/parties/tags",+ data_key="tags",+ incremental_fields=[],+ ),+ "opportunity_tags": CapsuleCRMEndpointConfig(+ name="opportunity_tags",+ path="/opportunities/tags",+ data_key="tags",+ incremental_fields=[],+ ),+ "kase_tags": CapsuleCRMEndpointConfig(+ name="kase_tags",+ path="/kases/tags",+ data_key="tags",+ incremental_fields=[],+ ),}ENDPOINTS = tuple(CAPSULE_CRM_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/tests/test_capsule_crm.py b/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/tests/test_capsule_crm.pyindex f04185d9ff78..f730769ee92a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/tests/test_capsule_crm.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/capsule_crm/tests/test_capsule_crm.py@@ -192,6 +192,54 @@ class TestRequestParams:assert snapshots[0]["params"]["since"] == "2026-06-15T12:00:00Z"+ @parameterized.expand(+ [+ ("boards", "boards", {"status": "all"}),+ ("stages", "stages", {"status": "all", "includeOnDeletedBoard": "true"}),+ ]+ )+ @mock.patch(SESSION_PATCH)+ def test_lookup_endpoints_request_archived_records(+ self, endpoint: str, data_key: str, expected: dict[str, Any], MockSession+ ) -> None:+ # Capsule defaults these to active-only, which would drop the boards and stages that+ # historic projects still point at.+ session = MockSession.return_value+ snapshots = _wire(session, [_response({data_key: []})])++ _rows(_source(_make_manager(), endpoint=endpoint))++ assert snapshots[0]["params"] == {"perPage": 100, **expected}++ @mock.patch(SESSION_PATCH)+ def test_entries_embeds_its_associations(self, MockSession) -> None:+ # Without the embeds an entry cannot be joined back to the record it belongs to.+ session = MockSession.return_value+ snapshots = _wire(session, [_response({"entries": []})])++ _rows(_source(_make_manager(), endpoint="entries"))++ assert snapshots[0]["params"]["embed"] == "party,kase,opportunity,creator,activityType"++ @parameterized.expand(+ [+ ("party_tags", f"{CAPSULE_CRM_BASE_URL}/parties/tags"),+ ("opportunity_tags", f"{CAPSULE_CRM_BASE_URL}/opportunities/tags"),+ ("kase_tags", f"{CAPSULE_CRM_BASE_URL}/kases/tags"),+ ]+ )+ @mock.patch(SESSION_PATCH)+ def test_tag_endpoints_are_entity_scoped(self, endpoint: str, expected_url: str, MockSession) -> None:+ # Capsule has no top-level /tags collection; tag definitions hang off each entity type and+ # all three nest under the same "tags" wrapper key.+ session = MockSession.return_value+ snapshots = _wire(session, [_response({"tags": [{"id": 3, "name": "VIP"}]})])++ rows = _rows(_source(_make_manager(), endpoint=endpoint))++ assert snapshots[0]["url"] == expected_url+ assert rows == [{"id": 3, "name": "VIP"}]+@mock.patch(SESSION_PATCH)def test_since_ignored_for_full_refresh_only_endpoint(self, MockSession) -> None:# tasks has no server-side `since` filter, so a watermark must not produce a `since` param.@@ -416,9 +464,31 @@ class TestSourceResponse:assert response.partition_keys == [partition_key]assert response.sort_mode == "asc"- @parameterized.expand([("users",), ("milestones",), ("pipelines",), ("categories",), ("lost_reasons",)])+ def test_entries_partitions_on_created_at_and_sorts_desc(self) -> None:+ # `entryAt` is user-editable, so partitioning follows `createdAt`. Capsule serves this+ # endpoint most-recent-first, which the pipeline has to be told about.+ response = _source(_make_manager(), endpoint="entries")+ assert response.partition_mode == "datetime"+ assert response.partition_keys == ["createdAt"]+ assert response.sort_mode == "desc"++ @parameterized.expand(+ [+ ("users",),+ ("milestones",),+ ("pipelines",),+ ("categories",),+ ("lost_reasons",),+ ("boards",),+ ("stages",),+ ("party_tags",),+ ("opportunity_tags",),+ ("kase_tags",),+ ]+ )def test_metadata_endpoints_are_unpartitioned(self, endpoint: str) -> None:response = _source(_make_manager(), endpoint=endpoint)assert response.primary_keys == ["id"]assert response.partition_mode is Noneassert response.partition_keys is None+ assert response.sort_mode == "asc"