: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.planhat._config import PlanhatSourceConfig
from products.warehouse_sources.sources.planhat.planhat import PlanhatResumeConfig, planhat_source, validate_credentials
from products.warehouse_sources.sources.planhat.settings import ENDPOINTS, INCREMENTAL_FIELDS, PLANHAT_ENDPOINTS
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 PlanhatSource(ResumableSource[PlanhatSourceConfig, PlanhatResumeConfig]):
codebase_detection = detect(env=("^PLANHAT_",))
api_docs_url = "https://docs.planhat.com"
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
@property
def source_type(self) -> ExternalDataSourceType:
return ExternalDataSourceType.PLANHAT
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
name=ExternalDataSourceType.PLANHAT,
category=DataWarehouseSourceCategory.CUSTOMER_SUPPORT,
label="Planhat",
releaseStatus=ReleaseStatus.GA,
caption="""Enter your Planhat API access token to pull your customer success data into the PostHog Data warehouse.
You can create an API access token from a Private App under **Settings → Service Accounts** in [Planhat](https://app.planhat.com). The token is shown once, so copy it immediately. It grants read access to your companies, end users, users, licenses, assets, NPS responses, conversations, tickets, invoices, sales, churn, opportunities, line items, products, tasks, custom fields, and metrics.
""",
iconPath="/static/services/planhat.png",
docsUrl="https://posthog.com/docs/cdp/sources/planhat",
fields=cast(
list[FieldType],
[
SourceFieldInputConfig(
name="api_key",
label="API access token",
type=SourceFieldInputConfigType.PASSWORD,
required=True,
placeholder="",
secret=True,
),
],
),
)
def get_canonical_descriptions(self) -> CanonicalDescriptions:
from products.warehouse_sources.sources.planhat.canonical_descriptions import (
CANONICAL_DESCRIPTIONS, # noqa: PLC0415
)
return CANONICAL_DESCRIPTIONS
def get_non_retryable_errors(self) -> dict[str, str | None]:
return {
"401 Client Error: Unauthorized for url: https://api.planhat.com": "Your Planhat API access token is invalid or has been revoked. Generate a new token from a Private App under Settings → Service Accounts, then reconnect.",
"403 Client Error: Forbidden for url: https://api.planhat.com": "Your Planhat API access token does not have access to this data. Check the Private App's scopes, then reconnect.",
}
def get_schemas(
self,
config: PlanhatSourceConfig,
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
# Every endpoint is full refresh only — Planhat's list endpoints expose no reliably
# ordered server-side timestamp filter, so there is no incremental cursor to advance.
# INCREMENTAL_FIELDS is empty, so build_endpoint_schemas yields full-refresh-only schemas.
return build_endpoint_schemas(ENDPOINTS, INCREMENTAL_FIELDS, names)
def validate_credentials(
self,
config: PlanhatSourceConfig,
team_id: int,
schema_name: Optional[str] = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
# The API token is account-wide, so a single probe validates access to every schema.
return validate_credentials(config.api_key)
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[PlanhatResumeConfig]:
return ResumableSourceManager[PlanhatResumeConfig](inputs, PlanhatResumeConfig)
def source_for_pipeline(
self,
config: PlanhatSourceConfig,
resumable_source_manager: ResumableSourceManager[PlanhatResumeConfig],
inputs: SourceInputs,
) -> SourceResponse:
if inputs.schema_name not in PLANHAT_ENDPOINTS:
raise ValueError(f"Unknown Planhat schema '{inputs.schema_name}'")
return planhat_source(
api_token=config.api_key,
endpoint=inputs.schema_name,
team_id=inputs.team_id,
job_id=inputs.job_id,
resumable_source_manager=resumable_source_manager,
db_incremental_field_last_value=None, # every Planhat endpoint is full refresh
)