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(data-warehouse): add 4 missing tables to the Coda source (#119025)

Tom Owersff8bf2e83496
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index e6400b2d461b..35cbf0f41397 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -2864,12 +2864,12 @@ Diffed against: <https://coda.io/apis/v1/openapi.json>
- [x] `/docs/{docId}/tables/{tableIdOrName}/columns` — Column definitions (name, type, formula) that resolve the column IDs used as keys in every synced row - without it rows are unreadable (high)
- [x] `/analytics/docs` — Per-doc usage analytics (views, active users) - the headline metric for measuring doc adoption across a workspace (high). `/analytics/docs/summary` skipped: it returns a single scalar (`totalSessions`) with no id or grain, not a table.
-- [ ] `/workspaces/{workspaceId}/users` — Workspace member lookup that resolves the owner/creator IDs on docs (medium)
-- [ ] `/docs/{docId}/pages` — Page hierarchy per doc - the structural dimension for content inventory and for joining page analytics (medium)
+- [x] `/workspaces/{workspaceId}/users` — Workspace member lookup that resolves the owner/creator IDs on docs (medium) — synced as `workspace_users`; only workspaces where the token user is an admin return rows
+- [x] `/docs/{docId}/pages` — Page hierarchy per doc - the structural dimension for content inventory and for joining page analytics (medium)
- [x] `/analytics/docs/{docId}/pages` — Page-level view analytics, one grain below doc analytics (medium)
- [x] `/folders` — Folder lookup resolving the folder reference each doc carries (medium)
-- [ ] `/docs/{docId}/acl/permissions` — Who a doc is shared with - needed for access and governance reporting over the docs table (low)
-- [ ] `/workspaces/{workspaceId}/roles` — Role lookup that segments workspace users by license/role type (low)
+- [x] `/docs/{docId}/acl/permissions` — Who a doc is shared with - needed for access and governance reporting over the docs table (low)
+- [x] `/workspaces/{workspaceId}/roles` — Role lookup that segments workspace users by license/role type (low) — synced as `workspace_role_activity`; the endpoint returns monthly active and inactive user counts per role, not a role lookup
- [ ] `/docs/{docId}/controls and /docs/{docId}/formulas` — Remaining doc object types, completing the content inventory alongside tables and pages (low)
- [ ] `/analytics/packs and /analytics/packs/summary` — Pack install and usage analytics, relevant only to workspaces that publish packs (low)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/coda/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/coda/canonical_descriptions.py
index 0968b48d79a1..6ab127263737 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/coda/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/coda/canonical_descriptions.py
@@ -113,4 +113,71 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"workspace": "Reference to the workspace the folder belongs to.",
},
},
+ "pages": {
+ "description": "A page in a Coda doc. Pages hold the doc's canvases and nest under parent pages.",
+ "docs_url": "https://coda.io/developers/apis/v1#tag/Pages",
+ "columns": {
+ "id": "Identifier for the page, unique within its doc.",
+ "type": "Type of the object, always 'page'.",
+ "href": "API URL of the page.",
+ "browserLink": "URL to open the page in a browser.",
+ "name": "The page's name.",
+ "subtitle": "The page's subtitle.",
+ "contentType": "Type of content on the page, such as a canvas or an embed.",
+ "isHidden": "Whether the page is hidden in the UI.",
+ "isEffectivelyHidden": "Whether the page or any of its parent pages is hidden in the UI.",
+ "parent": "Reference to the parent page, if the page is nested.",
+ "children": "References to the pages nested under this page.",
+ "authors": "People who authored the page.",
+ "createdAt": "Time at which the page was created.",
+ "createdBy": "Person who created the page.",
+ "updatedAt": "Time at which the page content was last modified.",
+ "updatedBy": "Person who last modified the page content.",
+ "_doc_id": "Identifier of the parent doc, injected during the fan-out sync.",
+ },
+ },
+ "permissions": {
+ "description": "A sharing permission on a Coda doc: one principal and the access it has.",
+ "docs_url": "https://coda.io/developers/apis/v1#tag/Permissions",
+ "columns": {
+ "id": "Identifier for the permission.",
+ "principal": "Who the doc is shared with: an email, group, domain, workspace, or anyone.",
+ "access": "Access the principal has, such as readonly, comment, or write.",
+ "_doc_id": "Identifier of the parent doc, injected during the fan-out sync.",
+ },
+ },
+ "workspace_users": {
+ "description": "A member of a Coda workspace, with their role and doc activity.",
+ "docs_url": "https://coda.io/developers/apis/v1#tag/Workspaces",
+ "columns": {
+ "email": "Email of the user.",
+ "name": "Name of the user.",
+ "role": "The user's workspace role: Admin, DocMaker, or Editor.",
+ "pictureUrl": "URL of the user's picture.",
+ "registeredAt": "Time at which the user registered in the workspace.",
+ "roleChangedAt": "Time at which the user's role last changed in the workspace.",
+ "lastActiveAt": "Date when the user last took an action in any workspace.",
+ "ownedDocs": "Number of docs the user owns in the workspace.",
+ "docsLastActiveAt": "Date when anyone last accessed a doc the user owns in the workspace.",
+ "docCollaboratorCount": "Number of collaborators that interacted with the user's docs in the last 90 days.",
+ "totalDocs": "Number of docs the user owns, manages, or added pages to in the last 90 days.",
+ "totalDocsLastActiveAt": "Date when anyone last accessed a doc the user owns or contributed to.",
+ "totalDocCollaboratorsLast90Days": "Number of unique users that viewed a doc the user owns, manages, or added pages to in the last 90 days.",
+ "_workspace_id": "Identifier of the workspace, injected during the fan-out sync.",
+ },
+ },
+ "workspace_role_activity": {
+ "description": "Monthly counts of active and inactive users per role in a Coda workspace.",
+ "docs_url": "https://coda.io/developers/apis/v1#tag/Workspaces",
+ "columns": {
+ "month": "Month the counts describe.",
+ "activeAdminCount": "Number of active Admins.",
+ "activeDocMakerCount": "Number of active Doc Makers.",
+ "activeEditorCount": "Number of active Editors.",
+ "inactiveAdminCount": "Number of inactive Admins.",
+ "inactiveDocMakerCount": "Number of inactive Doc Makers.",
+ "inactiveEditorCount": "Number of inactive Editors.",
+ "_workspace_id": "Identifier of the workspace, injected during the fan-out sync.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/coda/coda.py b/products/warehouse_sources/backend/temporal/data_imports/sources/coda/coda.py
index ad4161f5b76f..150b228fe1a5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/coda/coda.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/coda/coda.py
@@ -10,7 +10,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
JSONResponseCursorPaginator,
)
-from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import EndpointResource
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (
+ EndpointResource,
+ ResponseAction,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probe
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
@@ -18,6 +21,14 @@ CODA_BASE_URL = "https://coda.io/apis/v1"
PAGE_SIZE = 100
ROWS_PAGE_SIZE = 200
+# The docs list also returns docs the token user only opened (shared or published docs from other
+# workspaces). Their sharing settings and their workspace's members are not readable, so skip those
+# parents instead of failing the whole fan-out.
+_SKIP_INACCESSIBLE_PARENT: list[ResponseAction] = [
+ {"status_code": 403, "action": "ignore"},
+ {"status_code": 404, "action": "ignore"},
+]
+
def _cursor_paginator() -> JSONResponseCursorPaginator:
# Coda hands back an opaque `nextPageToken` in the body and expects it echoed as `pageToken`;
@@ -163,8 +174,109 @@ def _folders_resource() -> EndpointResource:
}
+def _pages_resource() -> EndpointResource:
+ return {
+ "name": "pages",
+ "endpoint": {
+ "path": "/docs/{doc_id}/pages",
+ "params": {
+ "doc_id": {"type": "resolve", "resource": "docs", "field": "id"},
+ "limit": PAGE_SIZE,
+ },
+ "data_selector": "items",
+ "paginator": _cursor_paginator(),
+ },
+ "include_from_parent": ["id"],
+ "data_map": _map_row(renames={"_docs_id": "_doc_id"}),
+ }
+
+
+def _permissions_resource() -> EndpointResource:
+ return {
+ "name": "permissions",
+ "endpoint": {
+ "path": "/docs/{doc_id}/acl/permissions",
+ "params": {
+ "doc_id": {"type": "resolve", "resource": "docs", "field": "id"},
+ "limit": PAGE_SIZE,
+ },
+ "data_selector": "items",
+ "paginator": _cursor_paginator(),
+ "response_actions": _SKIP_INACCESSIBLE_PARENT,
+ },
+ "include_from_parent": ["id"],
+ "data_map": _map_row(renames={"_docs_id": "_doc_id"}),
+ }
+
+
+def _first_doc_per_workspace() -> Callable[[dict[str, Any]], dict[str, Any] | list[dict[str, Any]]]:
+ seen: set[str] = set()
+
+ def _mapper(row: dict[str, Any]) -> dict[str, Any] | list[dict[str, Any]]:
+ workspace_id = row.get("workspaceId")
+ if workspace_id is None or workspace_id in seen:
+ return []
+ seen.add(workspace_id)
+ return row
+
+ return _mapper
+
+
+def _workspaces_resource() -> EndpointResource:
+ # Coda has no endpoint that lists workspaces, so walk the docs list and keep one doc per
+ # workspace. The workspace endpoints then run once per workspace instead of once per doc.
+ return {
+ "name": "workspaces",
+ "endpoint": {
+ "path": "/docs",
+ "params": {"limit": PAGE_SIZE},
+ "data_selector": "items",
+ "paginator": _cursor_paginator(),
+ },
+ "data_map": _first_doc_per_workspace(),
+ }
+
+
+def _workspace_users_resource() -> EndpointResource:
+ return {
+ "name": "workspace_users",
+ "endpoint": {
+ # This endpoint documents no `limit` parameter, only `pageToken`.
+ "path": "/workspaces/{workspace_id}/users",
+ "params": {
+ "workspace_id": {"type": "resolve", "resource": "workspaces", "field": "workspaceId"},
+ },
+ "data_selector": "items",
+ "paginator": _cursor_paginator(),
+ # Only workspace admins can list members.
+ "response_actions": _SKIP_INACCESSIBLE_PARENT,
+ },
+ "include_from_parent": ["workspaceId"],
+ "data_map": _map_row(renames={"_workspaces_workspaceId": "_workspace_id"}),
+ }
+
+
+def _workspace_role_activity_resource() -> EndpointResource:
+ return {
+ "name": "workspace_role_activity",
+ "endpoint": {
+ "path": "/workspaces/{workspace_id}/roles",
+ "params": {
+ "workspace_id": {"type": "resolve", "resource": "workspaces", "field": "workspaceId"},
+ },
+ "data_selector": "items",
+ # The response has no page token: all months come back in one response.
+ "paginator": "single_page",
+ "response_actions": _SKIP_INACCESSIBLE_PARENT,
+ },
+ "include_from_parent": ["workspaceId"],
+ "data_map": _map_row(renames={"_workspaces_workspaceId": "_workspace_id"}),
+ }
+
+
def _resource_chain(endpoint: str) -> list[EndpointResource]:
- # Rows and columns fan out docs → tables → …; page analytics fans out docs → pages. Each
+ # Rows and columns fan out docs → tables → …; pages, permissions and page analytics fan out
+ # over docs; workspace endpoints fan out over the distinct workspaces of the docs. Each
# endpoint's chain is the resources up to and including it, so iterating the leaf drives its
# parents lazily. Fresh dicts per call — config setup mutates.
if endpoint == "docs":
@@ -181,6 +293,14 @@ def _resource_chain(endpoint: str) -> list[EndpointResource]:
return [_docs_resource(), _page_analytics_resource()]
if endpoint == "folders":
return [_folders_resource()]
+ if endpoint == "pages":
+ return [_docs_resource(), _pages_resource()]
+ if endpoint == "permissions":
+ return [_docs_resource(), _permissions_resource()]
+ if endpoint == "workspace_users":
+ return [_workspaces_resource(), _workspace_users_resource()]
+ if endpoint == "workspace_role_activity":
+ return [_workspaces_resource(), _workspace_role_activity_resource()]
raise ValueError(f"Unknown Coda endpoint: {endpoint!r}")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/coda/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/coda/settings.py
index b21bd91604f4..a2f821f1032b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/coda/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/coda/settings.py
@@ -39,6 +39,24 @@ CODA_ENDPOINTS: dict[str, CodaEndpointConfig] = {
"folders": CodaEndpointConfig(
name="folders",
),
+ "pages": CodaEndpointConfig(
+ name="pages",
+ primary_keys=["_doc_id", "id"],
+ ),
+ "permissions": CodaEndpointConfig(
+ name="permissions",
+ primary_keys=["_doc_id", "id"],
+ ),
+ # Workspace users carry no id; the email is unique within a workspace.
+ "workspace_users": CodaEndpointConfig(
+ name="workspace_users",
+ primary_keys=["_workspace_id", "email"],
+ ),
+ # One row per workspace and month, with active and inactive user counts per role.
+ "workspace_role_activity": CodaEndpointConfig(
+ name="workspace_role_activity",
+ primary_keys=["_workspace_id", "month"],
+ ),
}
ENDPOINTS = tuple(CODA_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/coda/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/coda/source.py
index d6d1b894ac38..dddd728266fb 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/coda/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/coda/source.py
@@ -55,7 +55,7 @@ class CodaSource(SimpleSource[CodaSourceConfig]):
label="Coda",
caption="""Enter your Coda API token to pull your docs, tables, and rows into the PostHog Data warehouse.
-You can generate an API token in [Coda account settings](https://coda.io/account). The token only sees docs its creator can access. Rows are synced from every table of every doc — note Coda's doc-listing rate limit makes large workspaces slow to sync.""",
+You can generate an API token in [Coda account settings](https://coda.io/account). The token only sees docs its creator can access. Rows are synced from every table of every doc — note Coda's doc-listing rate limit makes large workspaces slow to sync. Workspace users and role activity sync only for workspaces where the token's creator is an admin.""",
iconPath="/static/services/coda.png",
docsUrl="https://posthog.com/docs/cdp/sources/coda",
releaseStatus=ReleaseStatus.ALPHA,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/coda/tests/test_coda.py b/products/warehouse_sources/backend/temporal/data_imports/sources/coda/tests/test_coda.py
index 7003ac9f8631..870b80a02a76 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/coda/tests/test_coda.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/coda/tests/test_coda.py
@@ -90,6 +90,80 @@ class TestGetRows:
assert [(p["page_id"], p["_doc_id"]) for p in result.rows] == [("page-1", "doc1")]
assert result.paths[1] == "/apis/v1/analytics/docs/doc1/pages"
+ def test_pages_fan_out_over_docs(self) -> None:
+ result = _driver().run(
+ "pages",
+ [
+ _response([{"id": "doc1"}]), # docs
+ _response([{"id": "canvas-1", "name": "Launch", "parent": {"id": "canvas-0"}}]), # pages for doc1
+ ],
+ )
+
+ assert result.raised is None
+ assert [(p["id"], p["_doc_id"]) for p in result.rows] == [("canvas-1", "doc1")]
+ assert result.paths[1] == "/apis/v1/docs/doc1/pages"
+
+ @pytest.mark.parametrize(
+ "endpoint, parents, denied_status, expected_paths, child_row, key",
+ [
+ (
+ "permissions",
+ [{"id": "doc1"}, {"id": "doc2"}],
+ 403,
+ ["/apis/v1/docs", "/apis/v1/docs/doc1/acl/permissions", "/apis/v1/docs/doc2/acl/permissions"],
+ {"id": "perm-1", "access": "readonly", "principal": {"type": "email", "email": "[email protected]"}},
+ ("_doc_id", "doc2"),
+ ),
+ (
+ "workspace_users",
+ [
+ {"id": "doc1", "workspaceId": "ws-1"},
+ {"id": "doc2", "workspaceId": "ws-1"},
+ {"id": "doc3", "workspaceId": "ws-2"},
+ ],
+ 403,
+ ["/apis/v1/docs", "/apis/v1/workspaces/ws-1/users", "/apis/v1/workspaces/ws-2/users"],
+ {"email": "[email protected]", "name": "A", "role": "Admin", "registeredAt": "2026-01-01T00:00:00Z"},
+ ("_workspace_id", "ws-2"),
+ ),
+ (
+ "workspace_role_activity",
+ [
+ {"id": "doc1", "workspaceId": "ws-1"},
+ {"id": "doc2", "workspaceId": "ws-1"},
+ {"id": "doc3", "workspaceId": "ws-2"},
+ ],
+ 404,
+ ["/apis/v1/docs", "/apis/v1/workspaces/ws-1/roles", "/apis/v1/workspaces/ws-2/roles"],
+ {"month": "2026-01-15", "activeAdminCount": 1, "activeEditorCount": 4},
+ ("_workspace_id", "ws-2"),
+ ),
+ ],
+ )
+ def test_fan_out_skips_inaccessible_parent(
+ self,
+ endpoint: str,
+ parents: list[dict[str, Any]],
+ denied_status: int,
+ expected_paths: list[str],
+ child_row: dict[str, Any],
+ key: tuple[str, str],
+ ) -> None:
+ result = _driver().run(
+ endpoint,
+ [
+ _response(parents),
+ ScriptedResponse(status=denied_status, json={"statusCode": denied_status}),
+ _response([child_row]),
+ ],
+ )
+
+ assert result.raised is None
+ # Workspace endpoints call each workspace once, even when several docs share it.
+ assert result.paths == expected_paths
+ key_column, parent_id = key
+ assert [row[key_column] for row in result.rows] == [parent_id]
+
def test_table_without_id_fails_fast_in_rows(self) -> None:
result = _driver().run("rows", [_response([{"id": "doc1"}]), _response([{"name": "broken"}])])