type
status
slug
tags
category
icon
password
Property
Nov 15, 2022 02:50 PM
date
summary
0x01 前言
本来就很喜欢使用Notion,包括本Blog也是使用Notion来搭建,最近因为想把json的东西存到Notion中,于是就想到了使用notion的api来操作,这里就简单记录一下怎么使用吧!
0x02步骤
创建一个Api机器人 https://www.notion.com/my-integrations
记住页面生成的Token

将网页上面创建api机器人添加到对应需要操作的页面

这是我要操作的测试Database 点击右上角分享按钮记住该DatabaseId

获取Database详情
成功获取database详情 ,这里会有对应的列名如name,number,info

然后就是使用对应列名插入新的page
这边建议的是先手工添加一条page ,然后获取page的详情,再按照对应格式添加page确保没有格式错误。
我这里添加了一条page,然后打开一样的点击分享按钮获取对应page 的Id

获取page详情
获取回来的数据
其实我们只要提取上面json中parent和properties部分内容就好了
然后就是构建需要插入内容
我这脚本是需要python写的为了避免错误我这里将false替换成False,null替换None
新增page
添加成功😄

0x03总结
使用api操作的话这样就可以时间脚本自动化操作notion的数据库了,这里只是简单介绍了一些用法,还有更多的可以参考官方的api文档。自由化程度如此之高可能这也是notion强大的原因
官方api文档