はじめに
hkob の雑記録の第447回目(通算21日目)からは、Retrieve view を実装していきます。ただ、かなり新しい項目なので、まずは JSON を取得してどのように実装していくかを検討していきます。
テスト用データベースの作成
View API test のためにデータベースを一つ作成しました。

今回のテストのために全てのView を作成しておきました。今回は一番上の TableView について実装を進めていきます。

まず、View のリンクを取得します。

URL はこのような形になっています。
https://www.notion.so/hkob/32fd8e4e98ab80e7a807f8fbbf48612d?v=32fd8e4e98ab81e88ba9000c227aaf76&source=copy_link
今回の View の id は後半の ?v= の後ろの部分(32fd8e4e98ab81e88ba9000c227aaf76)になります。
Table View の取得スクリプト
まずはこれまでの page などと同様にスクリプトを作成します。v1/views になっていること、その後ろが view_id になっているだけの違いです。
curl 'https://api.notion.com/v1/views/32fd8e4e98ab81e88ba9000c227aaf76' \ -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \ -H 'Notion-Version: 2026-03-11'
いつものように make すると対応する json が作成されます。
touch *.json; make sh retrieve_view_table_view.sh > retrieve_view_table_view.json % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 3103 0 3103 0 0 6486 0 --:--:-- --:--:-- --:--:-- 6491 sleep 1
取得した JSON は以下のようになります。
{ "object": "view", "id": "32fd8e4e-98ab-81e8-8ba9-000c227aaf76", "parent": { "type": "database_id", "database_id": "32fd8e4e-98ab-80e7-a807-f8fbbf48612d" }, "data_source_id": "32fd8e4e-98ab-8166-98e8-000b4292b61f", "name": "TableView", "type": "table", "created_time": "2026-01-11T09:33:52.487+00:00", "created_by": { "object": "user", "id": "2200a911-6a96-44bb-bd38-6bfb1e01b9f6" }, "last_edited_time": "2026-03-26T11:35:32.942+00:00", "last_edited_by": { "object": "user", "id": "2200a911-6a96-44bb-bd38-6bfb1e01b9f6" }, "url": "https://www.notion.so/32fd8e4e98ab80e7a807f8fbbf48612d?v=32fd8e4e98ab81e88ba9000c227aaf76", "filter": null, "sorts": null, "quick_filters": null, "configuration": { "type": "table", "properties": [ { "property_id": "title", "property_name": "Title", "visible": true, "width": 129 }, { "property_id": "flUp", "property_name": "TextTitle", "visible": true, "width": 100 }, { "property_id": "swq\\", "property_name": "NumberTitle", "visible": true, "width": 100 }, { "property_id": "zE|?", "property_name": "SelectTitle", "visible": true, "width": 100 }, { "property_id": "Kjx}", "property_name": "MultiSelectTitle", "visible": true, "width": 129 }, { "property_id": "SPrp", "property_name": "DateTitle", "visible": true, "width": 200 }, { "property_id": "_x>=", "property_name": "UserTitle", "visible": true, "width": 200 }, { "property_id": "qEdK", "property_name": "File&MediaTitle", "visible": true, "width": 122 }, { "property_id": "Lbi]", "property_name": "CheckboxTitle", "visible": true, "width": 35 }, { "property_id": "tvis", "property_name": "UrlTitle", "visible": true, "width": 212 }, { "property_id": "p|i?", "property_name": "MailTitle", "visible": true, "width": 166 }, { "property_id": "|NHO", "property_name": "TelTitle", "visible": true, "width": 105 }, { "property_id": "WsEj", "property_name": "CreatedTimeTitle", "visible": true, "width": 194 }, { "property_id": "eR=~", "property_name": "CreatedByTitle", "visible": true, "width": 184 }, { "property_id": "X>@X", "property_name": "LastEditedTimeTitle", "visible": true, "width": 184 }, { "property_id": "LQGa", "property_name": "LastEditedByTitle", "visible": true, "width": 181 }, { "property_id": "]~iZ", "property_name": "FormulaTitle", "visible": true, "width": 188 }, { "property_id": "<nJT", "property_name": "RelationTitle", "visible": true, "width": 126 }, { "property_id": "STe_", "property_name": "RollupTitle", "visible": true, "width": 200 }, { "property_id": "MNV~", "property_name": "StatusTitle", "visible": true, "width": 200 }, { "property_id": "{GE|", "property_name": "IDTitle", "visible": true, "width": 200 }, { "property_id": "Uw=a", "property_name": "PositionTitle", "visible": true, "width": 200 }, { "property_id": "verification", "property_name": "VerificationTitle", "visible": true, "width": 200 }, { "property_id": "verification_owner", "property_name": "OwnerTitle", "visible": true, "width": 200 }, { "property_id": "ZifK", "property_name": "BlockedByTitle", "visible": true, "width": 200 }, { "property_id": "Gx?d", "property_name": "BlockingTitle", "visible": true, "width": 200 }, { "property_id": "AVX=", "property_name": "SubItemTitle", "visible": true, "width": 200 }, { "property_id": "IFyg", "property_name": "ParentTitle", "visible": true, "width": 200 } ], "subtasks": { "filter_scope": "parents" }, "wrap_cells": true, "frozen_column_index": -1 }, "request_id": "a7c4f75f-a367-47a8-9cda-c4bb8f81a7c0" }
JSON の解読
View のデータ構造はこちらに記載されています。
Key fields については以下のように記載されています。今回の Table view に関するところを見てみます。

filter と sorts
ここは、DataSource の Query に使う filter と sort パラメータと同様とのことです。NotionRubyMapping では Query データベースがうまく再利用できると思われます。
quick_filters
リンク先に示されていますが、property field を使わずに簡易的に設定するフィルタになります。NotionRubyMapping では QuickFilter というオブジェクトを新規に作成してみたいと思います。
configuration
この部分は View ごとに異なる設定になります。Table view の場合はこちらに記載してあります。
Field keys はこのようになります。中に Property configuration, Group-by configuration, Subtask configuration が内包されています。

Property configuraton
Property configuration は以下のように定義されています。Table view だと width が設定できるのですね。

Group-by configuraton
同じように Group-by configuration は以下のように定義されています。

さらに extra field も存在するようです。

さらに、Formula に対する group-by の場合には、ネストされた group_by オブジェクトが使われます。

Subtask configuraton
最後に Subtask configuration は以下のように定義されています。

おわりに
こうみてみると View class の前に実装していくべき Object が多数ありそうです。作戦を練りながら少しずつ実装していきます。