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(coda): add columns, analytics, and folders tables (#103381)

Tom Owers51e84b4c317f
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 1828869231be..b1ddab356e24 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
@@ -1704,22 +1704,22 @@ Note: Headless API (https://api.coassemble.com/api/v1/headless). Docs sections a
## Coda — gaps
-Today (3): `docs`, `rows`, `tables`
+Today (7): `columns`, `doc_analytics`, `docs`, `folders`, `page_analytics`, `rows`, `tables`
Diffed against: <https://coda.io/apis/v1/openapi.json>
-- [ ] `/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)
-- [ ] `/analytics/docs and /analytics/docs/summary` — Per-doc usage analytics (views, active users) - the headline metric for measuring doc adoption across a workspace (high)
+- [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)
-- [ ] `/analytics/docs/{docId}/pages` — Page-level view analytics, one grain below doc analytics (medium)
-- [ ] `/folders` — Folder lookup resolving the folder reference each doc carries (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)
- [ ] `/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)
-Note: Coda has been rebranded to Superhuman Docs, but the OpenAPI spec is still served at https://coda.io/apis/v1/openapi.json (v1.6.0). The synced rows table returns cells keyed by column ID, which makes the missing columns endpoint a hard blocker rather than a nicety.
+Note: Coda has been rebranded to Superhuman Docs, but the OpenAPI spec is still served at https://coda.io/apis/v1/openapi.json (v1.6.0). The synced rows table returns cells keyed by column ID; the columns table now resolves those ids to names, types, and formulas.
## Codacy — **thin**
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 8238b1cc2ed9..0968b48d79a1 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
@@ -61,4 +61,56 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"_table_id": "Identifier of the parent table, injected during the fan-out sync.",
},
},
+ "columns": {
+ "description": "A column definition within a Coda table, giving the name, type, and formula for the column ids used as keys in each row's values.",
+ "docs_url": "https://coda.io/developers/apis/v1#tag/Columns",
+ "columns": {
+ "id": "Identifier for the column, unique within its table.",
+ "name": "The column's name.",
+ "type": "Type of the object, always 'column'.",
+ "href": "API URL of the column.",
+ "display": "Whether the column is the table's display column.",
+ "calculated": "Whether the column is a formula column.",
+ "formula": "The column's formula, if it is calculated.",
+ "defaultValue": "The column's default value, if any.",
+ "format": "The column's format (its value type and format options).",
+ "_doc_id": "Identifier of the parent doc, injected during the fan-out sync.",
+ "_table_id": "Identifier of the parent table, injected during the fan-out sync.",
+ },
+ },
+ "doc_analytics": {
+ "description": "Per-doc usage analytics for the workspace: one item per doc, with a metrics list of views, sessions, and AI credit usage over time.",
+ "docs_url": "https://coda.io/developers/apis/v1#tag/Analytics",
+ "columns": {
+ "doc_id": "Identifier of the doc these analytics describe, lifted from the nested doc object.",
+ "doc": "Metadata about the doc (id, title, creation and publish time).",
+ "metrics": "List of per-period metrics (views, copies, likes, sessions by device, and AI credits) with the date of each period.",
+ },
+ },
+ "page_analytics": {
+ "description": "Page-level view analytics within a doc: one item per page, with a metrics list of views, sessions, and time-viewed over time.",
+ "docs_url": "https://coda.io/developers/apis/v1#tag/Analytics",
+ "columns": {
+ "page_id": "Identifier of the page these analytics describe, lifted from the nested page object.",
+ "page": "Metadata about the page (id and name).",
+ "metrics": "List of per-period metrics (views, sessions, unique users, and time viewed) with the date of each period.",
+ "_doc_id": "Identifier of the parent doc, injected during the fan-out sync.",
+ },
+ },
+ "folders": {
+ "description": "A folder in a workspace, resolving the folder reference each doc carries.",
+ "docs_url": "https://coda.io/developers/apis/v1#tag/Folders",
+ "columns": {
+ "id": "Unique identifier for the folder.",
+ "name": "The folder's name.",
+ "type": "Type of the object, always 'folder'.",
+ "browserLink": "URL to open the folder in a browser.",
+ "description": "The folder's description.",
+ "icon": "The folder's icon.",
+ "iconColor": "The folder's icon color.",
+ "createdAt": "Time at which the folder was created.",
+ "canEdit": "Whether the API token's owner can edit the folder.",
+ "workspace": "Reference to the workspace the folder belongs to.",
+ },
+ },
}
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 3fc1753988ff..ad4161f5b76f 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
@@ -25,13 +25,22 @@ def _cursor_paginator() -> JSONResponseCursorPaginator:
return JSONResponseCursorPaginator(cursor_path="nextPageToken", cursor_param="pageToken")
-def _rename(renames: dict[str, str]) -> Callable[[dict[str, Any]], dict[str, Any]]:
- # include_from_parent names carried fields `_<parent>_<field>`; rename them back to the flat
- # `_doc_id` / `_table_id` keys the composite primary keys and downstream schema expect.
+def _map_row(
+ renames: dict[str, str] | None = None,
+ lift_ids: dict[str, str] | None = None,
+) -> Callable[[dict[str, Any]], dict[str, Any]]:
+ # `renames`: include_from_parent carries fields as `_<parent>_<field>`; rename them back to the
+ # flat `_doc_id` / `_table_id` keys the composite primary keys and downstream schema expect.
+ # `lift_ids`: analytics items nest their subject under `doc` / `page`; lift that object's id to a
+ # top-level column so it can serve as a merge primary key.
def _mapper(row: dict[str, Any]) -> dict[str, Any]:
- for src, dst in renames.items():
+ for src, dst in (renames or {}).items():
if src in row:
row[dst] = row.pop(src)
+ for nested_key, dst in (lift_ids or {}).items():
+ nested = row.get(nested_key)
+ if isinstance(nested, dict) and "id" in nested:
+ row[dst] = nested["id"]
return row
return _mapper
@@ -64,7 +73,7 @@ def _tables_resource() -> EndpointResource:
# Carry the parent doc id into every table row so ids that are only unique within a doc
# get a composite primary key.
"include_from_parent": ["id"],
- "data_map": _rename({"_docs_id": "_doc_id"}),
+ "data_map": _map_row(renames={"_docs_id": "_doc_id"}),
}
@@ -86,19 +95,92 @@ def _rows_resource() -> EndpointResource:
"paginator": _cursor_paginator(),
},
"include_from_parent": ["_doc_id", "id"],
- "data_map": _rename({"_tables__doc_id": "_doc_id", "_tables_id": "_table_id"}),
+ "data_map": _map_row(renames={"_tables__doc_id": "_doc_id", "_tables_id": "_table_id"}),
+ }
+
+
+def _columns_resource() -> EndpointResource:
+ return {
+ "name": "columns",
+ "endpoint": {
+ "path": "/docs/{doc_id}/tables/{table_id}/columns",
+ "params": {
+ # Both path params bind fields of the same parent table row (doc_id is carried in
+ # from the tables resource via include_from_parent above).
+ "doc_id": {"type": "resolve", "resource": "tables", "field": "_doc_id"},
+ "table_id": {"type": "resolve", "resource": "tables", "field": "id"},
+ "limit": PAGE_SIZE,
+ },
+ "data_selector": "items",
+ "paginator": _cursor_paginator(),
+ },
+ "include_from_parent": ["_doc_id", "id"],
+ "data_map": _map_row(renames={"_tables__doc_id": "_doc_id", "_tables_id": "_table_id"}),
+ }
+
+
+def _doc_analytics_resource() -> EndpointResource:
+ return {
+ "name": "doc_analytics",
+ "endpoint": {
+ "path": "/analytics/docs",
+ "params": {"limit": PAGE_SIZE},
+ "data_selector": "items",
+ "paginator": _cursor_paginator(),
+ },
+ # Each item nests the doc under `doc`; lift its id so it can key the merge.
+ "data_map": _map_row(lift_ids={"doc": "doc_id"}),
+ }
+
+
+def _page_analytics_resource() -> EndpointResource:
+ return {
+ "name": "page_analytics",
+ "endpoint": {
+ "path": "/analytics/docs/{doc_id}/pages",
+ "params": {
+ "doc_id": {"type": "resolve", "resource": "docs", "field": "id"},
+ "limit": PAGE_SIZE,
+ },
+ "data_selector": "items",
+ "paginator": _cursor_paginator(),
+ },
+ # Carry the parent doc id, and lift the nested page id, so each row has a composite key.
+ "include_from_parent": ["id"],
+ "data_map": _map_row(renames={"_docs_id": "_doc_id"}, lift_ids={"page": "page_id"}),
+ }
+
+
+def _folders_resource() -> EndpointResource:
+ return {
+ "name": "folders",
+ "endpoint": {
+ "path": "/folders",
+ "params": {"limit": PAGE_SIZE},
+ "data_selector": "items",
+ "paginator": _cursor_paginator(),
+ },
}
def _resource_chain(endpoint: str) -> list[EndpointResource]:
- # Rows fan out docs → tables → rows; 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.
+ # Rows and columns fan out docs → tables → …; page analytics fans out docs → pages. 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":
return [_docs_resource()]
if endpoint == "tables":
return [_docs_resource(), _tables_resource()]
if endpoint == "rows":
return [_docs_resource(), _tables_resource(), _rows_resource()]
+ if endpoint == "columns":
+ return [_docs_resource(), _tables_resource(), _columns_resource()]
+ if endpoint == "doc_analytics":
+ return [_doc_analytics_resource()]
+ if endpoint == "page_analytics":
+ return [_docs_resource(), _page_analytics_resource()]
+ if endpoint == "folders":
+ return [_folders_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 7d1ddee17c00..b21bd91604f4 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
@@ -8,8 +8,8 @@ class CodaEndpointConfig:
# Coda's list endpoints have no updated-since filters (rows only sort), so
-# every stream is a full refresh. Rows fan out docs → tables → rows; ids are
-# only unique within their parent, hence the composite keys.
+# every stream is a full refresh. Rows and columns fan out docs → tables → …;
+# ids are only unique within their parent, hence the composite keys.
CODA_ENDPOINTS: dict[str, CodaEndpointConfig] = {
"docs": CodaEndpointConfig(
name="docs",
@@ -22,6 +22,23 @@ CODA_ENDPOINTS: dict[str, CodaEndpointConfig] = {
name="rows",
primary_keys=["_doc_id", "_table_id", "id"],
),
+ "columns": CodaEndpointConfig(
+ name="columns",
+ primary_keys=["_doc_id", "_table_id", "id"],
+ ),
+ # Doc analytics returns one item per doc; the doc id is nested under `doc`, lifted to `doc_id`.
+ "doc_analytics": CodaEndpointConfig(
+ name="doc_analytics",
+ primary_keys=["doc_id"],
+ ),
+ # Page analytics fans out over docs; the page id is nested under `page`, lifted to `page_id`.
+ "page_analytics": CodaEndpointConfig(
+ name="page_analytics",
+ primary_keys=["_doc_id", "page_id"],
+ ),
+ "folders": CodaEndpointConfig(
+ name="folders",
+ ),
}
ENDPOINTS = tuple(CODA_ENDPOINTS.keys())
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 cd81289f1160..d93b5d850a5b 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
@@ -130,6 +130,61 @@ class TestGetRows:
assert parsed.path == "/apis/v1/docs/doc1/tables/grid-1/rows"
assert requests[2]["params"]["useColumnNames"] == "true"
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_columns_fan_out_docs_tables_columns(self, MockSession):
+ requests = _wire(
+ MockSession.return_value,
+ [
+ _response([{"id": "doc1"}]), # docs
+ _response([{"id": "grid-1"}]), # tables for doc1
+ _response([{"id": "c-1", "name": "Name"}]), # columns for grid-1
+ ],
+ )
+
+ rows = _rows("columns")
+
+ assert [(c["id"], c["_doc_id"], c["_table_id"]) for c in rows] == [("c-1", "doc1", "grid-1")]
+ assert urlparse(requests[2]["url"]).path == "/apis/v1/docs/doc1/tables/grid-1/columns"
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_doc_analytics_lifts_nested_doc_id(self, MockSession):
+ requests = _wire(
+ MockSession.return_value,
+ [_response([{"doc": {"id": "doc1", "title": "Roadmap"}, "metrics": [{"date": "2026-01-01", "views": 5}]}])],
+ )
+
+ rows = _rows("doc_analytics")
+
+ # The doc id is nested under `doc`; it must surface as a top-level `doc_id` to key the merge.
+ assert rows[0]["doc_id"] == "doc1"
+ assert rows[0]["metrics"][0]["views"] == 5
+ assert urlparse(requests[0]["url"]).path == "/apis/v1/analytics/docs"
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_page_analytics_fan_out_and_lifts_page_id(self, MockSession):
+ requests = _wire(
+ MockSession.return_value,
+ [
+ _response([{"id": "doc1"}]), # docs
+ _response([{"page": {"id": "page-1", "name": "Launch"}, "metrics": [{"views": 3}]}]), # pages for doc1
+ ],
+ )
+
+ rows = _rows("page_analytics")
+
+ assert [(p["page_id"], p["_doc_id"]) for p in rows] == [("page-1", "doc1")]
+ assert urlparse(requests[1]["url"]).path == "/apis/v1/analytics/docs/doc1/pages"
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_folders_is_a_top_level_endpoint(self, MockSession):
+ requests = _wire(MockSession.return_value, [_response([{"id": "folder-1", "name": "Team"}])])
+
+ rows = _rows("folders")
+
+ # Folders has no parent, so a single request against /folders yields its rows directly.
+ assert [f["id"] for f in rows] == ["folder-1"]
+ assert urlparse(requests[0]["url"]).path == "/apis/v1/folders"
+
@mock.patch(CLIENT_SESSION_PATCH)
def test_table_without_id_fails_fast_in_rows(self, MockSession):
_wire(