20210519

Created: May 19, 2021 8:00 AM

It is never too late to be what you might have been.

Notion API

使用Notion自动创建每天页面

  1. 创建Notion机器人

Notion - The all-in-one workspace for your notes, tasks, wikis, and databases.

createnotionintertaion.gif

  1. 将需要自动创建页面的Notion workspace分享给Notion机器人

sharetointegration-robot.gif

  1. 获取页面的DatabaseID

  2. 通过分享链接获取

    https://www.notion.so/485bb239e154448a85bfe8f262eaccac?v=11ef1ae0a3ba472a9c5165223b8697c3 则 DatabaseID为485bb239-e154-448a-85bf-e8f262eaccac

sharetointegration.gif

  1. 通过API查询
# $NOTION_API_KEY为第一步创建Notion的secret
curl 'https://api.notion.com/v1/databases'    -H 'Authorization: Bearer '"$NOTION_API_KEY"''    -H 'Notion-Version: 2021-05-13'
  1. 准备创建的数据
 {
    "parent": { "database_id": "485bb239-e154-448a-85bf-e8f262eaccac" },
    "properties": {
        "title": {
      "title": [{ "type": "text", "text": { "content": "'"${create_date}"'"} }]
        }
    },
    "children": [
    {
      "object": "block",
      "type": "paragraph",
      "paragraph": {
        "text": [{ "type": "text", "text": { "content": "It is never too late to be what you might have been." } }]
      }
    }
  ]
}
  1. 发送请求,创建数据
curl -X POST https://api.notion.com/v1/pages \
  -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \
  -H "Content-Type: application/json" \
  -H "Notion-Version: 2021-05-13" \
  --data '{
    "parent": { "database_id": "485bb239-e154-448a-85bf-e8f262eaccac" },
    "properties": {
        "title": {
      "title": [{ "type": "text", "text": { "content": "'"${create_date}"'"} }]
        }
    },
    "children": [
    {
      "object": "block",
      "type": "paragraph",
      "paragraph": {
        "text": [{ "type": "text", "text": { "content": "It is never too late to be what you might have been." } }]
      }
    }
  ]
}'

6 创建定时任务

0 8 * * * cd /data/ && sh notion.sh
  1. 问题难点

  2. DatabaseID 只有为database类型的才有databaseid
  3. 通过api查询databaseid 有时候会查询不到,所以还是建议通过share链接 获取databaseid