: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.clari._config import ClariSourceConfig
from products.warehouse_sources.sources.clari.clari import (
ClariResumeConfig,
clari_source,
validate_credentials as validate_clari_credentials,
)
from products.warehouse_sources.sources.clari.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 ClariSource(ResumableSource[ClariSourceConfig, ClariResumeConfig]):
codebase_detection = detect(env=("^CLARI_",))
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
supported_versions = ("v4",)
default_version = "v4"
@property
def source_type(self) -> ExternalDataSourceType:
return ExternalDataSourceType.CLARI
def get_non_retryable_errors(self) -> dict[str, str | None]:
return {
"401 Client Error: Unauthorized for url: https://api.clari.com": "Clari authentication failed. Please check your API key.",
"403 Client Error: Forbidden for url: https://api.clari.com": "Clari denied access. Please check your API key's permissions.",
"404 Client Error: Not Found for url: https://api.clari.com/v4/export/forecast": "Clari forecast not found. Please check your forecast ID (copy it from the Forecast tab URL in Clari).",
}
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
name=ExternalDataSourceType.CLARI,
category=DataWarehouseSourceCategory.SALES,
label="Clari",
caption="""Connect your Clari account to pull your revenue data into the PostHog Data warehouse.
Generate an API key in Clari under your account's API settings. The forecast ID is in the URL when viewing a forecast tab in Clari (e.g. `app.clari.com/forecast/<forecast-id>`). Note: Clari retains audit events for ~30 days and limits bulk exports per rolling 30 days, so avoid very frequent syncs of the forecast and activity tables. The first activity sync covers the past year.""",
iconPath="/static/services/clari.png",
docsUrl="https://posthog.com/docs/cdp/sources/clari",
releaseStatus=ReleaseStatus.BETA,
fields=cast(
list[FieldType],
[
SourceFieldInputConfig(
name="api_key",
label="API key",
type=SourceFieldInputConfigType.PASSWORD,
required=True,
placeholder="",
secret=True,
),
SourceFieldInputConfig(
name="forecast_id",
label="Forecast ID",
type=SourceFieldInputConfigType.TEXT,
required=True,
placeholder="net_bookings",
secret=False,
),
],
),
)
def get_canonical_descriptions(self) -> CanonicalDescriptions:
from products.warehouse_sources.sources.clari.canonical_descriptions import CANONICAL_DESCRIPTIONS
return CANONICAL_DESCRIPTIONS
def get_schemas(
self,
config: ClariSourceConfig,
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: ClariSourceConfig, team_id: int, schema_name: Optional[str] = None, api_version: str | None = None
) -> tuple[bool, str | None]:
if validate_clari_credentials(config.api_key):
return True, None
return False, "Invalid Clari credentials"
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[ClariResumeConfig]:
return ResumableSourceManager[ClariResumeConfig](inputs, ClariResumeConfig)
def source_for_pipeline(
self,
config: ClariSourceConfig,
resumable_source_manager: ResumableSourceManager[ClariResumeConfig],
inputs: SourceInputs,
) -> SourceResponse:
return clari_source(
api_key=config.api_key,
forecast_id=config.forecast_id,
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,
)