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.

fix(revenuecat): restore missing proj prefix on project id (#63906)

Tom Owers045e85014045
diff --git a/posthog/temporal/data_imports/sources/revenuecat/revenuecat.py b/posthog/temporal/data_imports/sources/revenuecat/revenuecat.py
index b7dfd83caf89..3734aa213ffd 100644
--- a/posthog/temporal/data_imports/sources/revenuecat/revenuecat.py
+++ b/posthog/temporal/data_imports/sources/revenuecat/revenuecat.py
@@ -72,8 +72,9 @@ def _normalize_project_id(raw: str | None) -> str:
The setup form points users at their dashboard URL
(``app.revenuecat.com/projects/<project_id>``) to find the id, so a large
share of connection failures come from pasting the whole URL, a
- ``projects/<id>`` path fragment, or a value with stray whitespace. Pull the
- id back out and trim it so those copy-paste mistakes don't become a 404.
+ ``projects/<id>`` path fragment, a value with stray whitespace, or the bare
+ id with its ``proj`` prefix dropped. Pull the id back out, trim it, and
+ restore a missing prefix so those copy-paste mistakes don't become a 404.
"""
if not raw:
return ""
@@ -86,8 +87,16 @@ def _normalize_project_id(raw: str | None) -> str:
value = value.split(marker, 1)[1]
# Keep only the first path segment, dropping any trailing `/overview`,
# query string, or fragment that rode along with the paste.
- value = value.split("/", 1)[0].split("?", 1)[0].split("#", 1)[0]
- return value.strip()
+ value = value.split("/", 1)[0].split("?", 1)[0].split("#", 1)[0].strip()
+ # RevenueCat project ids are always `proj`-prefixed (e.g. `proj1a2b3c4d`),
+ # but the setup form points users at the dashboard where the id is shown
+ # without the prefix, so a large share of failures are bare ids like
+ # `1a2b3c4d`. Restore the prefix so that copy-paste slip isn't a dead-end
+ # 404 — the membership check against the live project list still rejects
+ # anything that isn't a real, reachable project.
+ if value and not value.startswith("proj"):
+ value = f"proj{value}"
+ return value
def _accessible_project_ids(payload: dict[str, Any] | None) -> list[str]:
diff --git a/posthog/temporal/data_imports/sources/revenuecat/tests/test_revenuecat.py b/posthog/temporal/data_imports/sources/revenuecat/tests/test_revenuecat.py
index 9797f01cf29c..50b067981c48 100644
--- a/posthog/temporal/data_imports/sources/revenuecat/tests/test_revenuecat.py
+++ b/posthog/temporal/data_imports/sources/revenuecat/tests/test_revenuecat.py
@@ -53,6 +53,18 @@ class TestValidateCredentials:
called_url = mock_session.return_value.get.call_args.args[0]
assert called_url == f"{REVENUECAT_API_BASE_URL}/projects"
+ @patch("posthog.temporal.data_imports.sources.revenuecat.revenuecat._session")
+ def test_accepts_bare_project_id_missing_proj_prefix(self, mock_session):
+ # Users routinely enter the id shown on the dashboard without its `proj`
+ # prefix (e.g. `64dbb3e3`). The prefix is restored before the membership
+ # check so the bare id resolves against the real `proj`-prefixed id.
+ mock_session.return_value.get.return_value = _ok_json_response({"items": [{"id": "proj64dbb3e3"}]})
+
+ success, error = api_client.validate_credentials("sk_test", project_id="64dbb3e3")
+
+ assert success is True
+ assert error is None
+
@patch("posthog.temporal.data_imports.sources.revenuecat.revenuecat._session")
def test_follows_pagination_when_project_is_on_a_later_page(self, mock_session):
mock_session.return_value.get.side_effect = [
@@ -463,6 +475,9 @@ class TestNormalizeProjectId:
("url_with_fragment", "app.revenuecat.com/projects/proj1a2b3c4d#section", "proj1a2b3c4d"),
("bare_projects_path_fragment", "projects/proj1a2b3c4d", "proj1a2b3c4d"),
("trailing_slash", "proj1a2b3c4d/", "proj1a2b3c4d"),
+ ("bare_id_missing_proj_prefix", "1a2b3c4d", "proj1a2b3c4d"),
+ ("bare_id_from_url_missing_prefix", "app.revenuecat.com/projects/1a2b3c4d", "proj1a2b3c4d"),
+ ("bare_id_with_whitespace_missing_prefix", " 1a2b3c4d ", "proj1a2b3c4d"),
("none", None, ""),
("empty", "", ""),
("whitespace_only", " ", ""),
@@ -561,3 +576,21 @@ class TestIterateListEndpointNormalization:
called_url = mock_session.return_value.get.call_args.args[0]
assert called_url == f"{REVENUECAT_API_BASE_URL}/projects/proj_real/customers"
+
+ @patch("posthog.temporal.data_imports.sources.revenuecat.revenuecat._session")
+ def test_restores_missing_proj_prefix_in_request_url(self, mock_session):
+ # A source stored with a bare id must hit the `proj`-prefixed path at
+ # sync time, matching what validation accepted.
+ mock_session.return_value.get.return_value = _ok_json_response({"items": [], "next_page": None})
+
+ list(
+ api_client.iterate_list_endpoint(
+ "sk_test",
+ project_id="64dbb3e3",
+ path_suffix="/customers",
+ endpoint_name="customers",
+ )
+ )
+
+ called_url = mock_session.return_value.get.call_args.args[0]
+ assert called_url == f"{REVENUECAT_API_BASE_URL}/projects/proj64dbb3e3/customers"