: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
feat(warehouse_sources): support Formbricks API version v2 (#74169)
Tom Owersc96f508add3d
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/formbricks/formbricks.py b/products/warehouse_sources/backend/temporal/data_imports/sources/formbricks/formbricks.pyindex cdf61fb6f896..0cec15f47380 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/formbricks/formbricks.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/formbricks/formbricks.py@@ -37,6 +37,22 @@ RESPONSE_CHUNK_BYTES = 256 * 1024# far above a slow-drip stall.MAX_DOWNLOAD_SECONDS = 300+# Formbricks ships both a v1 and a v2 management API, and neither wholly supersedes the other for+# an ingest-only reader. v2 adds paginated, incrementally-filterable list endpoints for responses,+# contact-attribute-keys, and webhooks — which this source already reads from `/api/v2/` (responses+# needs the v2 sortBy/startDate/filterDateField window for incremental sync; v1's list has none of+# those). But v2 exposes no environment-wide list endpoint for surveys, contacts, contact-attributes,+# or action-classes, so those stay on `/api/v1/`. Each resource's path in FORMBRICKS_ENDPOINTS+# therefore already targets whichever version can list it, and the source-level pin does not re-route+# requests: routing the v1-only resources to v2 would 404, and the v2 resources are already on v2.+# v2 is the version Formbricks recommends for new integrations and the one this source's primary+# resource requires, so it is the default stamped onto new sources; v1 stays supported so existing+# pins keep resolving.+FORMBRICKS_API_VERSION_V1 = "v1"+FORMBRICKS_API_VERSION_V2 = "v2"+FORMBRICKS_SUPPORTED_VERSIONS = (FORMBRICKS_API_VERSION_V1, FORMBRICKS_API_VERSION_V2)+FORMBRICKS_DEFAULT_VERSION = FORMBRICKS_API_VERSION_V2+DEFAULT_HOST = "https://app.formbricks.com"HOST_NOT_ALLOWED_ERROR = "Formbricks host is not allowed"HTTP_NOT_ALLOWED_ERROR = "Formbricks host must use HTTPS"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/formbricks/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/formbricks/source.pyindex a54ffe57cd07..4fab31ba553a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/formbricks/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/formbricks/source.py@@ -21,6 +21,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.regfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.schema import SourceSchemafrom products.warehouse_sources.backend.temporal.data_imports.sources.formbricks.formbricks import (+ FORMBRICKS_DEFAULT_VERSION,+ FORMBRICKS_SUPPORTED_VERSIONS,HOST_NOT_ALLOWED_ERROR,HTTP_NOT_ALLOWED_ERROR,RESPONSE_TOO_LARGE_ERROR,@@ -42,6 +44,8 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType@SourceRegistry.registerclass FormbricksSource(ResumableSource[FormbricksSourceConfig, FormbricksResumeConfig]):+ supported_versions = FORMBRICKS_SUPPORTED_VERSIONS+ default_version = FORMBRICKS_DEFAULT_VERSIONapi_docs_url = "https://formbricks.com/docs/api-reference/rest-api"lists_tables_without_credentials = True # static endpoint catalog — safe for public docsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/formbricks/tests/test_formbricks_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/formbricks/tests/test_formbricks_source.pyindex 0b63c5861fda..030f5427a5ad 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/formbricks/tests/test_formbricks_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/formbricks/tests/test_formbricks_source.py@@ -7,9 +7,14 @@ from posthog.schema import ReleaseStatus, SourceFieldInputConfig, SourceFieldInpfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.formbricks.formbricks import (+ FORMBRICKS_API_VERSION_V1,+ FORMBRICKS_API_VERSION_V2,FormbricksResumeConfig,)-from products.warehouse_sources.backend.temporal.data_imports.sources.formbricks.settings import ENDPOINTS+from products.warehouse_sources.backend.temporal.data_imports.sources.formbricks.settings import (+ ENDPOINTS,+ FORMBRICKS_ENDPOINTS,+)from products.warehouse_sources.backend.temporal.data_imports.sources.formbricks.source import FormbricksSourcefrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.formbricks import (FormbricksSourceConfig,@@ -61,6 +66,29 @@ class TestFormbricksSource:def test_lists_tables_without_credentials(self) -> None:assert self.source.lists_tables_without_credentials is True+ def test_supports_v1_and_v2_with_v2_default(self) -> None:+ # New sources are stamped v2 (the version Formbricks recommends and that the responses+ # incremental sync requires); v1 stays supported so existing pins keep resolving.+ assert self.source.supported_versions == (FORMBRICKS_API_VERSION_V1, FORMBRICKS_API_VERSION_V2)+ assert self.source.default_version == FORMBRICKS_API_VERSION_V2++ @parameterized.expand(+ [+ ("responses", FORMBRICKS_API_VERSION_V2),+ ("contact_attribute_keys", FORMBRICKS_API_VERSION_V2),+ ("webhooks", FORMBRICKS_API_VERSION_V2),+ ("surveys", FORMBRICKS_API_VERSION_V1),+ ("contacts", FORMBRICKS_API_VERSION_V1),+ ("contact_attributes", FORMBRICKS_API_VERSION_V1),+ ("action_classes", FORMBRICKS_API_VERSION_V1),+ ]+ )+ def test_each_resource_targets_the_version_that_lists_it(self, endpoint: str, expected_version: str) -> None:+ # Only responses/contact-attribute-keys/webhooks have an environment-wide v2 list endpoint;+ # the rest are v1-only. A resource pointed at the wrong version would 404 (v1-only resource+ # on v2) or lose incremental filtering (responses on v1), so pin the routing per resource.+ assert f"/api/{expected_version}/management/" in FORMBRICKS_ENDPOINTS[endpoint].path+def test_get_schemas_covers_all_endpoints(self) -> None:schemas = self.source.get_schemas(self.config, self.team_id)assert {s.name for s in schemas} == set(ENDPOINTS)