: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.cloudbeds._config import CloudbedsSourceConfig
from products.warehouse_sources.sources.cloudbeds.cloudbeds import (
CLOUDBEDS_API_VERSION_V1_2,
CLOUDBEDS_API_VERSION_V1_3,
PROPERTY_ID_REQUIRED_MESSAGE,
CloudbedsResumeConfig,
cloudbeds_source,
validate_credentials,
)
from products.warehouse_sources.sources.cloudbeds.settings import CLOUDBEDS_ENDPOINTS, 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 CloudbedsSource(ResumableSource[CloudbedsSourceConfig, CloudbedsResumeConfig]):
codebase_detection = detect(env=("^CLOUDBEDS_",))
lists_tables_without_credentials = True # static endpoint catalog - safe for public docs
# v1.2 and v1.3 serve the same methods and response shapes; the version is just the
# `/api/<version>` URL segment, threaded into the request layer via resolve_api_version.
supported_versions = (CLOUDBEDS_API_VERSION_V1_2, CLOUDBEDS_API_VERSION_V1_3)
default_version = CLOUDBEDS_API_VERSION_V1_3
api_docs_url = "https://developers.cloudbeds.com/reference"
@property
def source_type(self) -> ExternalDataSourceType:
return ExternalDataSourceType.CLOUDBEDS
@property
def connection_host_fields(self) -> list[str]:
# `property_id` scopes which property the stored API key reads from; retargeting it must
# re-require the key so a group-level credential can't be pointed at another property.
return ["property_id"]
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
name=ExternalDataSourceType.CLOUDBEDS,
category=DataWarehouseSourceCategory.PRODUCTIVITY,
label="Cloudbeds",
releaseStatus=ReleaseStatus.BETA,
caption="""Enter your Cloudbeds API key to pull your properties, reservations and their rate details, guests, rooms, room types, transactions, rate plans, and staff users into the PostHog Data warehouse.
You can create an API key under **Settings → API credentials** in [Cloudbeds](https://hotels.cloudbeds.com). Note that Cloudbeds API keys expire after 30 days of inactivity, so a key that has not been used recently may need to be regenerated.
If your account manages multiple properties, enter the ID of the property you want to sync - group-level credentials require it to scope reads to a single property.
""",
iconPath="/static/services/cloudbeds.png",
docsUrl="https://posthog.com/docs/cdp/sources/cloudbeds",
keywords=["pms", "hotel", "hospitality"],
fields=cast(
list[FieldType],
[
SourceFieldInputConfig(
name="api_key",
label="API key",
type=SourceFieldInputConfigType.PASSWORD,
required=True,
placeholder="",
secret=True,
),
SourceFieldInputConfig(
name="property_id",
label="Property ID (required for multi-property accounts)",
type=SourceFieldInputConfigType.TEXT,
required=False,
placeholder="",
secret=False,
),
],
),
)
def get_canonical_descriptions(self) -> CanonicalDescriptions:
from products.warehouse_sources.sources.cloudbeds.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.cloudbeds.com": "Your Cloudbeds API key is invalid or has expired (keys expire after 30 days of inactivity). Generate a new key under Settings → API credentials, then reconnect.",
"403 Client Error: Forbidden for url: https://api.cloudbeds.com": "Your Cloudbeds credentials do not have access to this data. Check the credential's permission scopes, then reconnect.",
PROPERTY_ID_REQUIRED_MESSAGE: None,
}
def get_schemas(
self,
config: CloudbedsSourceConfig,
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 for now (INCREMENTAL_FIELDS is empty) - see the note in
# settings.py about the unverified `modifiedSince` filter on getReservations.
return build_endpoint_schemas(ENDPOINTS, INCREMENTAL_FIELDS, names)
def validate_credentials(
self,
config: CloudbedsSourceConfig,
team_id: int,
schema_name: Optional[str] = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
# One probe validates the token itself; per-endpoint OAuth scopes surface at sync time via
# get_non_retryable_errors. getHotels is served under both versions, so the probe runs on the
# instance's resolved pin (default_version pre-creation).
return validate_credentials(config.api_key, self.resolve_api_version(api_version), config.property_id)
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[CloudbedsResumeConfig]:
return ResumableSourceManager[CloudbedsResumeConfig](inputs, CloudbedsResumeConfig)
def source_for_pipeline(
self,
config: CloudbedsSourceConfig,
resumable_source_manager: ResumableSourceManager[CloudbedsResumeConfig],
inputs: SourceInputs,
) -> SourceResponse:
if inputs.schema_name not in CLOUDBEDS_ENDPOINTS:
raise ValueError(f"Unknown Cloudbeds schema '{inputs.schema_name}'")
return cloudbeds_source(
api_key=config.api_key,
endpoint=inputs.schema_name,
team_id=inputs.team_id,
job_id=inputs.job_id,
resumable_source_manager=resumable_source_manager,
api_version=self.resolve_api_version(inputs.api_version),
property_id=config.property_id,
db_incremental_field_last_value=None, # every Cloudbeds endpoint is full refresh
)