Share This Post

Notion API

Start building with the Notion API

開始之前

Step 1: 建立整合

  1. 到 https://www.notion.com/my-integrations
  2. 點擊 + New integration 或 + Create new integration Untitled
  3. 設定integration 完成後點擊Submit
  4. 看到這個畫面 表示密鑰成功產生了 Untitled

Step 2: 工作區和整合連接

  1. 點擊工作區右上角的 •••
  2. 滑動到Add connections 輸入建立的Integration名稱並選取 Untitled

開始用API

URL格式

  • 沒有資料庫 <https://www.notion.so/{workspace_name}-{page_id}>
  • 有資料庫 <https://www.notion.so/{database_id}?v={view_id}>

新增Block

 POST 
<https://api.notion.com/v1/blocks/{page_id}/children>
  • header添加
KeyValue
AuthorizationIntegration的密鑰
Notion-Version2022-06-28
  • data格式
{
	"children": [
		{
			"object": "block", // 物件類別
			"type": "heading_2", // 物件型態
			"heading_2": { // 物件屬性
				"rich_text": [{ "type": "text", "text": { "content": "Lacinato kale" } }]
			}
		},
		{
			"object": "block",
			"type": "paragraph",
			"paragraph": {
				"rich_text": [
					{
						"type": "text",
						"text": {
							"content": "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.",
							"link": { "url": "<https://en.wikipedia.org/wiki/Lacinato_kale>" }
						}
					}
				]
			}
		}
	]
}

<aside> 💡 type值可為: "paragraph""heading_1""heading_2""heading_3""bulleted_list_item""numbered_list_item""to_do""toggle""child_page","child_database", "embed""image""video""file""pdf""bookmark""callout""quote""equation""divider""table_of_contents""column""column_list", "link_preview""synced_block""template""link_to_page""table", "table_row",  "unsupported" 詳閱:https://developers.notion.com/reference/block

</aside>

新增Database

 POST 
<https://api.notion.com/v1/databases>
  • header添加
KeyValue
AuthorizationIntegration的密鑰
Notion-Version2022-06-28
  • data格式
{
    "parent": {
        "type": "page_id",
        "page_id": "{{page_id}}"
    },
    "is_inline": true, 
    "title": [ // 定義資料庫Title
        {
            "text": {
                "content": "EJ's code"
            }
        }
    ],
    "properties": { // 定義資料庫欄位
        "Title": { // 欄位名稱
            "title": {} // 欄位屬性
        },
        "Difficulty": { // 欄位名稱
            "select": { // 欄位屬性
                "options": [
                    {
                        "name": "Easy",
                        "color": "green"
                    },
                    {
                        "name": "Medium",
                        "color": "yellow"
                    },
                    {
                        "name": "Hard",
                        "color": "red"
                    }
                ]
            }
        },
        "EJ's date": { // 欄位名稱
            "date": {} // 欄位屬性
        },
        "User1's date": {
            "date": {}
        },
        "User2's date": {
            "date": {}
        },
        "Completed": {
            "people": {}
        },
        "Link": {
            "url": {}
        }
    }
}

新增Page

 POST 
<https://api.notion.com/v1/pages> 
  • header添加
KeyValue
AuthorizationIntegration的密鑰
Notion-VersionNotion-Version
  • data格式
{
    "parent": {
        "database_id": "{database_id}"
    },
    "properties": { // 定義Page屬性
        "Title": {
            "title": [
                {
                    "text": {
                        "content": "TEST"
                    }
                }
            ]
        },
        "Difficulty": {
            "multi_select": [
                {
                    "name": "TEST"
                }
            ]
        },
        "Link": {
            "url": "TEST"
        }
    },
    "children": [ // 定義Page內容
		{
			"object": "block",
			"type": "heading_2",
			"heading_2": {
				"rich_text": [{ "type": "text", "text": { "content": "Lacinato kale" } }]
			}
		},
		{
			"object": "block",
			"type": "paragraph",
			"paragraph": {
				"rich_text": [
					{
						"type": "text",
						"text": {
							"content": "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.",
							"link": { "url": "<https://en.wikipedia.org/wiki/Lacinato_kale>" }
						}
					}
				]
			}
		}
	]
}
Untitled

更新Page

 PATCH 
<https://api.notion.com/v1/pages/{page_id}>
  • header添加
KeyValue
AuthorizationIntegration的密鑰
Notion-Version2022-06-28
  • data格式
{
    "properties": {
        "EJ's date": {
            "date": {
                "start": "2023-02-05"
            }
        },
        "Completed": {
            "people": [
                {
                    "id": "1a1e8d57-a450-4dcf-abdb-e6384415bd37",
                    "name": "EJ",
                    "type": "person",
                    "person": {
                        "email": "k0970133227@gmail.com"
                    }
                }
            ]
        }
    }
}

EJ’s code

訂閱研究文章

Get updates and learn from the best

More To Explore

Scroll to Top

hurry up !

軟體工程師培訓

限時免費報名中

藉由與「真實世界軟體專案」相同的技術、工具與開發流程,化簡成與商業機密無關、門檻較低更容易上手的「模擬專案」,讓你有機會在職場前輩的陪伴下,完成真槍實彈的練習,動手解決真實的問題,快速累積個人的經驗與作品,而不只是「學習技術」而已。