シンプルテーブルが API でサポートされたということで試してみる。まずは概要から。
概要説明
API でシンプルテーブルのサポートを追加しました。
シンプルテーブルとシンプルテーブルの行
テーブルはテーブルの行を子供に持つ親になっています。テーブルは
table_row
だけを子供に持ちます。Append block children を通じてテーブルブロックを作った場合、
table
は最低でも一つの行( table_row
)を持つ必要があります。また、 table_row
の中の cells
配列は table_length
と同じ長さである必要があります。table
を取得するためには、 table_row
の子供を Retrieve block childrenを使って取得する必要があります。 table
ブロックは以下のようなフォーマットされたデーのみをもち、コンテンツは持ちません。テーブルの例を示します。
{ "type": "table", "table": { "table_width": 3, "has_column_header": false, "has_row_header": false } }
テーブルの行の例を示します。
{ "type": "table_row", "table_row": { "cells": [ [ { "type": "text", "text": { "content": "column 1 content", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, "plain_text": "column 1 content", "href": null } ], [ { "type": "text", "text": { "content": "column 2 content", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, "plain_text": "column 2 content", "href": null } ], [ { "type": "text", "text": { "content": "column 3 content", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, "plain_text": "column 3 content", "href": null } ] ] } }
詳細については、 Block object のドキュメントを読んでください。
検証
いつものように検証しましょう。簡単なので魔法陣でも書いてみましょう。スクリプトはこんな感じです。最低限のテキストだけ設定しています。
curl -X PATCH 'https://api.notion.com/v1/blocks/2b940cbce90848068ad77e91eb17d019/children' \ -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \ -H "Content-Type: application/json" \ -H "Notion-Version: 2021-08-16" \ --data '{ "children": [ { "object": "block", "type": "table", "table": { "table_width": 3, "has_column_header": false, "has_row_header": false, "children": [ { "type": "table_row", "table_row": { "cells": [ [ { "type": "text", "text": { "content": "2" } } ], [ { "type": "text", "text": { "content": "9" } } ], [ { "type": "text", "text": { "content": "4" } } ] ] } }, { "type": "table_row", "table_row": { "cells": [ [ { "type": "text", "text": { "content": "7" } } ], [ { "type": "text", "text": { "content": "5" } } ], [ { "type": "text", "text": { "content": "3" } } ] ] } }, { "type": "table_row", "table_row": { "cells": [ [ { "type": "text", "text": { "content": "6" } } ], [ { "type": "text", "text": { "content": "1" } } ], [ { "type": "text", "text": { "content": "8" } } ] ] } } ] } } ] }'
戻ってきた JSON はこちら
{ "object": "list", "results": [ { "object": "block", "id": "1a9a5f22-4a88-4e3f-b7bf-ed2701d63f59", "created_time": "2022-01-06T22:54:00.000Z", "last_edited_time": "2022-01-06T22:54:00.000Z", "has_children": true, "archived": false, "type": "table", "table": { "table_width": 3, "has_column_header": false, "has_row_header": false } } ], "next_cursor": null, "has_more": false }
実行結果
上のスクリプトでこんな感じの魔法陣が描けました。
2 | 9 | 4 |
7 | 5 | 3 |
6 | 1 | 8 |
Notion API Changelog まとめ