: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
from typing import Optional, cast
from products.warehouse_sources.sources.apollo._config import ApolloSourceConfig
from products.warehouse_sources.sources.apollo.apollo import (
ApolloResumeConfig,
apollo_source,
validate_credentials as validate_apollo_credentials,
)
from products.warehouse_sources.sources.apollo.settings import ENDPOINTS, INCREMENTAL_FIELDS
from products.warehouse_sources.sources.sdk import (
CanonicalDescriptions,
DataWarehouseSourceCategory,
ExternalDataSourceType,
FieldType,
ReleaseStatus,
ResumableSource,
ResumableSourceManager,
SourceConfig,
SourceFieldInputConfig,
SourceFieldInputConfigType,
SourceInputs,
SourceRegistry,
SourceResponse,
SourceSchema,
build_endpoint_schemas,
detect,
)
@SourceRegistry.register
class ApolloSource(ResumableSource[ApolloSourceConfig, ApolloResumeConfig]):
codebase_detection = detect(script_hosts=("assets.apollo.io",))
supported_versions = ("v1",)
default_version = "v1"
api_docs_url = "https://docs.apollo.io/reference"
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
@property
def source_type(self) -> ExternalDataSourceType:
return ExternalDataSourceType.APOLLO
def get_non_retryable_errors(self) -> dict[str, str | None]:
return {
"401 Client Error: Unauthorized for url: https://api.apollo.io": "Apollo authentication failed. Please check your API key.",
"403 Client Error: Forbidden for url: https://api.apollo.io": "Apollo denied access. API access requires a paid Apollo plan, and some endpoints need a master API key.",
}
def get_retryable_errors(self) -> set[str]:
# fetch_page exhausts its Retry-After backoff on a 429, then re-raises so Temporal
# retries the activity from saved page state. The import self-recovers, so log the
# rate limit at warning instead of raising an error tracking issue.
return {"Apollo API error (retryable)"}
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
name=ExternalDataSourceType.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 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",
docsUrl="https://posthog.com/docs/cdp/sources/apollo",
releaseStatus=ReleaseStatus.GA,
fields=cast(
list[FieldType],
[
SourceFieldInputConfig(
name="api_key",
label="API key",
type=SourceFieldInputConfigType.PASSWORD,
required=True,
placeholder="",
secret=True,
),
],
),
)
def get_canonical_descriptions(self) -> CanonicalDescriptions:
from products.warehouse_sources.sources.apollo.canonical_descriptions import CANONICAL_DESCRIPTIONS
return CANONICAL_DESCRIPTIONS
def get_schemas(
self,
config: ApolloSourceConfig,
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
return build_endpoint_schemas(ENDPOINTS, INCREMENTAL_FIELDS, names)
def validate_credentials(
self,
config: ApolloSourceConfig,
team_id: int,
schema_name: Optional[str] = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
if validate_apollo_credentials(config.api_key):
return True, None
return False, (
"Apollo rejected this API key. Create a key in Apollo under Settings > Integrations > API. "
"API access requires a paid Apollo plan."
)
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[ApolloResumeConfig]:
return ResumableSourceManager[ApolloResumeConfig](inputs, ApolloResumeConfig)
def source_for_pipeline(
self,
config: ApolloSourceConfig,
resumable_source_manager: ResumableSourceManager[ApolloResumeConfig],
inputs: SourceInputs,
) -> SourceResponse:
return apollo_source(
api_key=config.api_key,
endpoint=inputs.schema_name,
logger=inputs.logger,
resumable_source_manager=resumable_source_manager,
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
else None,
)