HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
執筆中ページ/
📕
「Notion API 活用術」テンプレート
/
3️⃣
S16. 作成 (Create)
3️⃣

S16. 作成 (Create)

16.1 子ブロックを追加 (Append block children)

  • 既存のブロックまたはページに子ブロックを追加する API の説明はこちらです。
    • Start building with the Notion API
      Creates and appends new children blocks to the parent block_id specified. Returns a paginated list of newly created first level children block objects. Errors Returns a 404 HTTP response if the block specified by id doesn't exist, or if the integration doesn't have access to the block. Returns a 400...
      Start building with the Notion API
      https://developers.notion.com/reference/patch-block-children
      Start building with the Notion API
💡
子ブロック追加用ブロック
  • この子ブロックの URL を取得してここに貼り付けてください。
    • 📝
      ブロック URL
      例:
      https://www.notion.so/hkob/S16-Create-b50e0bac66a04c549eb68f6aa0fc822a#4f3c3bf99fa544be9970b150696f4290
  • block_id は末尾の # の後ろの 32 桁の 16 進数です。下の赤字の部分にこの block_id を記述してください。ヘッダ部分はこれまでの のものと変更はありません。
    • https://api.notion.com/v1/blocks/ここに上のblock_idを記述/children
      SCHEME
  • ColumnList ブロックの書式はかなり複雑なので、NotionRubyMapping で作成してみます。
    • print JSON.pretty_generate(ColumnListBlock.new([ EquationBlock.new('\fbox{fbox}'), EquationBlock.new('\mathbb{MATHBB}'), ]).block_json) { "type": "column_list", "object": "block", "column_list": { "children": [ { "type": "column", "object": "block", "column": { "children": [ { "type": "equation", "object": "block", "equation": { "expression": "\\fbox{fbox}" } } ] } }, { "type": "column", "object": "block", "column": { "children": [ { "type": "equation", "object": "block", "equation": { "expression": "\\mathbb{MATHBB}" } } ] } } ] } }=> nil
      ColumnList block の JSON 記述を得る
  • Append block children の BODY は children キー配列の中に Property value object を並べます。
    • { "children": [ { "type": "column_list", "object": "block", "column_list": { "children": [ { "type": "column", "object": "block", "column": { "children": [ { "type": "equation", "object": "block", "equation": { "expression": "\\fbox{fbox}" } } ] } }, { "type": "column", "object": "block", "column": { "children": [ { "type": "equation", "object": "block", "equation": { "expression": "\\mathbb{MATHBB}" } } ] } } ] } } ] }
  • 設定画面は以下のようになります。
    • notion image

16.2 データベースを作成 (Create a database)

  • 新規にデータベースを作成する API の説明はこちらです。
    • Start building with the Notion API
      Creates and appends new children blocks to the parent block_id specified. Returns a paginated list of newly created first level children block objects. Errors Returns a 404 HTTP response if the block specified by id doesn't exist, or if the integration doesn't have access to the block. Returns a 400...
      Start building with the Notion API
      https://developers.notion.com/reference/patch-block-children
      Start building with the Notion API
この API の SCHEME は以下のように固定です。メソッドは POST に変更になります。
https://api.notion.com/v1/databases
  • データベースはこのページの下に作成してみましょう。このページの URL を取得します。
    • 📝
      ブロック URL
      例: https://www.notion.so/hkob/S16-Create-b50e0bac66a04c549eb68f6aa0fc822a?pvs=4
  • URL から page_id を取り出してください。上の赤字の部分です。
    • 📝
      b50e0bac66a04c549eb68f6aa0fc822a
Title, Checkbox, Formula プロパティを持つデータベースを作成する BODY は以下のようになります。
{ "properties": { "タイトル": { "title": {} }, "完了": { "checkbox": {} }, "現在時刻": { "formula": { "expression": "now()" } } }, "title": [ { "type": "text", "text": { "content": "新規作成データベース" } } ], "parent": { "type": "page_id", "page_id": "この部分に上の page_id を記述してください" } }
Create a database の BODY
  • 結果に書かれている database_id を記録しておいてください。下で使います。
    • 📝
      例: 6d1dfdb1-3b11-4506-ae2f-b5e005ed76d4

16.3 ページを作成 (Create a page)

  • 新規にページを作成する API の説明はこちらです。
    • Start building with the Notion API
      Creates a new page in the specified database or as a child of an existing page. If the parent is a database, the property values of the new page in the properties parameter must conform to the parent database's property schema. If the parent is a page, the only valid property is title.
      Start building with the Notion API
      https://developers.notion.com/reference/post-page
      Start building with the Notion API
  • この API の SCHEME も以下のように固定です。メソッドはこれも POST になります。
    • https://api.notion.com/v1/pages
  • タイトルのみを設定する payload は以下のようになります。BODY は以下のようになります。
    • { "properties": { "タイトル": { "title": [ { "type": "text", "text": { "content": "新規ページ" } } ] } }, "parent": { "type": "database_id", "database_id": "上に記述した database_id を記述してください" } }
設定画面は以下のようになります。
notion image

🔹
この CHAPTER 内の SECTION
S12. API アクセスの種類
12
S13. 個別取得 (Read)
13
S14. 一覧取得 (Read)
14
S15. 更新 (Update)
15
S16. 作成 (Create)
16
S17. 削除 (Delete)
17
🔶
CHAPTER LIST
C1. Notion APIの概要と利用準備
1
C2. Notion APIで理解するNotionのデータ構造
2
C3. Notion APIの基本(CRUD別の紹介)
3
C4. Google Apps Scriptによる応用
4
C5. ショートカットによる応用
5
C6. NotionRubyMappingを利用したツール
6