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 email, call, task and sequence tables (#99185)

Tom Owerse952ba15130e
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 f9a6cacfb4ad..6947c161b765 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
@@ -343,7 +343,7 @@ Note: Deliberately scoped: the connector takes a single user-supplied dataset_id
## Apollo — gaps
-Today (7): `account_stages`, `accounts`, `contacts`, `contact_stages`, `opportunities`, `opportunity_stages`, `users`
+Today (11): `account_stages`, `accounts`, `contacts`, `contact_stages`, `emailer_campaigns`, `emailer_messages`, `opportunities`, `opportunity_stages`, `phone_calls`, `tasks`, `users`
Diffed against: <https://docs.apollo.io/reference/organization-search>
@@ -351,10 +351,10 @@ Diffed against: <https://docs.apollo.io/reference/organization-search>
- [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)
-- [ ] `/tasks/search` — rep task volume and completion analysis (medium)
+- [x] `/emailer_messages/search (outreach emails)` — per-message email send/open/reply activity, the core sequence funnel (high)
+- [x] `/phone_calls/search` — call activity records tied to contacts and accounts (high)
+- [x] `/emailer_campaigns/search (sequences)` — lookup resolving sequence IDs on email activity and contact status (medium)
+- [x] `/tasks/search` — rep task volume and completion analysis (medium)
- [ ] `/conversations/search` — conversation intelligence records joinable to calls (medium)
- [ ] `/labels (lists)` — lookup for list membership used to segment contacts and accounts (medium)
- [ ] `/notes` — note history attached to CRM records (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 422fdb7191a1..55254033cbd7 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
@@ -128,13 +128,14 @@ def get_rows(
if config.method == "GET":
response = session.get(url, params=page_params, timeout=REQUEST_TIMEOUT_SECONDS)
else:
- body: dict[str, Any] = dict(page_params)
+ query_params: dict[str, Any] = page_params if config.page_params_in_query else {}
+ body: dict[str, Any] = {} if config.page_params_in_query else 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)
+ response = session.post(url, params=query_params, json=body, timeout=REQUEST_TIMEOUT_SECONDS)
if response.status_code == 429 or response.status_code >= 500:
retry_after = (
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 b9699105dd7b..f84d0e6c11f2 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
@@ -90,6 +90,177 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"created_at": "Time the user was created in Apollo.",
},
},
+ "emailer_messages": {
+ "description": "An outreach email your team drafted, scheduled, or sent from an Apollo sequence, with its delivery and engagement status.",
+ "docs_url": "https://docs.apollo.io/reference/search-for-outreach-emails",
+ "columns": {
+ "id": "Unique identifier for the email.",
+ "user_id": "Identifier of the Apollo user the email was sent on behalf of.",
+ "contact_id": "Identifier of the contact the email was sent to.",
+ "account_id": "Identifier of the account the recipient belongs to.",
+ "emailer_campaign_id": "Identifier of the sequence the email belongs to.",
+ "emailer_step_id": "Identifier of the sequence step that produced the email.",
+ "emailer_touch_id": "Identifier of the sequence touch that produced the email.",
+ "email_account_id": "Identifier of the mailbox the email was sent from.",
+ "status": "Delivery and engagement state: drafted, scheduled, delivered, opened, clicked, bounced, spam_blocked, unsubscribed, demoed, or failed_other.",
+ "subject": "Subject line of the email.",
+ "body_text": "Plain text body of the email.",
+ "body_html": "HTML body of the email.",
+ "from_email": "Address the email was sent from.",
+ "from_name": "Name the email was sent under.",
+ "to_email": "Address the email was sent to.",
+ "to_name": "Name of the recipient.",
+ "cc_emails": "Addresses copied on the email.",
+ "bcc_emails": "Addresses blind copied on the email.",
+ "due_at": "Time the email is scheduled to be delivered.",
+ "completed_at": "Time the email was delivered.",
+ "failed_at": "Time the send failed, if it did.",
+ "failure_reason": "Why the send failed.",
+ "not_sent_reason": "Which safeguard stopped the email from being sent.",
+ "replied": "Whether the recipient replied.",
+ "reply_class": "How Apollo classified the reply, such as willing_to_meet or not_interested.",
+ "demoed": "Whether the email led to a booked demo.",
+ "bounce": "Whether the email bounced.",
+ "spam_blocked": "Whether the email was blocked as spam.",
+ "enable_tracking": "Whether open and click tracking was on for this email.",
+ "tracking_disabled_reason": "Why tracking was off, if it was.",
+ "type": "Type of the email, such as a sequence step or a one-off send.",
+ "campaign_name": "Name of the sequence the email belongs to.",
+ "campaign_position": "Position of the email's step within the sequence.",
+ "provider_message_id": "Identifier the sending mail provider gave the message.",
+ "provider_thread_id": "Identifier of the mail provider thread the message sits in.",
+ "crm_id": "Identifier of the matching record in your CRM.",
+ "created_at": "Time the email record was created in Apollo.",
+ },
+ },
+ "phone_calls": {
+ "description": "A call your team placed or received through the Apollo dialer, linked to the contact and account it involved.",
+ "docs_url": "https://docs.apollo.io/reference/search-for-calls",
+ "columns": {
+ "id": "Unique identifier for the call.",
+ "user_id": "Identifier of the Apollo user who handled the call.",
+ "contact_id": "Identifier of the contact on the call.",
+ "account_id": "Identifier of the account the contact belongs to.",
+ "opportunity_id": "Identifier of the deal the call is associated with.",
+ "outreach_task_id": "Identifier of the task the call was made from.",
+ "phone_call_purpose_id": "Identifier of the purpose logged against the call.",
+ "phone_call_outcome_id": "Identifier of the outcome logged against the call.",
+ "inbound": "Whether the call came in rather than going out.",
+ "from_number": "Number the call was placed from.",
+ "to_number": "Number the call was placed to.",
+ "start_time": "Time the call started.",
+ "end_time": "Time the call ended.",
+ "duration": "Length of the call in seconds.",
+ "status": "State of the call, such as completed or no answer.",
+ "note": "Note logged against the call.",
+ "note_text": "Plain text of the note logged against the call.",
+ "logged": "Whether the call has been logged.",
+ "recording_url": "URL of the call recording.",
+ "transcribed": "Whether the recording has been transcribed.",
+ "transcribing": "Whether transcription is still running.",
+ "transcription_progress": "How far transcription has got, as a percentage.",
+ "transcription_too_long": "Whether the recording was too long to transcribe.",
+ "voicemail_dropped": "Whether a prerecorded voicemail was left.",
+ "conversation_id": "Identifier of the conversation intelligence record for the call.",
+ "conference_id": "Identifier of the conference the call ran in.",
+ "voice_setting_id": "Identifier of the dialer settings used for the call.",
+ "twilio_call_sid": "Identifier Twilio gave the call.",
+ "twilio_recording_sid": "Identifier Twilio gave the recording.",
+ "salesforce_id": "Identifier of the matching call record in Salesforce.",
+ "hubspot_id": "Identifier of the matching call record in HubSpot.",
+ },
+ },
+ "tasks": {
+ "description": "A follow-up action assigned to a rep in Apollo — a call, an email, or a LinkedIn step — with its due date and completion state.",
+ "docs_url": "https://docs.apollo.io/reference/search-tasks",
+ "columns": {
+ "id": "Unique identifier for the task.",
+ "user_id": "Identifier of the Apollo user the task is assigned to.",
+ "creator_id": "Identifier of the Apollo user who created the task.",
+ "contact_id": "Identifier of the contact the task is about.",
+ "person_id": "Identifier of the person record the task is about.",
+ "account_id": "Identifier of the account the task is about.",
+ "organization_id": "Identifier of the organization the task is about.",
+ "opportunity_id": "Identifier of the deal the task is about.",
+ "emailer_campaign_id": "Identifier of the sequence that generated the task.",
+ "title": "Title of the task.",
+ "subject": "Subject line of the task.",
+ "note": "Note attached to the task.",
+ "type": "Kind of task, such as call, email, or LinkedIn step.",
+ "priority": "Priority the task was given.",
+ "status": "State of the task: scheduled, completed, or skipped.",
+ "answered": "Whether the outreach the task covers was answered.",
+ "due_at": "Time the task is due.",
+ "completed_at": "Time the task was completed.",
+ "skipped_at": "Time the task was skipped.",
+ "created_from": "Where the task was created from.",
+ "playbook_id": "Identifier of the play that generated the task.",
+ "playbook_step_ids": "Identifiers of the play steps that generated the task.",
+ "rule_config_id": "Identifier of the automation rule that generated the task.",
+ "persona_ids": "Identifiers of the personas the task's contact matches.",
+ "starred_by_user_ids": "Identifiers of the users who starred the task.",
+ "salesforce_id": "Identifier of the matching task in Salesforce.",
+ "salesforce_type": "Type of the matching Salesforce record.",
+ "hubspot_id": "Identifier of the matching task in HubSpot.",
+ "created_at": "Time the task was created in Apollo.",
+ },
+ },
+ "emailer_campaigns": {
+ "description": "A sequence — a planned series of outreach steps. Resolves the emailer_campaign_id carried on synced emails and tasks, and carries the sequence's own send and reply stats.",
+ "docs_url": "https://docs.apollo.io/reference/search-for-sequences",
+ "columns": {
+ "id": "Unique identifier for the sequence.",
+ "name": "Name of the sequence.",
+ "user_id": "Identifier of the Apollo user who owns the sequence.",
+ "folder_id": "Identifier of the folder the sequence sits in.",
+ "label_ids": "Identifiers of the labels applied to the sequence.",
+ "active": "Whether the sequence is currently running.",
+ "archived": "Whether the sequence has been archived.",
+ "num_steps": "Number of steps in the sequence.",
+ "creation_type": "How the sequence was created.",
+ "last_used_at": "Time a contact was last added to the sequence.",
+ "emailer_schedule_id": "Identifier of the sending schedule the sequence uses.",
+ "sequence_ruleset_id": "Identifier of the ruleset the sequence follows.",
+ "max_emails_per_day": "Cap on how many emails the sequence sends per day.",
+ "sequence_by_exact_daytime": "Whether steps fire at exact times rather than after a delay.",
+ "cc_emails": "Addresses copied on every send.",
+ "bcc_emails": "Addresses blind copied on every send.",
+ "excluded_account_stage_ids": "Account stages whose members the sequence skips.",
+ "excluded_contact_stage_ids": "Contact stages whose members the sequence skips.",
+ "contact_email_event_to_stage_mapping": "Which contact stage each email event moves a contact to.",
+ "days_to_wait_before_mark_as_response": "How long to wait before an email counts as answered.",
+ "mark_finished_if_click": "Whether a click finishes a contact's run through the sequence.",
+ "mark_finished_if_reply": "Whether a reply finishes a contact's run through the sequence.",
+ "mark_finished_if_interested": "Whether marking a contact interested finishes their run.",
+ "mark_paused_if_ooo": "Whether an out-of-office reply pauses the contact.",
+ "create_task_if_email_open": "Whether an email open creates a follow-up task.",
+ "email_open_trigger_task_threshold": "How many opens it takes to create that task.",
+ "same_account_reply_policy_cd": "How the sequence handles a reply from someone else at the same account.",
+ "same_account_reply_delay_days": "How long the sequence pauses after a same-account reply.",
+ "unique_scheduled": "Contacts with an email scheduled.",
+ "unique_delivered": "Contacts who were delivered an email.",
+ "unique_opened": "Contacts who opened an email.",
+ "unique_clicked": "Contacts who clicked a link.",
+ "unique_replied": "Contacts who replied.",
+ "unique_bounced": "Contacts whose email bounced.",
+ "unique_hard_bounced": "Contacts whose email hard bounced.",
+ "unique_spam_blocked": "Contacts whose email was blocked as spam.",
+ "unique_unsubscribed": "Contacts who unsubscribed.",
+ "unique_demoed": "Contacts who booked a demo.",
+ "open_rate": "Share of delivered emails that were opened.",
+ "click_rate": "Share of delivered emails that were clicked.",
+ "reply_rate": "Share of delivered emails that were replied to.",
+ "bounce_rate": "Share of emails that bounced.",
+ "hard_bounce_rate": "Share of emails that hard bounced.",
+ "spam_block_rate": "Share of emails that were blocked as spam.",
+ "opt_out_rate": "Share of delivered emails that led to an unsubscribe.",
+ "demo_rate": "Share of delivered emails that led to a booked demo.",
+ "is_performing_poorly": "Whether Apollo flags the sequence as underperforming.",
+ "underperforming_touches_count": "Number of steps Apollo flags as underperforming.",
+ "sharing_permission": "Who can see and edit the sequence.",
+ "created_at": "Time the sequence 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",
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 2b267f0b5a7c..5736e7d210af 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
@@ -27,6 +27,9 @@ class ApolloEndpointConfig:
# The stage lookups return their whole set in one response, with no page params
# and no pagination object to walk.
paginated: bool = True
+ # Apollo splits its POST search endpoints: the CRM object searches read page params
+ # from the JSON body, the sequence and task searches only from the query string.
+ page_params_in_query: bool = False
# 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).
@@ -57,6 +60,39 @@ APOLLO_ENDPOINTS: dict[str, ApolloEndpointConfig] = {
path="/opportunities/search",
data_key="opportunities",
),
+ # The four endpoints below are full refresh only. None of them expose a
+ # server-side filter on a creation or modification timestamp, and the fields that
+ # do move after the record is written (an email's open/click/reply status, a call's
+ # transcription, a task's completion) are exactly the ones a user reads, so a
+ # date-windowed sync would freeze them at their first-imported value.
+ "emailer_messages": ApolloEndpointConfig(
+ name="emailer_messages",
+ path="/emailer_messages/search",
+ data_key="emailer_messages",
+ method="GET",
+ partition_key="created_at",
+ ),
+ "phone_calls": ApolloEndpointConfig(
+ name="phone_calls",
+ path="/phone_calls/search",
+ data_key="phone_calls",
+ method="GET",
+ # Calls carry no created_at; start_time is when the call was placed and never moves.
+ partition_key="start_time",
+ ),
+ "tasks": ApolloEndpointConfig(
+ name="tasks",
+ path="/tasks/search",
+ data_key="tasks",
+ page_params_in_query=True,
+ partition_key="created_at",
+ ),
+ "emailer_campaigns": ApolloEndpointConfig(
+ name="emailer_campaigns",
+ path="/emailer_campaigns/search",
+ data_key="emailer_campaigns",
+ page_params_in_query=True,
+ ),
"users": ApolloEndpointConfig(
name="users",
path="/users/search",
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 2ea53a2a7410..760f5bf6147c 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, along with the users and pipeline stages they reference.
+ caption="""Enter your Apollo API key to pull your saved contacts, accounts, and deals into the PostHog Data warehouse, along with your sequences, outreach emails, calls, and tasks, and 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 0ab6b0d53598..768f1f9f3827 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,14 @@ def _response(data_key: str, items: list[dict[str, Any]], total_pages: int = 1)
return resp
+def _raw_response(body: dict[str, Any]) -> mock.MagicMock:
+ resp = mock.MagicMock()
+ resp.json.return_value = body
+ resp.status_code = 200
+ resp.ok = True
+ 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()
@@ -157,6 +165,41 @@ class TestGetRows:
body = mock_session.return_value.post.call_args.kwargs["json"]
assert "sort_by_field" not in body
+ @pytest.mark.parametrize("endpoint", ["tasks", "emailer_campaigns"])
+ @mock.patch(f"{_MODULE}.make_tracked_session")
+ def test_query_param_post_endpoints_paginate_in_the_query_string(self, mock_session, endpoint):
+ # These POSTs only read page params from the query string. Sent in the JSON body they
+ # are ignored, so every request comes back as page 1 and the walk re-yields it until
+ # the 500-page cap.
+ mock_session.return_value.post.side_effect = [
+ _response(endpoint, [{"id": "a1"}], total_pages=2),
+ _response(endpoint, [{"id": "a2"}], total_pages=2),
+ ]
+
+ batches = list(get_rows("key", endpoint, mock.MagicMock(), _make_manager()))
+
+ assert [item["id"] for batch in batches for item in batch] == ["a1", "a2"]
+ calls = mock_session.return_value.post.call_args_list
+ assert [call.kwargs["params"]["page"] for call in calls] == [1, 2]
+ assert calls[0].kwargs["params"]["per_page"] == PAGE_SIZE
+ assert calls[0].kwargs["json"] == {}
+
+ @mock.patch(f"{_MODULE}.make_tracked_session")
+ def test_emailer_messages_stops_without_a_pagination_object(self, mock_session):
+ # This endpoint answers with no pagination object at all, so there is no total_pages
+ # to break on — the walk has to end on the first empty page instead of running to the cap.
+ page = {"emailer_messages": [{"id": "m1", "created_at": "2024-01-01T00:00:00Z"}], "emailer_steps": []}
+ empty: dict[str, list[Any]] = {"emailer_messages": [], "emailer_steps": []}
+ mock_session.return_value.get.side_effect = [
+ _raw_response(page),
+ _raw_response(empty),
+ ]
+
+ batches = list(get_rows("key", "emailer_messages", mock.MagicMock(), _make_manager()))
+
+ assert [item["id"] for batch in batches for item in batch] == ["m1"]
+ assert mock_session.return_value.get.call_count == 2
+
@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):
@@ -281,8 +324,10 @@ class TestApolloSourceResponse:
@pytest.mark.parametrize("config", list(APOLLO_ENDPOINTS.values()))
def test_partition_keys_are_stable_creation_fields(self, config):
+ # A partition key that moves (updated_at, last_activity_date) rewrites partitions
+ # on every sync. Only fields fixed when the record is written belong here.
if config.partition_key:
- assert config.partition_key == "created_at"
+ assert config.partition_key in {"created_at", "start_time"}
class TestRetryAfter:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/tests/test_apollo_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/tests/test_apollo_source.py
index 894797193a62..8d2e89566cfa 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/tests/test_apollo_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apollo/tests/test_apollo_source.py
@@ -45,7 +45,8 @@ class TestApolloSource:
assert {schema.name for schema in schemas} == set(ENDPOINTS)
incremental = {schema.name for schema in schemas if schema.supports_incremental}
- # Contacts and accounts support sort-based CDC; opportunities don't.
+ # Contacts and accounts support sort-based CDC. Nothing else does: the remaining
+ # endpoints have no server-side timestamp filter to window a sync with.
assert incremental == {"contacts", "accounts"}
@pytest.mark.parametrize(