: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.klaus._config import KlausSourceConfig
from products.warehouse_sources.sources.klaus.klaus import (
KlausResumeConfig,
klaus_source,
validate_credentials as validate_klaus_credentials,
)
from products.warehouse_sources.sources.klaus.settings import ENDPOINTS, INCREMENTAL_FIELDS
from products.warehouse_sources.sources.sdk import (
NOT_DETECTABLE,
CanonicalDescriptions,
DataWarehouseSourceCategory,
ExternalDataSourceType,
FieldType,
ReleaseStatus,
ResumableSource,
ResumableSourceManager,
SourceConfig,
SourceFieldInputConfig,
SourceFieldInputConfigType,
SourceInputs,
SourceRegistry,
SourceResponse,
SourceSchema,
)
@SourceRegistry.register
class KlausSource(ResumableSource[KlausSourceConfig, KlausResumeConfig]):
codebase_detection = NOT_DETECTABLE
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
@property
def source_type(self) -> ExternalDataSourceType:
return ExternalDataSourceType.KLAUS
@property
def connection_host_fields(self) -> list[str]:
# `subdomain` determines the host the stored API token is sent to;
# retargeting it must re-require the token.
return ["subdomain"]
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
name=ExternalDataSourceType.KLAUS,
category=DataWarehouseSourceCategory.CUSTOMER_SUPPORT,
label="Klaus",
releaseStatus=ReleaseStatus.BETA,
keywords=["zendesk qa", "zendesk", "quality assurance", "conversation reviews"],
caption="""Sync your Zendesk QA (formerly Klaus) reviews, AutoQA results, CSAT, disputes, and quality data into the PostHog Data warehouse.
You need an API token, which an admin or account manager can generate in Zendesk QA under **Settings > Auto QA and integrations > API**. The subdomain is the first part of your Zendesk URL (for `yourcompany.zendesk.com`, enter `yourcompany`).
Note that the Zendesk QA public API is heavily rate limited, so large initial syncs can take a while — syncs pace themselves and resume automatically.""",
iconPath="/static/services/klaus.png",
docsUrl="https://posthog.com/docs/cdp/sources/klaus",
fields=cast(
list[FieldType],
[
SourceFieldInputConfig(
name="subdomain",
label="Zendesk subdomain",
type=SourceFieldInputConfigType.TEXT,
required=True,
placeholder="yourcompany",
secret=False,
),
SourceFieldInputConfig(
name="api_token",
label="API token",
type=SourceFieldInputConfigType.PASSWORD,
required=True,
placeholder="",
secret=True,
),
],
),
)
def get_non_retryable_errors(self) -> dict[str, str | None]:
return {
"401 Client Error": "Invalid Zendesk QA credentials. Please check your subdomain and API token and reconnect.",
"403 Client Error": "Your Zendesk QA API token does not have access. Please generate a new token and reconnect.",
"Unauthorized for url": "Invalid Zendesk QA credentials. Please check your subdomain and API token and reconnect.",
"Zendesk QA subdomain must contain only": "The configured Zendesk subdomain is invalid. Enter just the subdomain part of yourcompany.zendesk.com.",
}
def get_canonical_descriptions(self) -> CanonicalDescriptions:
from products.warehouse_sources.sources.klaus.canonical_descriptions import ( # noqa: PLC0415 — keeps the descriptions dict off the import path
CANONICAL_DESCRIPTIONS,
)
return CANONICAL_DESCRIPTIONS
def get_schemas(
self,
config: KlausSourceConfig,
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
name=endpoint,
supports_incremental=(fields := INCREMENTAL_FIELDS.get(endpoint)) is not None,
supports_append=fields is not None,
incremental_fields=fields or [],
)
for endpoint in ENDPOINTS
]
if names is not None:
names_set = set(names)
schemas = [s for s in schemas if s.name in names_set]
return schemas
def validate_credentials(
self, config: KlausSourceConfig, team_id: int, schema_name: Optional[str] = None, api_version: str | None = None
) -> tuple[bool, str | None]:
return validate_klaus_credentials(config.subdomain, config.api_token)
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[KlausResumeConfig]:
return ResumableSourceManager[KlausResumeConfig](inputs, KlausResumeConfig)
def source_for_pipeline(
self,
config: KlausSourceConfig,
resumable_source_manager: ResumableSourceManager[KlausResumeConfig],
inputs: SourceInputs,
) -> SourceResponse:
return klaus_source(
subdomain=config.subdomain,
api_token=config.api_token,
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,
)