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 Lemlist API version v2 (#86343)

Tom Owers07cad66d1204
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.md
index 86e5493f73a1..4df5a117b09f 100644
--- a/.agents/skills/warehouse-source-new-version/SKILL.md
+++ b/.agents/skills/warehouse-source-new-version/SKILL.md
@@ -78,6 +78,7 @@ Add it when any of these hold:
- Vendor version labels are opaque: `"2026-02-25.clover"`, `"v21.0"`, `"2022-06-28"`. Copy them exactly; never normalize, sort, or parse.
- A source's per-endpoint URL versions (a hardcoded `/v2/...`, `/v3/...` in the endpoint config) are independent of the framework's source-level version label. A source may already call the vendor's newest per-resource routes while still carrying the `UNVERSIONED_API_VERSION` default — so a version-add can be correct as declaration-only even when the vendor's own version numbers look far apart. Diff what the source actually requests, not the vendor's headline version.
+- When a vendor selects versions with a per-endpoint query param and _requires_ it on some endpoints regardless of version, those endpoints must send the selector under every pin, the legacy one included — they are version-independent even though the selector value matches the new label, and gating them on the resolved pin breaks the old pin. Gate on the pin only endpoints where the selector is optional and merely enriches the response (extra fields under the new version); those are the genuine divergence.
- A change the vendor calls "breaking" (e.g. resource ids migrating int→string) still needs no per-version branch when the source only passes the affected values through opaquely — a primary key whose _column name_ is stable (type auto-inferred), cursors forwarded verbatim. The version still has to exist (the gate passed on a real divergence), but branch the request path only where the change hits a surface you hardcode: column hints, a parsed cursor, a typed primary key.
- A version bump often changes **webhook payloads** too — if the source is a `WebhookSource`, check whether webhook-created clients (created at source-setup time, not sync time) also need the version and whether existing webhook subscriptions must be updated.
- Credential-validation paths (`validate_credentials`, permission probes) run at creation time with no row pin; they may use the default/legacy version. Changing them is optional per version bump — verify the vendor accepts the validation calls under the new version before switching them.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/canonical_descriptions.py
index 4ecc36ad9467..025ae749129e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/canonical_descriptions.py
@@ -43,6 +43,7 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"userIds": "User IDs that belong to the team.",
"createdBy": "User ID that created the team.",
"createdAt": "When the team was created.",
+ "users": "Team members, each with userId, name, email and role. Returned on lemlist API v2.",
},
},
"team_senders": {
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/lemlist.py b/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/lemlist.py
index 018baaaca2d7..164830d6536b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/lemlist.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/lemlist.py
@@ -22,6 +22,15 @@ LEMLIST_BASE_URL = "https://api.lemlist.com/api"
# lemlist caps list pages at 100 rows and rate-limits to 20 requests / 2s per API key.
PAGE_SIZE = 100
+# lemlist selects an API version per endpoint via a `version` query param (not a header or path).
+# The framework labels are opaque: v1 preserves the wire this source has always sent, v2 opts every
+# version-aware endpoint into lemlist's current shape. campaigns/activities only serve v2 and so send
+# it under either pin; /team's v2 additionally returns a `users` array, sent only under a v2 pin.
+LEMLIST_API_VERSION_V1 = "v1"
+LEMLIST_API_VERSION_V2 = "v2"
+LEMLIST_SUPPORTED_VERSIONS = (LEMLIST_API_VERSION_V1, LEMLIST_API_VERSION_V2)
+LEMLIST_DEFAULT_VERSION = LEMLIST_API_VERSION_V2
+
@dataclasses.dataclass
class LemlistResumeConfig:
@@ -66,14 +75,15 @@ def lemlist_source(
team_id: int,
job_id: str,
resumable_source_manager: ResumableSourceManager[LemlistResumeConfig],
+ api_version: str,
should_use_incremental_field: bool = False,
db_incremental_field_last_value: Optional[Any] = None,
) -> SourceResponse:
config = LEMLIST_ENDPOINTS[endpoint]
params: dict[str, Any] = {}
- if config.requires_version_v2:
- params["version"] = "v2"
+ if config.requires_version_v2 or (config.version_v2_enriches and api_version == LEMLIST_API_VERSION_V2):
+ params["version"] = LEMLIST_API_VERSION_V2
if config.request_sort_by:
params["sortBy"] = config.request_sort_by
if config.request_sort_order:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/settings.py
index 8b096c7e9b71..72f99f927e7a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/settings.py
@@ -1,11 +1,13 @@
-from dataclasses import dataclass, field
+from dataclasses import field
from typing import Optional
+from posthog.dataclasses import frozen
+
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SortMode
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
-@dataclass
+@frozen
class LemlistEndpointConfig:
name: str
path: str
@@ -14,6 +16,9 @@ class LemlistEndpointConfig:
paginate: bool = True
# lemlist's newer response shapes require `version=v2` on a couple of list endpoints.
requires_version_v2: bool = False
+ # `version=v2` is optional here but enriches the response (e.g. /team gains a `users` array), so
+ # it's sent only when the source is pinned to v2 — v1 pins keep the leaner shape byte-for-byte.
+ version_v2_enriches: bool = False
# `/team` returns a single object rather than an array; wrap it into a one-row table.
single_object: bool = False
primary_keys: list[str] = field(default_factory=lambda: ["_id"])
@@ -67,6 +72,7 @@ LEMLIST_ENDPOINTS: dict[str, LemlistEndpointConfig] = {
paginate=False,
single_object=True,
partition_key="createdAt",
+ version_v2_enriches=True,
),
"team_senders": LemlistEndpointConfig(
name="team_senders",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/source.py
index bf7d727feb39..4019b936bbef 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/source.py
@@ -24,6 +24,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_
LemlistSourceConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.lemlist.lemlist import (
+ LEMLIST_DEFAULT_VERSION,
+ LEMLIST_SUPPORTED_VERSIONS,
LemlistResumeConfig,
lemlist_source,
validate_credentials as validate_lemlist_credentials,
@@ -38,6 +40,8 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
@SourceRegistry.register
class LemlistSource(ResumableSource[LemlistSourceConfig, LemlistResumeConfig]):
api_docs_url = "https://developer.lemlist.com/api-reference"
+ supported_versions = LEMLIST_SUPPORTED_VERSIONS
+ default_version = LEMLIST_DEFAULT_VERSION
@property
def source_type(self) -> ExternalDataSourceType:
@@ -125,6 +129,7 @@ You can generate an API key in your lemlist **Settings > Integrations** page."""
team_id=inputs.team_id,
job_id=inputs.job_id,
resumable_source_manager=resumable_source_manager,
+ api_version=self.resolve_api_version(inputs.api_version),
should_use_incremental_field=inputs.should_use_incremental_field,
db_incremental_field_last_value=inputs.db_incremental_field_last_value
if inputs.should_use_incremental_field
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/tests/test_lemlist.py b/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/tests/test_lemlist.py
index 806623b68ed2..cbe80493517e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/tests/test_lemlist.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/tests/test_lemlist.py
@@ -11,6 +11,9 @@ from parameterized import parameterized
from requests import Response
from products.warehouse_sources.backend.temporal.data_imports.sources.lemlist.lemlist import (
+ LEMLIST_API_VERSION_V1,
+ LEMLIST_API_VERSION_V2,
+ LEMLIST_DEFAULT_VERSION,
PAGE_SIZE,
LemlistResumeConfig,
_clamp_future_value_to_now,
@@ -62,13 +65,20 @@ def _wire(session: mock.MagicMock, responses: list[Response]) -> list[dict[str,
return param_snapshots
-def _source(endpoint: str, manager: mock.MagicMock | None = None, **kwargs: Any):
+def _source(
+ endpoint: str,
+ manager: mock.MagicMock | None = None,
+ *,
+ api_version: str = LEMLIST_DEFAULT_VERSION,
+ **kwargs: Any,
+):
return lemlist_source(
api_key="key",
endpoint=endpoint,
team_id=1,
job_id="j",
resumable_source_manager=manager if manager is not None else _make_manager(),
+ api_version=api_version,
**kwargs,
)
@@ -184,6 +194,30 @@ class TestRequestParams:
assert "minDate" not in params[0]
+class TestVersionDispatch:
+ @parameterized.expand(
+ [
+ # campaigns/activities only serve v2, so the param rides either pin (v1 pins byte-for-byte).
+ ("campaigns_pin_v1", "campaigns", LEMLIST_API_VERSION_V1, [{"_id": "c"}], "v2"),
+ ("campaigns_pin_v2", "campaigns", LEMLIST_API_VERSION_V2, [{"_id": "c"}], "v2"),
+ # /team's v2 adds a users array, so version is sent only under a v2 pin.
+ ("team_pin_v1", "team", LEMLIST_API_VERSION_V1, {"_id": "t"}, None),
+ ("team_pin_v2", "team", LEMLIST_API_VERSION_V2, {"_id": "t"}, "v2"),
+ # Endpoints with no version variant never send the param, whatever the pin.
+ ("team_senders_pin_v2", "team_senders", LEMLIST_API_VERSION_V2, [{"userId": "u"}], None),
+ ("unsubscribes_pin_v2", "unsubscribes", LEMLIST_API_VERSION_V2, [{"_id": "u"}], None),
+ ]
+ )
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_version_param_per_endpoint_and_pin(
+ self, _name: str, endpoint: str, api_version: str, payload: Any, expected: str | None, MockSession
+ ) -> None:
+ session = MockSession.return_value
+ params = _wire(session, [_response(payload)])
+ _rows(_source(endpoint, api_version=api_version))
+ assert params[0].get("version") == expected
+
+
class TestValidateCredentials:
@parameterized.expand([("ok", 200, True), ("unauthorized", 401, False), ("not_found", 404, False)])
@mock.patch(LEMLIST_SESSION_PATCH)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/tests/test_lemlist_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/tests/test_lemlist_source.py
index cdf4e84f8b80..ada5c519b2d9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/tests/test_lemlist_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/lemlist/tests/test_lemlist_source.py
@@ -35,6 +35,14 @@ class TestLemlistSourceConfig:
assert api_key_field.required is True
+class TestVersioning:
+ def test_supports_v1_and_v2_defaulting_to_v2(self) -> None:
+ source = LemlistSource()
+ assert source.supported_versions == ("v1", "v2")
+ # New sources are stamped with default_version; v2 is lemlist's current version.
+ assert source.default_version == "v2"
+
+
class TestGetSchemas:
def test_returns_all_endpoints(self) -> None:
schemas = LemlistSource().get_schemas(_config(), team_id=1)
@@ -111,6 +119,7 @@ class TestSourceForPipeline:
schema_name="activities",
should_use_incremental_field=True,
db_incremental_field_last_value="2026-05-11T00:00:00Z",
+ api_version="v1",
)
result: Any = LemlistSource().source_for_pipeline(_config("secret"), manager, inputs)
@@ -119,6 +128,8 @@ class TestSourceForPipeline:
assert captured["endpoint"] == "activities"
assert captured["should_use_incremental_field"] is True
assert captured["db_incremental_field_last_value"] == "2026-05-11T00:00:00Z"
+ # A present pin is honored verbatim; a NULL pin would resolve to default_version.
+ assert captured["api_version"] == "v1"
def test_drops_last_value_when_not_incremental(self, monkeypatch: Any) -> None:
captured: dict[str, Any] = {}