iTranslated by AI
Automating Notion Page Creation with Python and Slack Notifications
When working in a team or on projects, I imagine you have regular meetings. Do you ever forget to create a meeting minutes template or post the agenda for team members in advance? I do that quite often. Routine tasks that humans tend to forget are perfect for automation. With that in mind, I decided to automate the creation of meeting minutes using Python and the Notion API. The source code is provided in the latter half of this post. If you don't need the explanations and just want the source code, please scroll down to the second half.
Obtaining the Notion API (Preparation)
To use the Notion API, you need to apply via the following page:
API Application Page
Clicking "Create new Integration" allows you to use the API.

Since the application process is explained clearly in GIF format, you should be able to obtain an API key without any trouble. The Internal Integration Token corresponds to your API key. Keep it safe, as leaking it poses a serious security risk.
When creating a page in Notion, it is common to add pages to a table (or database), so we will implement it using that method. Don't forget that you need to add your created token to the page.

Implementing Page Creation
Let's get straight into implementing the page creation. For this test, we will implement it assuming we are adding pages to the database shown below.

Table Structure
| Column Name | Type | Role |
|---|---|---|
| Name | Title | Enter page name |
| Tags | Multi-select | Enter page tags |
| detail | Text | Description of the page |
| Created at | Created time | Creation date |
| Last edited at | Last edited time | Last modified date |
| Created by | Created by | Creator |
This is a standard table structure often used for meeting minutes. The column types mentioned above need to be specified when requesting via the API, which can be seen by clicking on the Notion table column names.
Implementing Page Creation (Python)
According to the official documentation, you can create a page by providing information in JSON format according to the rules. Three elements are required to create a page using the Notion API:
- url
- Declare the API URL to use.
url = 'https://api.notion.com/v1/pages'
- headers
- Header information for the request.
headers = {
"Accept": "application/json",
"Notion-Version": "2022-06-28",
"Content-Type": "application/json",
"Authorization": "Bearer " + api_key
}
- payload
- Page information written in JSON format.
- Specify the ID of the database where you want to create the page in parent.
- You can get the database ID from the URL. It corresponds to the {database_id} part of the URL structure when you open the target page in full-screen mode.
-
https://www.notion.so/{workspace_name}/{database_id}?v={view_id}
Click here for the official documentation
- Page settings information is specified in properties.
- The content you want to include in the page is specified in children.
Following the rules above, the implementation looks like this:
payload = {
"parent": {
"database_id": data_base_id
},
"properties": {
"Name": {
"title": [
{
"text": {
"content": title_today
}
}
],
},
"Tags":{
"multi_select":[
{
"name":tag_name
}
]
},
"detail": {
"rich_text": [
{
"text": {
"content": detail_text
}
}
],
},
"date": {
"date": {
"start": created_iso_format
}
},
}
"children":[
{
"object": 'block',
"type": 'heading_1',
"heading_1":{
"rich_text": [
{
"text": {
"content": "Today's Topics!!!"
}
}
],
}
},
],}
If you correlate the properties and children info above with the actual Notion screen, it looks like the following structure:

If you want to add or edit columns in the table, modify the properties; if you want to add blocks inside the page, you can append them to the children array.
Implementation Example
I created the final implementation for page creation in Notion as follows. I also added Slack notifications as a bonus.
import requests
import json
import datetime
today = datetime.date.today()
title = "Team_MTG_Minutes_"
title_today = title+ str(today)
created_iso_format = today.isoformat()
api_key = "Enter your obtained API Key here"
data_base_id = 'Enter your Database ID here'
emoji = "🤠"
tag_name = "Weekly Sync"
detail_text = "Team regular meeting"
slack_webhook_url ="Slack webhook url"
url = 'https://api.notion.com/v1/pages'
headers = {
"Accept": "application/json",
"Notion-Version": "2022-06-28",
"Content-Type": "application/json",
"Authorization": "Bearer " + api_key
}
payload = {
"parent": {
"database_id": data_base_id
},
"icon":{
"emoji": emoji
},
"properties": {
"Name": {
"title": [
{
"text": {
"content": title_today
}
}
],
},
"Tags":{
"multi_select":[
{
"name":tag_name
}
]
},
"detail": {
"rich_text": [
{
"text": {
"content": detail_text
}
}
],
},
"date": {
"date": {
"start": created_iso_format
}
},
},
"children":[
{
"object": 'block',
"type": 'heading_1',
"heading_1":{
"rich_text": [
{
"text": {
"content": "Today's Topics!!!"
}
}
],
}
},
{
"object": 'block',
"type": 'heading_2',
"heading_2":{
"rich_text": [
{
"text": {
"content": "Agenda"
}
}
],
}
},
{
"object": 'block',
"type": 'heading_2',
"heading_2":{
"rich_text": [
{
"text": {
"content": "Action Items"
}
}
],
}
},
{
"object": 'block',
"type": 'to_do',
"to_do":{
"rich_text": [
{
"text": {
"content": "ToDo 1"
}
}
],
"checked": False,
"color": "default",
}
}
],
}
response = requests.post(url, json=payload, headers=headers)
result_dict = response.json()
result = result_dict["object"]
page_url = result_dict["url"]
if result == "page":
print("success")
requests.post(slack_webhook_url, data=json.dumps({
# Message content
"text" : "Today's meeting minutes have been created!! Everyone, please fill in the topics!! \n " + page_url,
}))
elif result == "error":
requests.post(slack_webhook_url, data=json.dumps({
# Message content
"text" : "It seems like an error occurred! Really sorry!! Please create the minutes manually!! \n " + page_url,
}))
else:
requests.post(slack_webhook_url, data=json.dumps({
# Message content
"text" : "An exception occurred, lol. Not sure what happened. Please just create the minutes manually. Sorry about that.. \n " + page_url,
}))
If you run the above code, page creation should work without issues. To make it look more like meeting minutes, I added checkboxes for ToDos, so let's take action.
If an error occurs, suspect that the column names and properties specification might be mismatched, or that the API Key/Database ID settings are incorrect.
For Slack notifications, I have customized the message based on the result of the creation process.
Conclusion
It was my first time using the Notion API, but it was extremely convenient to be able to quickly automate tasks that I tend to forget. If you run this implementation at a set frequency (like once a week), you can nicely automate the creation of regular meeting notes. I used Cloud Functions and Cloud Scheduler to automate this.
In the future, it gets boring if the emoji is always the same, so I'd like to try changing it randomly.
For details on how to write other Notion blocks, please refer to the official documentation.
References
Discussion