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(data-warehouse): add 1 missing table to the Leadfeeder source (#116881)

Tom Owersb1b4c2627096
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.md
index ee945a8a3194..1139299d9adb 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
@@ -7136,7 +7136,7 @@ Today (3): `accounts`, `leads`, `visits`
Diffed against: <https://docs.leadfeeder.com/api/>
-- [ ] `GET /accounts/{account_id}/custom_feeds (and GET /accounts/{account_id}/custom_feeds/{id}/leads)` — custom feeds are the saved lead segments; syncing them resolves feed ids and lets leads be attributed to a segment (medium)
+- [x] `GET /accounts/{account_id}/custom_feeds (and GET /accounts/{account_id}/custom_feeds/{id}/leads)` — custom feeds are the saved lead segments; syncing them resolves feed ids and lets leads be attributed to a segment (medium)
Note: The docs page PostHog targets is explicitly labelled the legacy Leadfeeder API and points new integrations at the newer Dealfront platform API (https://docs.dealfront.com/api/public), which the page says exposes richer company/contact data, financials, signals, tags, lists and CRM relationships. That newer API is hosted on Apidog with no fetchable spec, so its resource list is unverified and not enumerated here - but the connector is built on a deprecated API and is worth a migration review. Legacy API resources are only accounts, custom feeds, leads, visits and feed exports; PostHog covers three of the four queryable ones.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/canonical_descriptions.py
index 81bf43ef94c5..643c895dc1d9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/canonical_descriptions.py
@@ -68,4 +68,21 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"device_type": "Device category used for the visit.",
},
},
+ "custom_feeds": {
+ "description": "Saved lead segments (custom feeds) of each account. A feed filters leads by criteria such as country, page or assignee.",
+ "docs_url": "https://docs.leadfeeder.com/api/",
+ "columns": {
+ "id": "Identifier of the custom feed. Built-in feeds use fixed ids such as 'all_leads' on the legacy API.",
+ "type": "JSON:API resource type: 'custom_feeds' on the legacy API, 'custom_feed' on the unified API.",
+ "account_id": "Identifier of the Leadfeeder account this custom feed belongs to.",
+ "name": "Name of the custom feed.",
+ "criteria": "Filter criteria of the feed (legacy API only).",
+ "advanced_filters": "Filter groups and conditions of the feed (unified API only).",
+ "notifications": "Notification subscriptions configured for the feed (unified API only).",
+ "deletable": "Whether the feed can be deleted (unified API only).",
+ "viewable": "Whether the feed can be viewed (unified API only).",
+ "created_at": "Timestamp the feed was created (unified API only).",
+ "updated_at": "Timestamp the feed was last updated (unified API only).",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/leadfeeder.py b/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/leadfeeder.py
index 1330d34eddf9..6ada8c76862e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/leadfeeder.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/leadfeeder.py
@@ -38,6 +38,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
JSONResponsePaginator,
PageNumberPaginator,
+ SinglePagePaginator,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.resource import Resource
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (
@@ -296,6 +297,16 @@ def _unified_child_endpoint(config: LeadfeederEndpointConfig, account_id: str, s
return child_endpoint
+def _unified_account_scoped_endpoint(config: LeadfeederEndpointConfig, account_id: str) -> Endpoint:
+ """One account's slice of a fan-out endpoint that has no date window and no pagination."""
+ return {
+ "path": config.unified_path,
+ "params": {"account_id": account_id},
+ "data_selector": "data",
+ "paginator": SinglePagePaginator(),
+ }
+
+
def _split_window(start: str, end: str, parts: int) -> list[_DateWindow]:
"""Cut a date window into at most `parts` day-aligned sub-windows, oldest first.
@@ -401,8 +412,29 @@ def _unified_leadfeeder_source(
# The unified fan-out endpoints take `account_id` as a query param, which the shared REST
# framework can't resolve from a parent resource (it only binds resolved params into the path),
- # so iterate accounts explicitly and sync each account's window with the id baked in. The date
- # range is computed from the incremental watermark (if any) or the configured start date;
+ # so iterate accounts explicitly and sync each account with the id baked in.
+ if not config.supports_date_filter:
+
+ def _per_account() -> Iterator[list[dict[str, Any]]]:
+ for account_id in _unified_account_ids(client, team_id, job_id):
+ yield from _unified_single_resource(
+ client,
+ endpoint,
+ _unified_account_scoped_endpoint(config, account_id),
+ team_id,
+ job_id,
+ partial(_flatten_item, account_id=account_id),
+ )
+
+ return SourceResponse(
+ name=endpoint,
+ items=_per_account,
+ primary_keys=config.primary_keys,
+ partition_count=1,
+ partition_size=1,
+ )
+
+ # The date range is computed from the incremental watermark (if any) or the configured start date;
# re-reading the floored day is self-healing since merge dedupes on the primary key.
start = (
_to_date_str(db_incremental_field_last_value)
@@ -544,9 +576,12 @@ def leadfeeder_source(
)
else:
child_params: dict[str, Any] = {
- **_base_params(),
+ **(_base_params() if config.paginated else {}),
"account_id": {"type": "resolve", "resource": _ACCOUNTS_RESOURCE, "field": "id"},
}
+ child_endpoint: Endpoint = {"path": config.path, "params": child_params, "data_selector": "data"}
+ if config.supports_date_filter:
+ child_endpoint["incremental"] = _date_range_incremental(config, start_date_config)
resources: list[str | EndpointResource] = [
{
"name": _ACCOUNTS_RESOURCE,
@@ -554,12 +589,7 @@ def leadfeeder_source(
},
{
"name": endpoint,
- "endpoint": {
- "path": config.path,
- "params": child_params,
- "data_selector": "data",
- "incremental": _date_range_incremental(config, start_date_config),
- },
+ "endpoint": child_endpoint,
"include_from_parent": ["id"],
"data_map": _flatten_fan_out,
},
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/settings.py
index c7b4db44a3a0..e7930565dc09 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/settings.py
@@ -45,7 +45,7 @@ def _datetime_field(name: str) -> IncrementalField:
}
-@dataclass
+@dataclass # nosemgrep: prefer-frozen-dataclasses -- pre-existing; new field shifts the backlog finding into diff
class LeadfeederEndpointConfig:
name: str
# Legacy-API path relative to the base. Fan-out endpoints carry an `{account_id}` placeholder
@@ -68,6 +68,8 @@ class LeadfeederEndpointConfig:
# When True the endpoint honours the server-side `start_date`/`end_date` date-range filter, which
# makes it genuinely incremental. Endpoints without a server filter are full refresh only.
supports_date_filter: bool = False
+ # False when the endpoint returns its whole result set in one response with no page params.
+ paginated: bool = True
should_sync_default: bool = True
@@ -114,6 +116,17 @@ LEADFEEDER_ENDPOINTS: dict[str, LeadfeederEndpointConfig] = {
_datetime_field("started_at"),
],
),
+ # Saved lead segments (custom feeds) of each account. Neither generation paginates this list or
+ # filters it by date, so full refresh only. Built-in feed ids such as `all_leads` repeat in every
+ # account on the legacy API, so the account id is part of the key.
+ "custom_feeds": LeadfeederEndpointConfig(
+ name="custom_feeds",
+ path="/accounts/{account_id}/custom-feeds",
+ unified_path="/v1/web-visits/custom-feeds",
+ primary_keys=["account_id", "id"],
+ fan_out_over_accounts=True,
+ paginated=False,
+ ),
}
ENDPOINTS = tuple(LEADFEEDER_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/source.py
index 6766f917643b..0a2faa3c78de 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/source.py
@@ -63,7 +63,7 @@ class LeadfeederSource(ResumableSource[LeadfeederSourceConfig, LeadfeederResumeC
label="Leadfeeder",
releaseStatus=ReleaseStatus.ALPHA,
keywords=["dealfront"],
- caption="""Enter your Dealfront (Leadfeeder) API key to pull your website visitor and lead data into the PostHog data warehouse. This syncs the **Accounts**, **Leads**, and **Visits** tables.
+ caption="""Enter your Dealfront (Leadfeeder) API key to pull your website visitor and lead data into the PostHog data warehouse. This syncs the **Accounts**, **Custom feeds**, **Leads**, and **Visits** tables.
New connections use the unified Dealfront API. Create an API key in your Dealfront platform settings, under Personal, API keys.
@@ -120,8 +120,8 @@ Optionally set a **Start date** to bound the initial sync. Leave it blank to pul
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
- # Discovery is version-independent: both generations expose the same accounts / leads / visits
- # tables with the same incremental fields, so the static catalog is identical whatever the pin.
+ # Discovery is version-independent: both generations expose the same accounts / leads / visits /
+ # custom_feeds tables with the same incremental fields, so the static catalog is identical whatever the pin.
def _build_schema(endpoint: str) -> SourceSchema:
endpoint_config = LEADFEEDER_ENDPOINTS[endpoint]
# Only endpoints with a server-side start_date/end_date filter are genuinely incremental.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/tests/test_leadfeeder.py b/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/tests/test_leadfeeder.py
index 27010439116d..1dbdb3a62a2f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/tests/test_leadfeeder.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/leadfeeder/tests/test_leadfeeder.py
@@ -167,6 +167,58 @@ class TestFanOut:
assert "/accounts/1/leads" in result.paths
+def _unpaginated_unified_response(items: list[dict[str, Any]]) -> ScriptedResponse:
+ # The unified custom-feeds list carries no `meta.page_count`, so only a single-page paginator stops it.
+ return ScriptedResponse(json={"data": items, "meta": {"request_id": "req-1"}})
+
+
+class TestCustomFeeds:
+ @parameterized.expand(
+ [
+ (
+ "legacy",
+ LEADFEEDER_API_LEGACY,
+ _response,
+ ["/accounts", "/accounts/1/custom-feeds", "/accounts/2/custom-feeds"],
+ ),
+ (
+ "unified",
+ LEADFEEDER_API_2026_08_07,
+ _unpaginated_unified_response,
+ ["/v1/accounts", "/v1/web-visits/custom-feeds", "/v1/web-visits/custom-feeds"],
+ ),
+ ]
+ )
+ def test_reads_one_unwindowed_page_per_account(
+ self, _name: str, api_version: str, feeds_response: Any, expected_paths: list[str]
+ ) -> None:
+ result = _driver("2024-01-01").run(
+ "custom_feeds",
+ [
+ feeds_response([_item("1", "accounts"), _item("2", "accounts")]),
+ feeds_response([_item("all_leads", "custom_feeds", name="All leads")]),
+ feeds_response([_item("all_leads", "custom_feeds", name="All leads"), _item("77", "custom_feeds")]),
+ ],
+ api_version=api_version,
+ )
+
+ assert result.raised is None
+ assert result.rows == [
+ {"id": "all_leads", "type": "custom_feeds", "name": "All leads", "account_id": "1"},
+ {"id": "all_leads", "type": "custom_feeds", "name": "All leads", "account_id": "2"},
+ {"id": "77", "type": "custom_feeds", "account_id": "2"},
+ ]
+ assert result.paths == expected_paths
+ feed_requests = result.requests[1:]
+ if api_version == LEADFEEDER_API_2026_08_07:
+ assert [request.param("account_id") for request in feed_requests] == ["1", "2"]
+ for request in feed_requests:
+ for param in ("start_date", "end_date", "page[number]", "page[num]", "page[size]"):
+ assert request.param(param) is None
+ assert result.response is not None
+ assert result.response.primary_keys == ["account_id", "id"]
+
+
class TestSourceResponse:
@parameterized.expand(
[