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): add Apollo user and pipeline stage tables (#98299)

Tom Owers0c660550020c
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 7a2b9efe7962..417769c1b5f7 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
@@ -341,14 +341,14 @@ Note: Deliberately scoped: the connector takes a single user-supplied dataset_id
## Apollo — gaps
-Today (3): `accounts`, `contacts`, `opportunities`
+Today (7): `account_stages`, `accounts`, `contacts`, `contact_stages`, `opportunities`, `opportunity_stages`, `users`
Diffed against: <https://docs.apollo.io/reference/organization-search>
-- [ ] `/opportunity_stages (list deal stages)` — lookup resolving the stage IDs already carried on the opportunities we sync (high)
-- [ ] `/contact_stages` — lookup resolving contact_stage_id on synced contacts (high)
-- [ ] `/account_stages` — lookup resolving account_stage_id on synced accounts (high)
-- [ ] `/users/search` — lookup resolving owner/user IDs on accounts, contacts and deals (high)
+- [x] `/opportunity_stages (list deal stages)` — lookup resolving the stage IDs already carried on the opportunities we sync (high)
+- [x] `/contact_stages` — lookup resolving contact_stage_id on synced contacts (high)
+- [x] `/account_stages` — lookup resolving account_stage_id on synced accounts (high)
+- [x] `/users/search` — lookup resolving owner/user IDs on accounts, contacts and deals (high)
- [ ] `/emailer_messages/search (outreach emails)` — per-message email send/open/reply activity, the core sequence funnel (high)
- [ ] `/phone_calls/search` — call activity records tied to contacts and accounts (high)
- [ ] `/emailer_campaigns/search (sequences)` — lookup resolving sequence IDs on email activity and contact status (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/apollo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/apollo.py
index ada33620cb8b..422fdb7191a1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/apollo.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/apollo.py
@@ -124,13 +124,17 @@ def get_rows(
reraise=True,
)
def fetch_page(page_number: int) -> dict[str, Any]:
- body: dict[str, Any] = {"page": page_number, "per_page": PAGE_SIZE}
- if config.sort_by_field is not None:
- # Newest-first lets incremental runs stop at the watermark instead
- # of paging through history (and keeps full scans deterministic).
- body["sort_by_field"] = config.sort_by_field
- body["sort_ascending"] = False
- response = session.post(url, json=body, timeout=REQUEST_TIMEOUT_SECONDS)
+ page_params: dict[str, Any] = {"page": page_number, "per_page": PAGE_SIZE} if config.paginated else {}
+ if config.method == "GET":
+ response = session.get(url, params=page_params, timeout=REQUEST_TIMEOUT_SECONDS)
+ else:
+ body: dict[str, Any] = dict(page_params)
+ if config.sort_by_field is not None:
+ # Newest-first lets incremental runs stop at the watermark instead
+ # of paging through history (and keeps full scans deterministic).
+ body["sort_by_field"] = config.sort_by_field
+ body["sort_ascending"] = False
+ response = session.post(url, json=body, timeout=REQUEST_TIMEOUT_SECONDS)
if response.status_code == 429 or response.status_code >= 500:
retry_after = (
@@ -175,6 +179,9 @@ def get_rows(
if crossed_watermark or not items:
break
+ if not config.paginated:
+ break
+
if page >= MAX_PAGES:
# Apollo hard-caps search results at 500 pages / 50k records per query.
# Checked before the total_pages break so the cap is never silent when
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/canonical_descriptions.py
index 255f26f5cf8b..b9699105dd7b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/canonical_descriptions.py
@@ -70,4 +70,72 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"updated_at": "Time the opportunity was last updated.",
},
},
+ "users": {
+ "description": "A user of your Apollo team — the reps whose IDs appear as the owner of contacts, accounts, and deals.",
+ "docs_url": "https://docs.apollo.io/reference/get-a-list-of-users",
+ "columns": {
+ "id": "Unique identifier for the user.",
+ "team_id": "Identifier of the Apollo team the user belongs to.",
+ "first_name": "User's first name.",
+ "last_name": "User's last name.",
+ "name": "User's full name.",
+ "title": "User's job title.",
+ "email": "User's email address.",
+ "deleted": "Whether the user has been removed from the team.",
+ "permission_set_id": "Identifier of the permission set applied to the user.",
+ "subteam_ids": "Identifiers of the subteams the user belongs to.",
+ "credit_limit": "Number of email credits the user can spend.",
+ "export_credit_limit": "Number of export credits the user can spend.",
+ "linked_crm_name": "Name of the CRM the user's account is linked to.",
+ "created_at": "Time the user was created in Apollo.",
+ },
+ },
+ "contact_stages": {
+ "description": "A stage in your contact pipeline. Resolves the contact_stage_id carried on synced contacts.",
+ "docs_url": "https://docs.apollo.io/reference/list-contact-stages",
+ "columns": {
+ "id": "Unique identifier for the contact stage.",
+ "team_id": "Identifier of the Apollo team the stage belongs to.",
+ "name": "Name of the stage.",
+ "display_name": "Name of the stage as shown in Apollo.",
+ "display_order": "Position of the stage in the pipeline.",
+ "category": "Outcome the stage represents: in_progress, succeeded, or failed.",
+ "ignore_trigger_override": "Whether automation triggers skip contacts in this stage.",
+ "is_meeting_set": "Whether reaching this stage counts as a meeting being set.",
+ },
+ },
+ "account_stages": {
+ "description": "A stage in your account pipeline. Resolves the account_stage_id carried on synced accounts.",
+ "docs_url": "https://docs.apollo.io/reference/list-account-stages",
+ "columns": {
+ "id": "Unique identifier for the account stage.",
+ "team_id": "Identifier of the Apollo team the stage belongs to.",
+ "name": "Name of the stage.",
+ "display_name": "Name of the stage as shown in Apollo.",
+ "display_order": "Position of the stage in the pipeline.",
+ "category": "Outcome the stage represents: in_progress, succeeded, or failed.",
+ "default_exclude_for_leadgen": "Whether accounts in this stage are excluded from lead generation by default.",
+ "is_meeting_set": "Whether reaching this stage counts as a meeting being set.",
+ },
+ },
+ "opportunity_stages": {
+ "description": "A stage in your deal pipeline. Resolves the opportunity_stage_id carried on synced opportunities.",
+ "docs_url": "https://docs.apollo.io/reference/list-deal-stages",
+ "columns": {
+ "id": "Unique identifier for the deal stage.",
+ "team_id": "Identifier of the Apollo team the stage belongs to.",
+ "name": "Name of the stage.",
+ "display_order": "Position of the stage in the pipeline.",
+ "opportunity_pipeline_id": "Identifier of the pipeline the stage belongs to.",
+ "forecast_category_cd": "Forecast category the stage rolls up to.",
+ "probability": "Chance of winning a deal that sits in this stage, as a percentage.",
+ "is_won": "Whether deals in this stage count as won.",
+ "is_closed": "Whether deals in this stage count as closed.",
+ "is_meeting_set": "Whether reaching this stage counts as a meeting being set.",
+ "is_editable": "Whether the stage can be edited in Apollo.",
+ "type": "Type of the stage.",
+ "description": "Description of the stage.",
+ "salesforce_id": "Identifier of the matching stage in Salesforce.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/settings.py
index c5b8995295ed..2b267f0b5a7c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/settings.py
@@ -1,6 +1,8 @@
-from dataclasses import dataclass, field
+from dataclasses import field
from typing import Optional
+from posthog.dataclasses import frozen
+
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
_UPDATED_AT_INCREMENTAL_FIELDS: list[IncrementalField] = [
@@ -13,14 +15,18 @@ _UPDATED_AT_INCREMENTAL_FIELDS: list[IncrementalField] = [
]
-@dataclass
+@frozen
class ApolloEndpointConfig:
name: str
- # Search path under /api/v1 (search endpoints are POSTs with JSON bodies).
+ # Path under /api/v1 (search endpoints are POSTs with JSON bodies, lookups are GETs).
path: str
# Key the rows live under in the response body.
data_key: str
primary_key: str = "id"
+ method: str = "POST"
+ # The stage lookups return their whole set in one response, with no page params
+ # and no pagination object to walk.
+ paginated: bool = True
# Apollo has no server-side timestamp filter; incremental streams sort
# descending on this field and stop at the persisted high-water mark
# (the same CDC emulation Fivetran uses on CONTACT/ACCOUNT).
@@ -51,6 +57,33 @@ APOLLO_ENDPOINTS: dict[str, ApolloEndpointConfig] = {
path="/opportunities/search",
data_key="opportunities",
),
+ "users": ApolloEndpointConfig(
+ name="users",
+ path="/users/search",
+ data_key="users",
+ method="GET",
+ ),
+ "contact_stages": ApolloEndpointConfig(
+ name="contact_stages",
+ path="/contact_stages",
+ data_key="contact_stages",
+ method="GET",
+ paginated=False,
+ ),
+ "account_stages": ApolloEndpointConfig(
+ name="account_stages",
+ path="/account_stages",
+ data_key="account_stages",
+ method="GET",
+ paginated=False,
+ ),
+ "opportunity_stages": ApolloEndpointConfig(
+ name="opportunity_stages",
+ path="/opportunity_stages",
+ data_key="opportunity_stages",
+ method="GET",
+ paginated=False,
+ ),
}
ENDPOINTS = tuple(APOLLO_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/source.py
index 25a1d21cc488..2ea53a2a7410 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/source.py
@@ -63,7 +63,7 @@ class ApolloSource(ResumableSource[ApolloSourceConfig, ApolloResumeConfig]):
name=SchemaExternalDataSourceType.APOLLO,
category=DataWarehouseSourceCategory.CRM,
label="Apollo",
- caption="""Enter your Apollo API key to pull your saved contacts, accounts, and deals into the PostHog Data warehouse.
+ caption="""Enter your Apollo API key to pull your saved contacts, accounts, and deals into the PostHog Data warehouse, along with the users and pipeline stages they reference.
You can create an API key in Apollo under Settings > Integrations > API. API access requires a paid Apollo plan. Note that Apollo search results are capped at 50,000 records per stream.""",
iconPath="/static/services/apollo.png",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/tests/test_apollo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/tests/test_apollo.py
index ab7c0a853f24..0ab6b0d53598 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/tests/test_apollo.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/tests/test_apollo.py
@@ -42,6 +42,15 @@ def _response(data_key: str, items: list[dict[str, Any]], total_pages: int = 1)
return resp
+def _lookup_response(data_key: str, items: list[dict[str, Any]]) -> mock.MagicMock:
+ # The stage lookups answer with just the rows: no page params echoed, no pagination object.
+ resp = mock.MagicMock()
+ resp.json.return_value = {data_key: items}
+ resp.status_code = 200
+ resp.ok = True
+ return resp
+
+
def _rate_limited(retry_after: str | None = None) -> mock.MagicMock:
resp = mock.MagicMock()
resp.status_code = 429
@@ -148,6 +157,38 @@ class TestGetRows:
body = mock_session.return_value.post.call_args.kwargs["json"]
assert "sort_by_field" not in body
+ @pytest.mark.parametrize("endpoint", ["contact_stages", "account_stages", "opportunity_stages"])
+ @mock.patch(f"{_MODULE}.make_tracked_session")
+ def test_lookup_endpoints_read_one_unpaginated_page(self, mock_session, endpoint):
+ # Without the single-page stop these would loop forever: the response carries no
+ # total_pages to break on, so every pass re-yields the same rows.
+ mock_session.return_value.get.return_value = _lookup_response(endpoint, [{"id": "s1"}])
+
+ manager = _make_manager()
+ batches = list(get_rows("key", endpoint, mock.MagicMock(), manager))
+
+ assert [item["id"] for batch in batches for item in batch] == ["s1"]
+ assert mock_session.return_value.get.call_count == 1
+ assert mock_session.return_value.post.call_count == 0
+ assert mock_session.return_value.get.call_args.kwargs["params"] == {}
+ manager.save_state.assert_not_called()
+
+ @mock.patch(f"{_MODULE}.make_tracked_session")
+ def test_users_paginates_with_query_params(self, mock_session):
+ # Page params have to ride the query string on this GET; sent as a body they are
+ # ignored and every page comes back as page 1.
+ mock_session.return_value.get.side_effect = [
+ _response("users", [{"id": "u1"}], total_pages=2),
+ _response("users", [{"id": "u2"}], total_pages=2),
+ ]
+
+ batches = list(get_rows("key", "users", mock.MagicMock(), _make_manager()))
+
+ assert [item["id"] for batch in batches for item in batch] == ["u1", "u2"]
+ pages = [call.kwargs["params"]["page"] for call in mock_session.return_value.get.call_args_list]
+ assert pages == [1, 2]
+ assert mock_session.return_value.get.call_args.kwargs["params"]["per_page"] == PAGE_SIZE
+
@mock.patch(f"{_MODULE}.make_tracked_session")
def test_resumes_from_saved_page(self, mock_session):
mock_session.return_value.post.return_value = _response("contacts", [])