: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(salesloft): add 4 missing tables to the Sales Loft source (#129123)
Tom Owers58730fe9309c
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 e355d688e176..bf12e2e2a207 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@@ -10583,11 +10583,11 @@ Today (28): `account_stages`, `account_tiers`, `accounts`, `actions`, `cadence_mDiffed against: <https://developers.salesloft.com/docs/api/opportunities-index/>-- [ ] `opportunities` — core revenue object synced from the CRM; currently no way to tie cadence activity to pipeline (high)+- [x] `opportunities` — core revenue object synced from the CRM; currently no way to tie cadence activity to pipeline (high)- [ ] `opportunity_stages` — lookup resolving the stage id on every opportunity (high)-- [ ] `tasks` — the rep work queue — completion rates are a primary Salesloft metric (high)-- [ ] `activity_histories` — unified transition/activity timeline across people and accounts (high)-- [ ] `cadence_stats` — the vendor's headline cadence performance metric (opens, replies, conversions) (high)+- [x] `tasks` — the rep work queue — completion rates are a primary Salesloft metric (high)+- [x] `activity_histories` — unified transition/activity timeline across people and accounts (high)+- [x] `cadence_stats` — the vendor's headline cadence performance metric (opens, replies, conversions) (high)- [ ] `tags` — lookup resolving tag ids attached to people, accounts and cadences (medium)- [ ] `account_types` — lookup resolving the account_type id already carried on accounts (medium)- [ ] `opportunity_people` — join table linking people to opportunities (medium)diff --git a/products/warehouse_sources/sources/salesloft/canonical_descriptions.py b/products/warehouse_sources/sources/salesloft/canonical_descriptions.pyindex ffed97f73ed4..e2dab88a7a9e 100644--- a/products/warehouse_sources/sources/salesloft/canonical_descriptions.py+++ b/products/warehouse_sources/sources/salesloft/canonical_descriptions.py@@ -35,6 +35,22 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {archived_at="Time at which the account was archived, if archived.",),},+ "activity_histories": {+ "description": "A past activity from the Salesloft activity feed, attributed to a person, account, or CRM opportunity.",+ "docs_url": "https://developers.salesloft.com/docs/api/activity-histories-index",+ "columns": _columns(+ id="Identifier of the activity, in `{type}-{id}` format.",+ type="Type of the activity (e.g. email, call).",+ occurred_at="Time at which the activity occurred.",+ pinned_at="Time at which the activity was pinned, if pinned.",+ resource_type="Type of the record the activity is attributed to (person, account, or crm_opportunity).",+ resource_id="Identifier of the record the activity is attributed to.",+ user_guid="UUID of the user the activity is for.",+ static_data="Data captured when the activity was recorded.",+ dynamic_data="Data resolved from related records when the activity is read.",+ tags="Tags applied to the activity.",+ ),+ },"account_stages": {"description": "A stage that an account can be assigned to, representing its position in a workflow.","docs_url": "https://developers.salesloft.com/docs/api/account-stages-index",@@ -79,6 +95,34 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {creator="The user who created the cadence.",),},+ "cadence_stats": {+ "description": "Aggregate performance stats for one cadence: people, emails, calls, replies, meetings, and opportunities.",+ "docs_url": "https://developers.salesloft.com/docs/api/cadence-stats-show",+ "columns": {+ "cadence_id": "Identifier of the cadence the stats belong to.",+ "cadence_people_count": "Number of people ever added to the cadence.",+ "people_acted_on_count": "Number of people skipped, scheduled, or advanced in the cadence.",+ "in_progress_people_count": "Number of people currently in the cadence.",+ "sent_emails_count": "Number of emails sent in the cadence.",+ "delivered_count": "Number of emails successfully delivered in the cadence.",+ "bounced_count": "Number of emails that bounced in the cadence.",+ "viewed_count": "Number of emails viewed in the cadence.",+ "clicked_count": "Number of links clicked in the cadence.",+ "replied_count": "Number of emails that received a reply in the cadence.",+ "calls_count": "Number of calls made in the cadence.",+ "viewed_rate": "Percentage of emails viewed in the cadence.",+ "clicked_rate": "Percentage of delivered emails where a link was clicked.",+ "replied_rate": "Percentage of emails that received a reply in the cadence.",+ "meetings_booked_count": "Number of meetings booked and attributed to the cadence.",+ "meetings_booked_rate": "Percentage of people who booked a meeting after being added to the cadence.",+ "opportunities_created_count": "Number of opportunities created and attributed to the cadence.",+ "opportunities_created_rate": "Percentage of people who became an opportunity after being added to the cadence.",+ "step_group_count": "Number of step groups in the cadence.",+ "due_action_count": "Number of due actions in the cadence.",+ "cadence_duration": "Duration of the cadence in days.",+ "outcome_attribution_enabled": "Whether outcome attribution is enabled for the cadence.",+ },+ },"cadence_memberships": {"description": "The relationship between a person and a cadence they are enrolled in.","docs_url": "https://developers.salesloft.com/docs/api/cadence-memberships-index",@@ -242,6 +286,33 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {associated_id="ID of the object the note is associated with.",),},+ "opportunities": {+ "description": "A sales opportunity synced from the CRM or created through the API.",+ "docs_url": "https://developers.salesloft.com/docs/api/opportunities-index",+ "columns": _columns(+ name="Name of the opportunity.",+ amount="Estimated total sale amount.",+ currency_iso_code="ISO code of the currency of the amount.",+ stage_name="Name of the opportunity stage.",+ probability="Probability that the opportunity closes.",+ opportunity_type="Type of the opportunity.",+ close_date="Date the opportunity is expected to close.",+ is_closed="Whether the opportunity is closed.",+ is_won="Whether the opportunity is closed won.",+ crm_id="Identifier of the opportunity in the CRM.",+ crm_type="Type of the CRM the opportunity comes from.",+ crm_url="URL of the opportunity in the CRM.",+ crm_last_updated_date="Time at which the opportunity was last updated in the CRM.",+ created_date="Time at which the opportunity was created in the CRM.",+ account="The account the opportunity is associated with.",+ owner="The user who owns the opportunity.",+ creator="The user who created the opportunity.",+ most_recent_cadence="The most recent cadence associated with the opportunity.",+ most_recent_step="The most recent cadence step associated with the opportunity.",+ custom_fields="Custom field values defined by the team.",+ tags="Tags applied to the opportunity.",+ ),+ },"people": {"description": "An individual contact tracked in Salesloft.","docs_url": "https://developers.salesloft.com/docs/api/people-index",@@ -298,6 +369,26 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {succeeded_at="Time at which the success occurred.",),},+ "tasks": {+ "description": "A task assigned to a user, such as a call, email, or general to-do. Tasks from cadence steps are not included.",+ "docs_url": "https://developers.salesloft.com/docs/api/tasks-index",+ "columns": _columns(+ subject="Subject line of the task.",+ description="Description recorded for the person when the task was completed.",+ task_type="Type of the task (call, email, or general).",+ current_state="State of the task (scheduled or completed).",+ due_date="Date the task is due.",+ due_at="Time at which the task is due.",+ remind_at="Time at which the user is reminded of the task.",+ expires_after="Time at which the task expires.",+ completed_at="Time at which the task was completed.",+ person="The person to contact.",+ opportunity="The opportunity associated with the task.",+ user="The user the task is assigned to.",+ created_by_user="The user who created the task.",+ completed_by="The user who completed the task.",+ ),+ },"team_templates": {"description": "An email template shared and managed at the team level.","docs_url": "https://developers.salesloft.com/docs/api/team-templates-index",diff --git a/products/warehouse_sources/sources/salesloft/salesloft.py b/products/warehouse_sources/sources/salesloft/salesloft.pyindex 5df2b94abd0c..f5e65f9accd1 100644--- a/products/warehouse_sources/sources/salesloft/salesloft.py+++ b/products/warehouse_sources/sources/salesloft/salesloft.py@@ -4,24 +4,25 @@ from typing import Any, Optionalfrom urllib.parse import parse_qs, urlparsefrom products.warehouse_sources.sources.salesloft.settings import (+ PAGE_SIZE,SALESLOFT_ENDPOINTS,SALESLOFT_UPDATED_AT_FIELD,SalesloftEndpointConfig,)from products.warehouse_sources.sources.sdk import (+ ClientConfig,+ DependentEndpointConfig,JSONResponseCursorPaginator,RESTAPIConfig,ResumableSourceManager,SourceResponse,+ build_dependent_resource,make_tracked_session,rest_api_resource,validate_via_probe,)SALESLOFT_BASE_URL = "https://api.salesloft.com/v2"-# Salesloft caps per_page at 100; larger pages keep us under the per-page rate-limit-# cost penalties that escalate past page 100.-PAGE_SIZE = 100@dataclasses.dataclass(frozen=False)@@ -32,6 +33,8 @@ class SalesloftResumeConfig:# legacy ``next_url``.next_url: str = ""next_page: Optional[int] = None+ # Fan-out endpoints (cadence_stats) save the framework's per-parent checkpoint here instead.+ fanout_state: Optional[dict[str, Any]] = Nonedef _format_datetime(value: Any) -> str:@@ -56,9 +59,11 @@ def _build_params(params: dict[str, Any] = {"per_page": PAGE_SIZE}if config.incremental:- # Default sort key on these endpoints is `updated_at`; ascending order lets the- # pipeline advance its incremental watermark deterministically.+ # The default sort key is `updated_at` unless the endpoint sets `sort_by`; ascending order+ # lets the pipeline advance its incremental watermark deterministically.params["sort_direction"] = "ASC"+ if config.sort_by:+ params["sort_by"] = config.sort_byif should_use_incremental_field and db_incremental_field_last_value is not None:filter_field = incremental_field or SALESLOFT_UPDATED_AT_FIELD@@ -90,6 +95,66 @@ def validate_credentials(api_key: str) -> bool:return ok+def _client_config(api_key: str) -> ClientConfig:+ return {+ "base_url": SALESLOFT_BASE_URL,+ # Auth (Bearer) is supplied via the framework auth config so its value is redacted from+ # logs and raised errors; only the non-secret Accept header is set here.+ "headers": {"Accept": "application/json"},+ "auth": {"type": "bearer", "token": api_key},+ }+++def _page_paginator() -> JSONResponseCursorPaginator:+ # Salesloft returns the next page NUMBER in the body; feed it back as the `page` query param.+ # A null `next_page` stops pagination — matching the API's own end-of-list signal rather than+ # probing one extra empty page.+ return JSONResponseCursorPaginator(cursor_path="metadata.paging.next_page", cursor_param="page")+++def _fanout_source(+ api_key: str,+ config: SalesloftEndpointConfig,+ fanout: DependentEndpointConfig,+ team_id: int,+ job_id: str,+ resumable_source_manager: ResumableSourceManager[SalesloftResumeConfig],+) -> SourceResponse:+ initial_paginator_state: Optional[dict[str, Any]] = None+ if resumable_source_manager.can_resume():+ resume = resumable_source_manager.load_state()+ if resume is not None and resume.fanout_state:+ initial_paginator_state = resume.fanout_state++ def save_checkpoint(state: Optional[dict[str, Any]]) -> None:+ resumable_source_manager.save_state(SalesloftResumeConfig(fanout_state=state))++ resource = build_dependent_resource(+ endpoint_configs=SALESLOFT_ENDPOINTS,+ child_endpoint=config.name,+ fanout=fanout,+ client_config=_client_config(api_key),+ path_format_values={},+ team_id=team_id,+ job_id=job_id,+ db_incremental_field_last_value=None,+ # The child is a single-object endpoint that takes no page-size param; the parent's rides+ # in `parent_params`.+ page_size_param=None,+ parent_endpoint_extra={"paginator": _page_paginator(), "data_selector": "data"},+ child_endpoint_extra={"paginator": "single_page", "data_selector": "data"},+ resume_hook=save_checkpoint,+ initial_paginator_state=initial_paginator_state,+ )++ return SourceResponse(+ name=config.name,+ items=lambda: resource,+ primary_keys=config.primary_keys,+ partition_mode=None,+ )++def salesloft_source(api_key: str,endpoint: str,@@ -102,16 +167,13 @@ def salesloft_source() -> SourceResponse:config = SALESLOFT_ENDPOINTS[endpoint]+ if config.fanout is not None:+ return _fanout_source(api_key, config, config.fanout, team_id, job_id, resumable_source_manager)+params = _build_params(config, should_use_incremental_field, db_incremental_field_last_value, incremental_field)rest_config: RESTAPIConfig = {- "client": {- "base_url": SALESLOFT_BASE_URL,- # Auth (Bearer) is supplied via the framework auth config so its value is redacted from- # logs and raised errors; only the non-secret Accept header is set here.- "headers": {"Accept": "application/json"},- "auth": {"type": "bearer", "token": api_key},- },+ "client": _client_config(api_key),"resource_defaults": {},"resources": [{@@ -120,12 +182,7 @@ def salesloft_source("path": config.path,"params": params,"data_selector": "data",- # Salesloft returns the next page NUMBER in the body; feed it back as the- # `page` query param. A null `next_page` stops pagination — matching the API's- # own end-of-list signal rather than probing one extra empty page.- "paginator": JSONResponseCursorPaginator(- cursor_path="metadata.paging.next_page", cursor_param="page"- ),+ "paginator": _page_paginator(),},}],@@ -159,7 +216,7 @@ def salesloft_source(return SourceResponse(name=endpoint,items=lambda: resource,- primary_keys=["id"],+ primary_keys=config.primary_keys,partition_mode="datetime" if config.partition_key else None,partition_format="month" if config.partition_key else None,partition_keys=[config.partition_key] if config.partition_key else None,diff --git a/products/warehouse_sources/sources/salesloft/settings.py b/products/warehouse_sources/sources/salesloft/settings.pyindex 97d7421f048f..f8638eb148cb 100644--- a/products/warehouse_sources/sources/salesloft/settings.py+++ b/products/warehouse_sources/sources/salesloft/settings.py@@ -1,7 +1,7 @@-from dataclasses import dataclass+from dataclasses import dataclass, fieldfrom typing import Optional-from products.warehouse_sources.sources.sdk import IncrementalField, IncrementalFieldType+from products.warehouse_sources.sources.sdk import DependentEndpointConfig, IncrementalField, IncrementalFieldType# Salesloft v2 resources. Endpoint set + incremental support mirror the canonical# Airbyte connector (`source-salesloft`), which is the authoritative reference for@@ -15,6 +15,9 @@ from products.warehouse_sources.sources.sdk import IncrementalField, Incremental# payload actually carries `created_at` (some join/attachment resources do not).SALESLOFT_UPDATED_AT_FIELD = "updated_at"+# Salesloft caps per_page at 100; larger pages keep us under the per-page rate-limit+# cost penalties that escalate past page 100.+PAGE_SIZE = 100@dataclass(frozen=False)@@ -23,6 +26,15 @@ class SalesloftEndpointConfig:path: strincremental: bool = Falsepartition_key: Optional[str] = None+ # Set where the endpoint's default `sort_by` is not `updated_at` (tasks, activity_histories).+ sort_by: Optional[str] = None+ primary_keys: list[str] = field(default_factory=lambda: ["id"])+ fanout: Optional[DependentEndpointConfig] = None+ page_size: int = PAGE_SIZE++ @property+ def default_incremental_field(self) -> Optional[str]:+ return SALESLOFT_UPDATED_AT_FIELD if self.incremental else None@propertydef incremental_fields(self) -> list[IncrementalField]:@@ -38,8 +50,8 @@ class SalesloftEndpointConfig:]-def _incremental(name: str, path: str) -> SalesloftEndpointConfig:- return SalesloftEndpointConfig(name=name, path=path, incremental=True, partition_key="created_at")+def _incremental(name: str, path: str, sort_by: Optional[str] = None) -> SalesloftEndpointConfig:+ return SalesloftEndpointConfig(name=name, path=path, incremental=True, partition_key="created_at", sort_by=sort_by)def _full_refresh(name: str, path: str, partition_key: Optional[str] = "created_at") -> SalesloftEndpointConfig:@@ -51,6 +63,7 @@ SALESLOFT_ENDPOINTS: dict[str, SalesloftEndpointConfig] = {"accounts": _incremental("accounts", "/accounts"),"account_stages": _incremental("account_stages", "/account_stages"),"actions": _incremental("actions", "/actions"),+ "activity_histories": _incremental("activity_histories", "/activity_histories", sort_by="updated_at"),"cadences": _incremental("cadences", "/cadences"),"cadence_memberships": _incremental("cadence_memberships", "/cadence_memberships"),"call_data_records": _incremental("call_data_records", "/call_data_records"),@@ -59,8 +72,10 @@ SALESLOFT_ENDPOINTS: dict[str, SalesloftEndpointConfig] = {"emails": _incremental("emails", "/activities/emails"),"email_templates": _incremental("email_templates", "/email_templates"),"notes": _incremental("notes", "/notes"),+ "opportunities": _incremental("opportunities", "/opportunities", sort_by="updated_at"),"people": _incremental("people", "/people"),"successes": _incremental("successes", "/successes"),+ "tasks": _incremental("tasks", "/tasks", sort_by="updated_at"),"team_templates": _incremental("team_templates", "/team_templates"),# Full refresh (no reliable server-side timestamp filter; mostly reference/config data)"account_tiers": _full_refresh("account_tiers", "/account_tiers"),@@ -83,6 +98,24 @@ SALESLOFT_ENDPOINTS: dict[str, SalesloftEndpointConfig] = {"team_template_attachments", "/team_template_attachments", partition_key=None),"users": _full_refresh("users", "/users"),+ # Fan-out: Salesloft serves cadence stats one cadence at a time (`/cadence_stats/{id}`), and the+ # payload carries no cadence id, so the parent id is injected as `cadence_id`.+ "cadence_stats": SalesloftEndpointConfig(+ name="cadence_stats",+ path="/cadence_stats/{cadence_id}",+ primary_keys=["cadence_id"],+ fanout=DependentEndpointConfig(+ parent_name="cadences",+ resolve_param="cadence_id",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "cadence_id"},+ # A stable sort keeps page boundaries fixed while cadences are added during the walk.+ parent_params={"per_page": PAGE_SIZE, "sort_by": "created_at", "sort_direction": "ASC"},+ # A cadence deleted between the listing and its stats fetch 404s; skip it.+ child_response_actions=[{"status_code": 404, "action": "ignore"}],+ ),+ ),}ENDPOINTS = tuple(SALESLOFT_ENDPOINTS.keys())diff --git a/products/warehouse_sources/sources/salesloft/tests/test_salesloft.py b/products/warehouse_sources/sources/salesloft/tests/test_salesloft.pyindex b04095476aba..8619305fdc5e 100644--- a/products/warehouse_sources/sources/salesloft/tests/test_salesloft.py+++ b/products/warehouse_sources/sources/salesloft/tests/test_salesloft.py@@ -15,7 +15,13 @@ from products.warehouse_sources.sources.salesloft.salesloft import ()from products.warehouse_sources.sources.salesloft.settings import SALESLOFT_ENDPOINTSfrom products.warehouse_sources.sources.salesloft.source import SalesLoftSource-from products.warehouse_sources.sources.sdk.testing import ScriptedResponse, SourceDriver, always, scripted_network+from products.warehouse_sources.sources.sdk.testing import (+ ScriptedResponse,+ SourceDriver,+ always,+ route,+ scripted_network,+)def _response(items: list[dict[str, Any]] | None, next_page: int | None, status: int = 200) -> ScriptedResponse:@@ -55,6 +61,95 @@ class TestBuildParams:assert "updated_at[gte]" in params+class TestIncrementalRequestShaping:+ @pytest.mark.parametrize(+ "endpoint, expected_sort_by",+ [+ # Their default sort keys (due_date, occurred_at) would break the ascending watermark.+ ("tasks", "updated_at"),+ ("activity_histories", "updated_at"),+ ("opportunities", "updated_at"),+ # Endpoints whose default sort key is already updated_at send no sort_by.+ ("people", None),+ ],+ )+ def test_incremental_run_sorts_and_filters_on_updated_at(self, endpoint: str, expected_sort_by: str | None) -> None:+ result = _driver().run(+ endpoint,+ [_response([{"id": 1}], next_page=None)],+ should_use_incremental_field=True,+ incremental_field="updated_at",+ db_incremental_field_last_value=datetime(2026, 3, 4, 2, 58, 14, tzinfo=UTC),+ )++ assert result.raised is None+ assert result.requests[0].param("sort_by") == expected_sort_by+ assert result.requests[0].param("sort_direction") == "ASC"+ assert result.requests[0].param("updated_at[gte]") == "2026-03-04T02:58:14.000Z"+++def _stats(sent: int) -> ScriptedResponse:+ return ScriptedResponse(json={"data": {"sent_emails_count": sent, "replied_rate": "40.0%"}})+++class TestCadenceStatsFanout:+ def test_walks_every_cadence_page_and_tags_stats_with_the_cadence_id(self) -> None:+ script = route(+ {+ "/cadences": [+ _response([{"id": 1}, {"id": 2}], next_page=2),+ _response([{"id": 3}], next_page=None),+ ],+ "/cadence_stats/1": [_stats(10)],+ # Cadence deleted between the listing and the stats fetch.+ "/cadence_stats/2": [ScriptedResponse(status=404, json={"error": "Not Found"})],+ "/cadence_stats/3": [_stats(30)],+ }+ )++ result = _driver().run("cadence_stats", script)++ assert result.raised is None+ assert [(row["cadence_id"], row["sent_emails_count"]) for row in result.rows] == [(1, 10), (3, 30)]+ assert all("_cadences_id" not in row for row in result.rows)+ assert result.paths == [+ "/v2/cadences",+ "/v2/cadence_stats/1",+ "/v2/cadence_stats/2",+ "/v2/cadences",+ "/v2/cadence_stats/3",+ ]+ parent_requests = [r for r in result.requests if r.path == "/v2/cadences"]+ assert [r.param("page") for r in parent_requests] == [None, "2"]+ assert all(r.param("sort_by") == "created_at" and r.param("per_page") == "100" for r in parent_requests)+ assert all(r.param("per_page") is None for r in result.requests if r.path.startswith("/v2/cadence_stats/"))++ def test_resume_skips_cadences_already_synced(self) -> None:+ cadences = _response([{"id": 1}, {"id": 2}], next_page=None)+ first = _driver().run(+ "cadence_stats",+ route(+ {+ "/cadences": [cadences],+ "/cadence_stats/1": [_stats(10)],+ "/cadence_stats/2": [ScriptedResponse(status=401, json={"error": "Unauthorized"})],+ }+ ),+ )+ assert isinstance(first.raised, requests.HTTPError)+ assert first.final_state is not None++ resumed = _driver().run(+ "cadence_stats",+ route({"/cadences": [cadences], "/cadence_stats/2": [_stats(20)]}),+ resume_state=first.final_state,+ )++ assert resumed.raised is None+ assert [(row["cadence_id"], row["sent_emails_count"]) for row in resumed.rows] == [(2, 20)]+ assert "/v2/cadence_stats/1" not in resumed.paths++class TestValidateCredentials:@pytest.mark.parametrize("status_code, expected",