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(warehouse_sources): support Pipedrive API version v2 (#71670)

Tom Owers0095b7450f72
diff --git a/products/warehouse_sources/backend/migrations/0087_repin_pipedrive_api_version_v2.py b/products/warehouse_sources/backend/migrations/0087_repin_pipedrive_api_version_v2.py
new file mode 100644
index 000000000000..7713bad822a2
--- /dev/null
+++ b/products/warehouse_sources/backend/migrations/0087_repin_pipedrive_api_version_v2.py
@@ -0,0 +1,36 @@
+from django.db import migrations
+
+# Pipedrive deprecated the v1 API endpoints that have v2 replacements (sunset 2025-12-31). The
+# source now defaults new instances to v2; this repins existing source-level pins from v1 to v2
+# so they stop using the deprecated `/api/v1/activities` endpoint.
+PIPEDRIVE_SOURCE_TYPE = "Pipedrive"
+OLD_VERSION = "v1"
+NEW_VERSION = "v2"
+
+
+def repin_pipedrive_v1_to_v2(apps, schema_editor):
+ ExternalDataSource = apps.get_model("warehouse_sources", "ExternalDataSource")
+
+ # Only the source-level pin is touched. Schema-level `ExternalDataSchema.api_version`
+ # overrides are user-managed (a customer intentionally pinned that schema) and are left
+ # alone — the schema-level deprecation warning prompts the user to migrate those.
+ #
+ # NULL pins already resolve to the source's `default_version` (now v2), so they need no
+ # update. Matching only `api_version="v1"` keeps this idempotent: a second run matches
+ # nothing, and any row a customer re-pins to v1 after this ran would (intentionally) be
+ # repinned again only if the migration is re-applied — acceptable, since v1 is deprecated.
+ ExternalDataSource.objects.filter(source_type=PIPEDRIVE_SOURCE_TYPE, api_version=OLD_VERSION).update(
+ api_version=NEW_VERSION
+ )
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("warehouse_sources", "0086_sleekplan_source"),
+ ]
+
+ operations = [
+ # Reverse is a no-op: nulling or downgrading pins would move customers back onto the
+ # deprecated version and clobber any deliberate post-migration pins.
+ migrations.RunPython(repin_pipedrive_v1_to_v2, migrations.RunPython.noop, elidable=False),
+ ]
diff --git a/products/warehouse_sources/backend/migrations/max_migration.txt b/products/warehouse_sources/backend/migrations/max_migration.txt
index f837be5d3e9d..8a36bebcfff1 100644
--- a/products/warehouse_sources/backend/migrations/max_migration.txt
+++ b/products/warehouse_sources/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0086_sleekplan_source
+0087_repin_pipedrive_api_version_v2
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/api_inventory.md b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/api_inventory.md
index bf3179382f9a..b452f392992c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/api_inventory.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/api_inventory.md
@@ -28,7 +28,7 @@ Reference: <https://developers.pipedrive.com/docs/api/v1>
| products | `/api/v2/products` | cursor | id | add_time |
| pipelines | `/api/v2/pipelines` | cursor | id | add_time |
| stages | `/api/v2/stages` | cursor | id | add_time |
-| activities | `/api/v1/activities` | offset | id | add_time |
+| activities | `/api/v2/activities` | cursor | id | add_time |
| notes | `/api/v1/notes` | offset | id | add_time |
| leads | `/api/v1/leads` | offset | id | add_time |
| users | `/api/v1/users` | offset | id | — |
@@ -36,6 +36,14 @@ Reference: <https://developers.pipedrive.com/docs/api/v1>
| person_fields | `/api/v1/personFields` | offset | id | — |
| organization_fields | `/api/v1/organizationFields` | offset | id | — |
+## Source versions
+
+The source declares two versions (`ExternalDataSource.api_version`), `v1` and `v2`, differing
+only in the `activities` endpoint — Pipedrive deprecated `/api/v1/activities` (sunset
+2025-12-31) in favour of the cursor-paginated `/api/v2/activities`. New sources default to `v2`.
+The other endpoints don't change: `notes`, `leads`, `users`, and the `*_fields` endpoints have
+no v2 replacement and stay on v1 under both labels; the rest were already on v2.
+
## Incremental sync
Shipped as **full refresh for every endpoint**. Pipedrive's v2 collection endpoints
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/canonical_descriptions.py
index a7b4beaef836..df8223b9cfaa 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/canonical_descriptions.py
@@ -1,7 +1,7 @@
"""Canonical, documentation-sourced descriptions for Pipedrive endpoints and columns.
Sourced from the official Pipedrive API reference (https://developers.pipedrive.com/docs/api/v1).
-Keyed by the endpoint names in `settings.py` `PIPEDRIVE_ENDPOINTS`, which match the
+Keyed by the endpoint names in `settings.py` (`ENDPOINTS`), which match the
`ExternalDataSchema.name` of a synced Pipedrive table. Columns absent here fall back to LLM
enrichment.
"""
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/pipedrive.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/pipedrive.py
index 30e190f8e04d..c260a884c6f2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/pipedrive.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/pipedrive.py
@@ -12,8 +12,8 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline
from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.pipedrive.settings import (
- PIPEDRIVE_ENDPOINTS,
PipedriveEndpointConfig,
+ endpoints_for_version,
)
# Pipedrive caps list pages at 500 items (default 100).
@@ -120,10 +120,11 @@ def get_rows(
company_domain: str,
api_token: str,
endpoint: str,
+ api_version: str,
logger: FilteringBoundLogger,
resumable_source_manager: ResumableSourceManager[PipedriveResumeConfig],
) -> Iterator[list[dict[str, Any]]]:
- config = PIPEDRIVE_ENDPOINTS[endpoint]
+ config = endpoints_for_version(api_version)[endpoint]
# `redact_values` masks the token (sent via the custom `x-api-token` header, which the
# name-based denylist can't catch) in logged URLs and captured HTTP samples.
session = make_tracked_session(headers=_get_headers(api_token), redact_values=(api_token,))
@@ -179,10 +180,11 @@ def pipedrive_source(
company_domain: str,
api_token: str,
endpoint: str,
+ api_version: str,
logger: FilteringBoundLogger,
resumable_source_manager: ResumableSourceManager[PipedriveResumeConfig],
) -> SourceResponse:
- config = PIPEDRIVE_ENDPOINTS[endpoint]
+ config = endpoints_for_version(api_version)[endpoint]
return SourceResponse(
name=endpoint,
@@ -190,6 +192,7 @@ def pipedrive_source(
company_domain=company_domain,
api_token=api_token,
endpoint=endpoint,
+ api_version=api_version,
logger=logger,
resumable_source_manager=resumable_source_manager,
),
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/settings.py
index da8ea48e91ab..3f30978ec9ff 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/settings.py
@@ -17,14 +17,17 @@ class PipedriveEndpointConfig:
partition_key: Optional[str] = "add_time"
-PIPEDRIVE_ENDPOINTS: dict[str, PipedriveEndpointConfig] = {
+# Endpoints whose path and pagination are identical across every supported source version.
+# Their v1 collection endpoints have no v2 replacement (notes, leads, users, *_fields) or were
+# already on v2 (deals, persons, organizations, products, pipelines, stages), so they don't
+# change between our `v1` and `v2` labels.
+_SHARED_ENDPOINTS: dict[str, PipedriveEndpointConfig] = {
"deals": PipedriveEndpointConfig(name="deals", path="/api/v2/deals", pagination="cursor"),
"persons": PipedriveEndpointConfig(name="persons", path="/api/v2/persons", pagination="cursor"),
"organizations": PipedriveEndpointConfig(name="organizations", path="/api/v2/organizations", pagination="cursor"),
"products": PipedriveEndpointConfig(name="products", path="/api/v2/products", pagination="cursor"),
"pipelines": PipedriveEndpointConfig(name="pipelines", path="/api/v2/pipelines", pagination="cursor"),
"stages": PipedriveEndpointConfig(name="stages", path="/api/v2/stages", pagination="cursor"),
- "activities": PipedriveEndpointConfig(name="activities", path="/api/v1/activities", pagination="offset"),
"notes": PipedriveEndpointConfig(name="notes", path="/api/v1/notes", pagination="offset"),
"leads": PipedriveEndpointConfig(name="leads", path="/api/v1/leads", pagination="offset"),
"users": PipedriveEndpointConfig(name="users", path="/api/v1/users", pagination="offset", partition_key=None),
@@ -39,4 +42,22 @@ PIPEDRIVE_ENDPOINTS: dict[str, PipedriveEndpointConfig] = {
),
}
-ENDPOINTS = tuple(PIPEDRIVE_ENDPOINTS.keys())
+# `activities` is the only endpoint that differs by version: Pipedrive deprecated the v1
+# offset endpoint in favour of the v2 cursor endpoint (same `id`/`add_time` fields).
+_ACTIVITIES_BY_VERSION: dict[str, PipedriveEndpointConfig] = {
+ "v1": PipedriveEndpointConfig(name="activities", path="/api/v1/activities", pagination="offset"),
+ "v2": PipedriveEndpointConfig(name="activities", path="/api/v2/activities", pagination="cursor"),
+}
+
+
+def endpoints_for_version(api_version: str) -> dict[str, PipedriveEndpointConfig]:
+ """Endpoint configs for a resolved source version. Only a deliberate `v1` pin uses the
+ deprecated offset `activities` endpoint; every other label (the default `v2`, or a pin we
+ don't recognise) uses the current v2 cursor endpoint rather than the sunset one."""
+ activities = _ACTIVITIES_BY_VERSION["v1"] if api_version == "v1" else _ACTIVITIES_BY_VERSION["v2"]
+ return {**_SHARED_ENDPOINTS, "activities": activities}
+
+
+# Endpoint names are version-independent (`activities` exists under both), so schema discovery
+# can enumerate them without a resolved version.
+ENDPOINTS = (*_SHARED_ENDPOINTS.keys(), "activities")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/source.py
index 87ce9ad5d416..dc30cecd74ae 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/source.py
@@ -1,3 +1,4 @@
+import datetime
from typing import Optional, cast
from posthog.schema import (
@@ -13,7 +14,11 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline
SourceInputs,
SourceResponse,
)
-from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, ResumableSource
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import (
+ FieldType,
+ ResumableSource,
+ VersionDeprecation,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.canonical_descriptions import (
CanonicalDescriptions,
)
@@ -33,8 +38,11 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
@SourceRegistry.register
class PipedriveSource(ResumableSource[PipedriveSourceConfig, PipedriveResumeConfig]):
- supported_versions = ("v1",)
- default_version = "v1"
+ supported_versions = ("v1", "v2")
+ default_version = "v2"
+ # v1 only differs from v2 in the `activities` endpoint; the vendor deprecated the v1
+ # endpoints that have v2 replacements and stops guaranteeing them after the sunset date.
+ deprecated_versions = (VersionDeprecation(version="v1", sunset_at=datetime.date(2025, 12, 31)),)
api_docs_url = "https://developers.pipedrive.com/docs/api/v1"
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
@@ -147,6 +155,7 @@ You can find your personal API token in Pipedrive under **Settings > Personal pr
company_domain=normalize_company_domain(config.company_domain),
api_token=config.api_token,
endpoint=inputs.schema_name,
+ api_version=self.resolve_api_version(inputs.api_version),
logger=inputs.logger,
resumable_source_manager=resumable_source_manager,
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/tests/test_pipedrive.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/tests/test_pipedrive.py
index 80066b438902..5ea4225351de 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/tests/test_pipedrive.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/tests/test_pipedrive.py
@@ -14,7 +14,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.pipedrive.
pipedrive_source,
validate_credentials,
)
-from products.warehouse_sources.backend.temporal.data_imports.sources.pipedrive.settings import PIPEDRIVE_ENDPOINTS
+from products.warehouse_sources.backend.temporal.data_imports.sources.pipedrive.settings import endpoints_for_version
class TestNormalizeCompanyDomain:
@@ -60,19 +60,43 @@ class TestNormalizeCompanyDomain:
assert base_url("https://MyCompany.pipedrive.com") == "https://mycompany.pipedrive.com"
+class TestEndpointsForVersion:
+ @pytest.mark.parametrize(
+ "api_version, expected_path, expected_pagination",
+ [
+ ("v1", "/api/v1/activities", "offset"),
+ ("v2", "/api/v2/activities", "cursor"),
+ # A pin we don't recognise resolves to the current (v2) endpoint, not the sunset one.
+ ("v99", "/api/v2/activities", "cursor"),
+ ],
+ )
+ def test_activities_endpoint_switches_by_version(
+ self, api_version: str, expected_path: str, expected_pagination: str
+ ) -> None:
+ activities = endpoints_for_version(api_version)["activities"]
+ assert activities.path == expected_path
+ assert activities.pagination == expected_pagination
+
+ def test_shared_endpoints_are_version_independent(self) -> None:
+ # Only `activities` diverges; everything else must be identical across versions.
+ v1 = {name: cfg for name, cfg in endpoints_for_version("v1").items() if name != "activities"}
+ v2 = {name: cfg for name, cfg in endpoints_for_version("v2").items() if name != "activities"}
+ assert v1 == v2
+
+
class TestInitialUrl:
def test_cursor_endpoint_only_sets_limit(self) -> None:
- url = _initial_url("acme", PIPEDRIVE_ENDPOINTS["deals"])
+ url = _initial_url("acme", endpoints_for_version("v2")["deals"])
assert url == f"https://acme.pipedrive.com/api/v2/deals?limit={PAGE_SIZE}"
def test_offset_endpoint_sets_start_and_limit(self) -> None:
- url = _initial_url("acme", PIPEDRIVE_ENDPOINTS["activities"])
+ url = _initial_url("acme", endpoints_for_version("v1")["activities"])
assert url == f"https://acme.pipedrive.com/api/v1/activities?limit={PAGE_SIZE}&start=0"
class TestNextUrl:
def test_cursor_returns_next_page_url(self) -> None:
- config = PIPEDRIVE_ENDPOINTS["deals"]
+ config = endpoints_for_version("v2")["deals"]
response = {"data": [{"id": 1}], "additional_data": {"next_cursor": "abc123"}}
assert _next_url("acme", config, response) == (
f"https://acme.pipedrive.com/api/v2/deals?limit={PAGE_SIZE}&cursor=abc123"
@@ -87,11 +111,11 @@ class TestNextUrl:
],
)
def test_cursor_terminates_when_no_next_cursor(self, additional_data: dict[str, Any]) -> None:
- config = PIPEDRIVE_ENDPOINTS["deals"]
+ config = endpoints_for_version("v2")["deals"]
assert _next_url("acme", config, {"data": [], "additional_data": additional_data}) is None
def test_offset_returns_next_page_url(self) -> None:
- config = PIPEDRIVE_ENDPOINTS["activities"]
+ config = endpoints_for_version("v1")["activities"]
response = {
"data": [{"id": 1}],
"additional_data": {"pagination": {"more_items_in_collection": True, "next_start": 500}},
@@ -109,7 +133,7 @@ class TestNextUrl:
],
)
def test_offset_terminates(self, additional_data: dict[str, Any]) -> None:
- config = PIPEDRIVE_ENDPOINTS["activities"]
+ config = endpoints_for_version("v1")["activities"]
assert _next_url("acme", config, {"data": [], "additional_data": additional_data}) is None
@@ -157,7 +181,7 @@ class TestGetRows:
mock_session.return_value.get.side_effect = [page1, page2]
manager = self._manager()
- batches = list(get_rows("acme", "token", "deals", mock.MagicMock(), manager))
+ batches = list(get_rows("acme", "token", "deals", "v2", mock.MagicMock(), manager))
assert batches == [[{"id": 1}], [{"id": 2}]]
# The session masks the token in logged URLs and captured samples.
@@ -178,7 +202,7 @@ class TestGetRows:
resume_url = f"https://acme.pipedrive.com/api/v2/deals?limit={PAGE_SIZE}&cursor=resume-me"
manager = self._manager(PipedriveResumeConfig(next_url=resume_url))
- batches = list(get_rows("acme", "token", "deals", mock.MagicMock(), manager))
+ batches = list(get_rows("acme", "token", "deals", "v2", mock.MagicMock(), manager))
assert batches == [[{"id": 9}]]
assert mock_session.return_value.get.call_args.args[0] == resume_url
@@ -192,7 +216,7 @@ class TestGetRows:
mock_session.return_value.get.return_value = page
manager = self._manager()
- batches = list(get_rows("acme", "token", "users", mock.MagicMock(), manager))
+ batches = list(get_rows("acme", "token", "users", "v2", mock.MagicMock(), manager))
assert batches == [[{"id": 1}, {"id": 2}]]
manager.save_state.assert_not_called()
@@ -206,7 +230,7 @@ class TestGetRows:
mock_session.return_value.get.return_value = page
with pytest.raises(Exception, match="401 Client Error"):
- list(get_rows("acme", "token", "deals", mock.MagicMock(), self._manager()))
+ list(get_rows("acme", "token", "deals", "v2", mock.MagicMock(), self._manager()))
class TestPipedriveSource:
@@ -222,7 +246,7 @@ class TestPipedriveSource:
def test_source_response_partitioning(
self, endpoint: str, expected_partition_keys: list[str] | None, expected_mode: str | None
) -> None:
- response = pipedrive_source("acme", "token", endpoint, mock.MagicMock(), mock.MagicMock())
+ response = pipedrive_source("acme", "token", endpoint, "v2", mock.MagicMock(), mock.MagicMock())
assert response.name == endpoint
assert response.primary_keys == ["id"]
assert response.partition_keys == expected_partition_keys
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/tests/test_pipedrive_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/tests/test_pipedrive_source.py
index 1780be8917fb..aaa12f5c2412 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/tests/test_pipedrive_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pipedrive/tests/test_pipedrive_source.py
@@ -1,3 +1,5 @@
+import datetime
+
import pytest
from unittest import mock
@@ -20,6 +22,17 @@ class TestPipedriveSource:
def test_source_type(self) -> None:
assert self.source.source_type == ExternalDataSourceType.PIPEDRIVE
+ def test_v1_is_deprecated_with_vendor_sunset_and_default_is_v2(self) -> None:
+ # New sources start on v2; v1 stays supported but carries the vendor's sunset date so the
+ # generic in-product deprecation warning fires.
+ assert self.source.default_version == "v2"
+ assert set(self.source.supported_versions) == {"v1", "v2"}
+
+ deprecation = self.source.get_version_deprecation("v1")
+ assert deprecation is not None
+ assert deprecation.sunset_at == datetime.date(2025, 12, 31)
+ assert self.source.get_version_deprecation("v2") is None
+
def test_get_source_config(self) -> None:
config = self.source.get_source_config
@@ -129,10 +142,22 @@ class TestPipedriveSource:
assert isinstance(manager, ResumableSourceManager)
assert manager._data_class is PipedriveResumeConfig
+ @pytest.mark.parametrize(
+ "pinned_version, expected_version",
+ [
+ ("v2", "v2"),
+ ("v1", "v1"),
+ # A missing pin resolves to the source's default (v2).
+ (None, "v2"),
+ ],
+ )
@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.pipedrive.source.pipedrive_source")
- def test_source_for_pipeline_plumbs_arguments(self, mock_pipedrive_source: mock.MagicMock) -> None:
+ def test_source_for_pipeline_plumbs_arguments(
+ self, mock_pipedrive_source: mock.MagicMock, pinned_version: str | None, expected_version: str
+ ) -> None:
inputs = mock.MagicMock()
inputs.schema_name = "deals"
+ inputs.api_version = pinned_version
manager = mock.MagicMock()
self.source.source_for_pipeline(self.config, manager, inputs)
@@ -142,6 +167,7 @@ class TestPipedriveSource:
assert kwargs["company_domain"] == "acme"
assert kwargs["api_token"] == "token"
assert kwargs["endpoint"] == "deals"
+ assert kwargs["api_version"] == expected_version
assert kwargs["resumable_source_manager"] is manager
@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.pipedrive.source.pipedrive_source")