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 pandadoc API version v2 (#86338)

Tom Owers7aca7839ed83
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/pandadoc.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/pandadoc.py
index af7c95633a1a..440d873d5c85 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/pandadoc.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/pandadoc.py
@@ -21,6 +21,14 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.pandadoc.s
PandaDocEndpointConfig,
)
+# PandaDoc versions its API per endpoint via a URL segment (/public/v1, /public/v2), not
+# globally: /public/v2 is a small, growing set of new endpoints (API logs, document audit
+# trail), NOT a mirror of v1. Every resource this source reads (documents, templates, forms,
+# contacts, members, folders) is served only under /public/v1 and has no v2 route, so both
+# pins resolve to the same wire here and the base URL stays on v1 regardless of the pin.
+API_VERSION_V1 = "v1"
+API_VERSION_V2 = "v2"
+
PANDADOC_BASE_URL = "https://api.pandadoc.com/public/v1"
# PandaDoc list pages cap at 100 items.
PAGE_SIZE = 100
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/source.py
index 3b942f1efa8c..f042d6badb07 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/source.py
@@ -24,6 +24,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_
PandaDocSourceConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.pandadoc.pandadoc import (
+ API_VERSION_V1,
+ API_VERSION_V2,
PandaDocResumeConfig,
pandadoc_source,
validate_credentials as validate_pandadoc_credentials,
@@ -37,9 +39,11 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
@SourceRegistry.register
class PandaDocSource(ResumableSource[PandaDocSourceConfig, PandaDocResumeConfig]):
- supported_versions = ("v1",)
- default_version = "v1"
- api_docs_url = "https://developers.pandadoc.com"
+ # v2 is declared so new sources are stamped with the vendor's current API generation, but the
+ # endpoints this source reads are v1-only (see pandadoc.py), so both pins resolve to the same wire.
+ supported_versions = (API_VERSION_V1, API_VERSION_V2)
+ default_version = API_VERSION_V2
+ api_docs_url = "https://developers.pandadoc.com/reference/version"
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/tests/test_pandadoc.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/tests/test_pandadoc.py
index 78aba534e4ae..92bf5fb1c2e7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/tests/test_pandadoc.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/tests/test_pandadoc.py
@@ -10,6 +10,7 @@ from requests import Response
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.auth import APIKeyAuth
from products.warehouse_sources.backend.temporal.data_imports.sources.pandadoc.pandadoc import (
PAGE_SIZE,
+ PANDADOC_BASE_URL,
PandaDocResumeConfig,
_build_query_params,
_format_date_filter,
@@ -219,6 +220,27 @@ class TestPagination:
assert auth[0].api_key == "API-Key secret-key"
assert auth[0].name == "Authorization"
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_requests_target_public_v1(self, MockSession):
+ # PandaDoc serves this source's endpoints only under /public/v1; v2 has no route for them,
+ # so the wire must stay on v1 even though v2 is the source's default pin. Guards against a
+ # future edit repointing the base URL to /public/v2, which would 404 every sync.
+ session = MockSession.return_value
+ session.headers = {}
+ urls: list[str] = []
+
+ def _prepare(request):
+ urls.append(request.url)
+ return mock.MagicMock()
+
+ session.prepare_request.side_effect = _prepare
+ session.send.side_effect = [_response([{"id": "a"}])]
+
+ _rows(pandadoc_source("key", "documents", team_id=1, job_id="j", resumable_source_manager=_make_manager()))
+
+ assert PANDADOC_BASE_URL == "https://api.pandadoc.com/public/v1"
+ assert urls[0].startswith("https://api.pandadoc.com/public/v1/documents")
+
@mock.patch(CLIENT_SESSION_PATCH)
def test_resumes_from_saved_page(self, MockSession):
session = MockSession.return_value
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/tests/test_pandadoc_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/tests/test_pandadoc_source.py
index a773ecce11f2..1699546d5306 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/tests/test_pandadoc_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pandadoc/tests/test_pandadoc_source.py
@@ -25,6 +25,13 @@ class TestPandaDocSource:
def test_source_type(self):
assert self.source.source_type == ExternalDataSourceType.PANDADOC
+ def test_declares_v1_and_v2_with_v2_default(self):
+ # v2 must be the default (new sources stamp it) while v1 stays supported. The registry
+ # invariant test only checks default == supported[-1], so it would still pass if v2 were
+ # dropped; this test locks in the actual bump.
+ assert self.source.supported_versions == ("v1", "v2")
+ assert self.source.default_version == "v2"
+
def test_get_source_config(self):
config = self.source.get_source_config