Skip to content

: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.

feat(warehouse_sources): support Rippling API version v2 (#80088)

Tom Owersd7b7980256be
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.md
index 0eb9d8682912..62c17f389a52 100644
--- a/.agents/skills/warehouse-source-new-version/SKILL.md
+++ b/.agents/skills/warehouse-source-new-version/SKILL.md
@@ -51,7 +51,7 @@ Add it when any of these hold:
- Keep it minimal. If the version is just a header/URL segment and response shapes are compatible, thread the version string down to where the client/URL is built (see Stripe: `StripeSource.source_for_pipeline` passes `self.resolve_api_version(inputs.api_version)` → `stripe_source(...)` → `StripeClient(stripe_version=...)`). Resolve through `resolve_api_version` at the source class — never hardcode a fallback version in the request layer.
- Only introduce per-version modules/branches where behavior genuinely diverges (different pagination, different field mapping). Keep all version branching inside the source's own directory — never in shared layers.
- When the new version renames endpoints, changes primary keys, or reshapes responses, the divergence must actually be branched — never leave the old single-version request path serving the new default. All the relevant surfaces can vary by version: `get_rows` receives the resolved pin in `inputs.api_version`; credential fields can key off `default_version`.
- - Conversely, don't add inert scaffolding: an `api_version` param no caller varies, or a version→URL map with identical values, is a review finding, not forward-compat. Declaration-only (`supported_versions`/`default_version` and nothing else) is the correct shape just when the gate above passed on a non-wire reason — the old label is being retired, the vendor switches behavior account-side rather than per request, or the source already reads the vendor's newest generation under the framework's legacy unversioned label (verify the request paths the source actually builds, not the label — a legacy label can already ride the new wire, so the new label just formalizes it for new rows and both resolve identically). If the gate passed on nothing at all, there is no PR.
+ - Conversely, don't add inert scaffolding: an `api_version` param no caller varies, or a version→URL map with identical values, is a review finding, not forward-compat. Declaration-only (`supported_versions`/`default_version` and nothing else) is the correct shape just when the gate above passed on a non-wire reason — the old label is being retired, the vendor switches behavior account-side rather than per request, or the source already reads the vendor's newest generation under the framework's legacy unversioned label (verify the request paths the source actually builds, not the label — a legacy label can already ride the new wire, so the new label just formalizes it for new rows and both resolve identically). If the gate passed on nothing at all, there is no PR. When no-header requests resolve to a version bound to the credential account-side (not a moving "latest"), threading a version header is not merely inert — it overrides the customer's chosen version, the silent move this framework exists to prevent — so stay declaration-only and don't send one.
- **Discovery and probe paths receive the pin — consume it.** The framework passes the resolved pin as the `api_version` parameter of `get_schemas`, `validate_credentials`, `get_endpoint_permissions`, and the webhook management methods. A multi-version source MUST build its discovery/probe/webhook clients from that parameter, not from `default_version` or a hardcoded header — otherwise a pinned source discovers/reconciles under the wrong version and its tables can disappear, duplicate, or fail reconciliation. Resolve it with `self.resolve_api_version(api_version)` — callers with a row pass an already-resolved value (mirroring `SourceInputs.api_version`), so the source-side resolve only covers pre-creation calls that pass `None`. Ignoring the parameter is only correct when you can state why the version makes no difference to that path.
- Watch for version-dependent column hints/schemas: e.g. Stripe's `external_table_definitions` were built for specific versions. When adding a version whose response shapes differ, gate the canonical column hints to the versions they were built for and let newer versions auto-infer the schema from the data (a set of hint-compatible versions checked where hints are applied). For `has_managed_hogql_schema=True` sources this includes the read path: `hogql_definition`'s canonical column mapping is version-blind, so renamed columns need the canonical schema/descriptions updated too.
4. **Keep old versions working**: do not delete or alter the request path for previously supported versions. Removing a version is an explicit future decision, not part of a version-add PR.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/rippling/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/rippling/source.py
index 1c7940af4b41..4ef7271e57d1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/rippling/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/rippling/source.py
@@ -37,8 +37,17 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
@SourceRegistry.register
class RipplingSource(ResumableSource[RipplingSourceConfig, RipplingResumeConfig]):
+ # Rippling versions its REST API through a dated `Rippling-Api-Version` header and, when no
+ # header is sent, serves the version bound to the API token account-side (chosen when the
+ # customer mints the token) — never a moving "latest". We send the token as-is with no version
+ # header, so every pin issues byte-for-byte identical requests; the pin only records which tier
+ # a source targets, and adding a header would override the customer's token version — the silent
+ # move this framework prevents. New sources default to v2, Rippling's current REST API tier.
+ supported_versions = ("v1", "v2")
+ default_version = "v2"
+
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
- api_docs_url = "https://developer.rippling.com/"
+ api_docs_url = "https://developer.rippling.com/documentation/rest-api/guides/versioning"
@property
def source_type(self) -> ExternalDataSourceType:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/rippling/tests/test_rippling_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/rippling/tests/test_rippling_source.py
index bfd6f60f1bf5..547b74a04391 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/rippling/tests/test_rippling_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/rippling/tests/test_rippling_source.py
@@ -1,6 +1,13 @@
+import json
+from collections.abc import Iterable
+from typing import Any, cast
+from urllib.parse import urlparse
+
import pytest
from unittest import mock
+from requests import Response
+
from posthog.schema import ReleaseStatus, SourceFieldInputConfig, SourceFieldInputConfigType
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
@@ -11,10 +18,14 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.rippling.r
from products.warehouse_sources.backend.temporal.data_imports.sources.rippling.settings import (
ENDPOINTS,
INCREMENTAL_FIELDS,
+ RIPPLING_ENDPOINTS,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.rippling.source import RipplingSource
from products.warehouse_sources.backend.types import ExternalDataSourceType
+# The REST framework builds its session via make_tracked_session in the rest_client module.
+CLIENT_SESSION_PATCH = "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.rest_client.make_tracked_session"
+
class TestRipplingSource:
def setup_method(self):
@@ -134,6 +145,52 @@ class TestRipplingSource:
assert kwargs["db_incremental_field_last_value"] == "2024-10-01T00:00:00"
assert kwargs["incremental_field"] == "updated_at"
+ def test_version_declaration_defaults_to_v2_with_v1_supported(self):
+ # Rippling's REST API version is bound to the token account-side, so both labels issue the
+ # same requests; the default tracks the newest label without repinning existing v1 sources.
+ assert self.source.supported_versions == ("v1", "v2")
+ assert self.source.default_version == "v2"
+ assert self.source.deprecated_versions == ()
+
+ @pytest.mark.parametrize("pinned_version", [None, "v1", "v2"])
+ @pytest.mark.parametrize("endpoint", ["workers", "work_locations"])
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_request_path_is_identical_for_every_version(self, mock_session, endpoint, pinned_version):
+ # The pin only records which Rippling tier a source targets; it must never change the wire.
+ # A future v2 branch that switched paths or injected a `Rippling-Api-Version` header would
+ # break existing v1 syncs and silently override the customer's token-bound version.
+ session = mock_session.return_value
+ session.headers = {}
+ captured: list[Any] = []
+
+ def _prepare(request: Any) -> mock.MagicMock:
+ captured.append(request)
+ prepared = mock.MagicMock()
+ prepared.url = request.url
+ return prepared
+
+ session.prepare_request.side_effect = _prepare
+ page = Response()
+ page.status_code = 200
+ page._content = json.dumps({"results": [], "next_link": None}).encode()
+ session.send.return_value = page
+
+ inputs = mock.MagicMock()
+ inputs.schema_name = endpoint
+ inputs.api_version = pinned_version
+ inputs.should_use_incremental_field = False
+ inputs.db_incremental_field_last_value = None
+ inputs.incremental_field = None
+ manager = mock.MagicMock()
+ manager.can_resume.return_value = False
+
+ response = self.source.source_for_pipeline(self.config, manager, inputs)
+ list(cast(Iterable[Any], response.items()))
+
+ assert captured, "expected at least one request"
+ assert urlparse(captured[0].url).path == RIPPLING_ENDPOINTS[endpoint].path
+ assert "Rippling-Api-Version" not in (captured[0].headers or {})
+
@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.rippling.source.rippling_source")
def test_source_for_pipeline_omits_last_value_on_full_refresh(self, mock_rippling_source):
inputs = mock.MagicMock()