: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(data-warehouse): add amplemarket contacts and lead list entries tables (#116117)
Tom Owers572666fb6666
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 5e1788760bbb..9f79e47d453d 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@@ -518,9 +518,9 @@ Today (10): `accounts`, `call_dispositions`, `calls`, `excluded_domains`, `excluDiffed against: <https://api.amplemarket.com/api-docs/v1/swagger.yaml>-- [ ] `Contacts (GET /contacts)` — expands contact IDs on synced tasks into prospect attributes and account relationships (high)-- [ ] `Lead list entries (GET /lead-lists/{id})` — provides leads, list membership, and enrichment results absent from synced list summaries (high)-- [ ] `Job openings (GET /job-openings)` — adds hiring signals for account prioritization and outreach analysis (medium)+- [x] `Contacts (GET /contacts)` — expands contact IDs on synced tasks into prospect attributes and account relationships (high). Added as `contacts` (fan-out over `accounts` by `account_id`, because the endpoint has no unfiltered listing). Contacts not linked to an account are not reachable.+- [x] `Lead list entries (GET /lead-lists/{id})` — provides leads, list membership, and enrichment results absent from synced list summaries (high). Added as `lead_list_entries` (fan-out over `lead_lists`).+- ~~`Job openings (GET /job-openings)`~~ — skipped: it requires a company id, domain, or LinkedIn URL and searches Amplemarket's company data, so the rows are not records in the customer's accountNote: Parsed every GET operation in the vendor's published OpenAPI spec, including nested resources. Contacts require IDs, a name, or an account filter; lead entries require pagination for each list. Job openings require a company identifier or domain. Task status and type endpoints contain enum strings; enrichment jobs, recordings, and webhook-only engagement were excluded.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/amplemarket.py b/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/amplemarket.pyindex f9525228791d..c2e1fca67f5e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/amplemarket.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/amplemarket.py@@ -57,7 +57,7 @@ def _source_response(config: AmplemarketEndpointConfig, items: Iterable[Any]) ->return SourceResponse(name=config.name,items=lambda: items,- primary_keys=[config.primary_key],+ primary_keys=config.primary_keys,sort_mode=config.sort_mode,partition_count=1,partition_size=1,@@ -68,11 +68,11 @@ def _source_response(config: AmplemarketEndpointConfig, items: Iterable[Any]) ->def _fanout_source(api_key: str, endpoint: str, team_id: int, job_id: str) -> SourceResponse:- """Fan a per-user endpoint (tasks) out over the users list.+ """Fan a per-parent endpoint (tasks, contacts, lead list entries) out over its parent list.- The parent users list is small and re-fetched each sync, so the fan-out is not resumable;- each user's task pages follow their own `_links.next.href` chain, which carries the- `user_id` filter forward.+ The parent list is re-fetched each sync, so the fan-out is not resumable; each parent's+ child pages follow their own `_links.next.href` chain, which carries the parent filter+ forward."""config = AMPLEMARKET_ENDPOINTS[endpoint]assert config.fanout is not Nonediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/canonical_descriptions.pyindex af45a9bf5fdf..8d021b5b92c8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/canonical_descriptions.py@@ -51,6 +51,29 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"action": "What the disposition does: 'complete' marks the task and lead as completed, 'next_stage' takes no automatic action.",},},+ "contacts": {+ "description": "A Prospect Hub contact: a person your team is prospecting, linked to an account.",+ "docs_url": "https://docs.amplemarket.com/api-reference/contacts/get-contacts",+ "columns": {+ "id": "Unique identifier for the contact.",+ "account_id": "The ID of the account the contact was retrieved for.",+ "name": "The full name of the contact.",+ "first_name": "The first name of the contact.",+ "last_name": "The last name of the contact.",+ "email": "The email address of the contact.",+ "linkedin_url": "The contact's LinkedIn profile URL.",+ "title": "The contact's job title.",+ "location": "The contact's location.",+ "time_zone": "The contact's time zone.",+ "company_name": "The name of the contact's company.",+ "company_domain": "The domain of the contact's company.",+ "owner": "The email of the user who owns the contact.",+ "created_at": "When the contact was created, in ISO 8601 format.",+ "last_contacted_at": "When the contact was last contacted, in ISO 8601 format.",+ "crm": "The linked CRM record (Salesforce or HubSpot), if any.",+ "phone_numbers": "The phone numbers known for the contact.",+ },+ },"excluded_domains": {"description": "A domain on the account's exclusion list, so its leads are not contacted.","docs_url": "https://docs.amplemarket.com/guides/exclusion-lists",@@ -86,6 +109,26 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"type": "The type of input the lead list was created from, such as linkedin or email.",},},+ "lead_list_entries": {+ "description": "A lead on a lead list, with the enrichment and validation results Amplemarket added.",+ "docs_url": "https://docs.amplemarket.com/api-reference/lead-list/retrieve-lead-list",+ "columns": {+ "id": "Unique identifier for the lead list entry.",+ "lead_list_id": "The ID of the lead list the entry belongs to.",+ "email": "The email address of the lead.",+ "person_id": "The ID of the matched person in Amplemarket's database.",+ "linkedin_url": "The lead's LinkedIn profile URL.",+ "first_name": "The first name of the lead.",+ "last_name": "The last name of the lead.",+ "company_name": "The name of the lead's company.",+ "company_domain": "The domain of the lead's company.",+ "industry": "The industry of the lead's company.",+ "title": "The lead's job title.",+ "email_validation_result": "The result of validating the lead's email address.",+ "data": "Custom data fields uploaded with the lead.",+ "phone_numbers": "The phone numbers revealed for the lead.",+ },+ },"mailboxes": {"description": "A mailbox connected to Amplemarket and used to send sequence emails.","docs_url": "https://docs.amplemarket.com/api-reference/mailboxes/get-mailboxes",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/settings.pyindex a81f619af057..7f93631b2a7e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/settings.py@@ -6,6 +6,7 @@ from posthog.dataclasses import frozenfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (DependentEndpointConfig,)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import ResponseActionfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SortModefrom products.warehouse_sources.backend.types import IncrementalField@@ -18,7 +19,7 @@ class AmplemarketEndpointConfig:path: str# The key the row objects are nested under in the response body (e.g. {"sequences": [...]}).data_key: str- primary_key: str = "id"+ primary_keys: list[str] = field(default_factory=lambda: ["id"])# Stable creation-time field used for datetime partitioning. Never an updated_at-style# field, which would rewrite partitions on every sync.partition_key: Optional[str] = None@@ -41,6 +42,35 @@ _TASKS_FANOUT = DependentEndpointConfig(include_from_parent=[],)+# A parent deleted between the parent listing and the child fetch answers 404 (or 410 for a+# lead list), which should drop that parent rather than fail the sync.+_DELETED_PARENT_IGNORE: list[ResponseAction] = [+ {"status_code": 404, "action": "ignore"},+ {"status_code": 410, "action": "ignore"},+]++# /contacts has no unfiltered listing (it requires a name, account_id, or ids[] filter), so+# contacts fan out over the accounts list. Contacts not linked to an account are not reachable.+_CONTACTS_FANOUT = DependentEndpointConfig(+ parent_name="accounts",+ resolve_param="account_id",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "account_id"},+ child_response_actions=_DELETED_PARENT_IGNORE,+)++# The lead list listing carries only list summaries; the entries come from each list's detail+# endpoint, paged under `leads`.+_LEAD_LIST_ENTRIES_FANOUT = DependentEndpointConfig(+ parent_name="lead_lists",+ resolve_param="lead_list_id",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "lead_list_id"},+ child_response_actions=_DELETED_PARENT_IGNORE,+)+# Pagination is cursor-based via `_links.next.href` (HAL-style relative URLs). Requests omit# `page[size]` and follow the server defaults: the documented maximum varies per endpoint and@@ -52,8 +82,8 @@ _TASKS_FANOUT = DependentEndpointConfig(# until the filter is proven to work.## Deliberately not synced, because they are actions or per-query lookups rather than record-# collections: people/company search and enrichment, email validation, contacts (requires a-# name/account_id/ids filter), job openings (a prospecting search surface), and the+# collections: people/company search and enrichment, email validation, job openings (a search+# over Amplemarket's company data by domain, not records in the customer's account), and the# credit-consuming endpoints.AMPLEMARKET_ENDPOINTS: dict[str, AmplemarketEndpointConfig] = {"accounts": AmplemarketEndpointConfig(@@ -74,18 +104,28 @@ AMPLEMARKET_ENDPOINTS: dict[str, AmplemarketEndpointConfig] = {path="/calls/dispositions",data_key="dispositions",),+ # Keyed with the account id, because the API does not document that a contact belongs to+ # exactly one account.+ "contacts": AmplemarketEndpointConfig(+ name="contacts",+ path="/contacts?account_id={account_id}",+ data_key="contacts",+ primary_keys=["account_id", "id"],+ partition_key="created_at",+ fanout=_CONTACTS_FANOUT,+ ),"excluded_domains": AmplemarketEndpointConfig(name="excluded_domains",path="/excluded-domains",data_key="excluded_domains",- primary_key="domain",+ primary_keys=["domain"],partition_key="date_added",),"excluded_emails": AmplemarketEndpointConfig(name="excluded_emails",path="/excluded-emails",data_key="excluded_emails",- primary_key="email",+ primary_keys=["email"],partition_key="date_added",),"lead_lists": AmplemarketEndpointConfig(@@ -93,6 +133,15 @@ AMPLEMARKET_ENDPOINTS: dict[str, AmplemarketEndpointConfig] = {path="/lead-lists",data_key="lead_lists",),+ # Entries are keyed with their list id, because the same person can sit on several lists and+ # entry ids are not documented as unique across lists. Entries carry no creation time.+ "lead_list_entries": AmplemarketEndpointConfig(+ name="lead_list_entries",+ path="/lead-lists/{lead_list_id}",+ data_key="leads",+ primary_keys=["lead_list_id", "id"],+ fanout=_LEAD_LIST_ENTRIES_FANOUT,+ ),"mailboxes": AmplemarketEndpointConfig(name="mailboxes",path="/mailboxes",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/tests/test_amplemarket.py b/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/tests/test_amplemarket.pyindex c51e1ae677db..b3ced2d1cd70 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/tests/test_amplemarket.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/amplemarket/tests/test_amplemarket.py@@ -1,5 +1,7 @@from typing import Any+import pytest+from products.warehouse_sources.backend.temporal.data_imports.sources.amplemarket.amplemarket import (AmplemarketResumeConfig,validate_credentials,@@ -73,7 +75,7 @@ class TestPagination:assert result.queries == [{"page[after]": ("x",), "page[size]": ("20",)}]-class TestTasksFanout:+class TestFanout:def test_tasks_are_fetched_per_user(self) -> None:# /tasks requires a user_id filter, so the fan-out binds each parent user's id into the# child path and pages each user's tasks through their own next-link chain.@@ -97,3 +99,43 @@ class TestTasksFanout:{"user_id": ("u1",), "page[after]": ("t1",)},{"user_id": ("u2",)},]++ @pytest.mark.parametrize(+ "endpoint, parent_key, child_key, parent_id_column, gone_status, child_paths",+ [+ ("contacts", "accounts", "contacts", "account_id", 404, ["/contacts", "/contacts", "/contacts"]),+ (+ "lead_list_entries",+ "lead_lists",+ "leads",+ "lead_list_id",+ 410,+ ["/lead-lists/p1", "/lead-lists/p1", "/lead-lists/p2"],+ ),+ ],+ )+ def test_children_carry_parent_id_and_skip_deleted_parents(+ self,+ endpoint: str,+ parent_key: str,+ child_key: str,+ parent_id_column: str,+ gone_status: int,+ child_paths: list[str],+ ) -> None:+ # The parent id is part of the primary key, so every child row must carry it, and a parent+ # deleted after the listing must not fail the sync.+ result = _driver().run(+ endpoint,+ [+ _page(parent_key, [{"id": "p1"}, {"id": "p2"}, {"id": "p3"}]),+ _page(child_key, [{"id": "c1"}], f"{child_paths[0]}?page[after]=c1"),+ _page(child_key, [{"id": "c2"}]),+ _page(child_key, [{"id": "c1"}]),+ ScriptedResponse(status=gone_status, json={"_errors": [], "object": "error"}),+ ],+ )++ assert result.raised is None+ assert [(row[parent_id_column], row["id"]) for row in result.rows] == [("p1", "c1"), ("p1", "c2"), ("p2", "c1")]+ assert result.paths[1:4] == child_paths