Notion API <발표자: 김정연>
<목차>
1.기존의 방식의 단점 → 이걸 왜 쓰는지 큰그림(아키텍처 느낌)
2.Notion API가 뭔지?
3.Notion API 로 가능한 일
4.간단한 데모
5.한계점
유비쿼터스 = 사용자가 컴퓨터나 네트워크를 의식하지 않고 장소에 상관없이 자유롭게 네트워크에 접할 수 있는 환경


→ 노션의 한계를 넘고 구글 캘린더의 장점을 합치기 위한 연동 필요
But, 기존의 연동 방법 = 노션에 구글캘린더를 임베드 하는 방식
<기존 연동 방식의 단점>
⇒ 단순히 노션에서 구글캘린더를 보는 정도의 연동 수준
⇒ Notion API를 사용하여 자동화 시킬 경우 쌍방향 동기화가 가능!!

따라서, Notion API 기능을 사용하여
다른 앱과 자동으로 업데이트하고, 작업을 수행, 정보의 일관성을 유지
→ 효율적으로 작업 진행!
Notion API 사용 → 노션을 코드로 접근해서 CMS 혹은 데이터베이스로 활용 가능
1) OAuth로 타사 플랫폼에서 직접 통합( 다른 앱과 정보 교환)
2) Automate actions (작업을 자동화)
API에서 사용되는 각 엔드포인트 및 객체 유형에 대한 정보는 Notion 개발자 Reference 문서를 통해 찾을 수 있습니다. https://developers.notion.com/reference/intro
[Grocery Test Database]

{
"object": "database",
"properties": {
"Grocery item": {
"id": "fy:{",
"type": "title",
"title": {} -> Title(제목) : DB에서 title 타입을 가진 단 하나의 속성
},
"Price": {
"id": "dia[",
"type": "number",
"number": {
"format": "dollar" -> number 특정 속성에 추가 구성 가능
}
},
"Last ordered": {
"id": "]\\R[",
"type": "date",
"date": {}
},
}
// remaining details omitted
}
curl -X POST https://api.notion.com/v1/pages \
-H 'Authorization: secret_Jueo9fvwkT7EuuMpa5qwubYzI0vsBJM2taTIW7PpVoU' \
-H "Content-Type: application/json" \
-H "Notion-Version: 2022-06-28" \
--data '{
"parent": { "type": "database_id", "database_id": "da3e736306e4495b99dcc51971274d3a"},
"properties": {
"Grocery item": {
"type": "title",
"title": [{ "type": "text", "text": { "content": "방울토마토" } }]
},
"Price": {
"type": "number",
"number": 1.49
},
"Last ordered": {
"type": "date",
"date": { "start": "2022-08-09" }
}
}
}'

새로운 방울토마토 페이지 생성 확인

Notion DB와 상호 작용하려면 Notion 통합을 생성하고 API 시크릿 토큰 정보 필요

from notion.client import NotionClient
from notion.block import TodoBlock, PageBlock, TextBlock, CodeBlock, VideoBlock
import warnings
warnings.filterwarnings(action='ignore')
# Obtain the `token_v2` value by inspecting your browser cookies on a logged-in (non-guest) session on Notion.so
client = NotionClient(token_v2="9e1277377147e8156ee3cd5320ff15382ed7f06acf52603306bc82179a0dd869cdf9c48d33c37fba73f18c0de2912bf1341ce2299bf7898c80fff02892dbae64a38d8b9d8f6b00237b7677e9603f") #시크릿 토큰 값
# Replace this URL with the URL of the page you want to edit
page = client.get_block("https://www.notion.so/Hello-Notion-Task-39928068200848a4bfb4b8f827098bbe") #notion page url
print("페이지 제목 확인: ", page.title)
answer = "예"
text = page.children.add_new(TextBlock)
text.title = "파이썬 API VideoBlock 활용 참고 영상 자동 추가 반복하기"
while answer =="예":
video = page.children.add_new(VideoBlock) #VideoBlock 추가
video.width = 200
video.height = 300
input_url = input("추가 할 비디오의 URL 주소를 입력하세요.")
video.set_source_url(input_url)
answer = input("추가로 비디오 블록을 생성할건가요?")
print("자동 완성 완료")

속도 제한
노션 API는 초당 3개의 요청만을 처리할 수 있다.
따라서 프로젝트 규모가 커질 경우 API 앞에 캐싱 레이어를 추가하는 것을 고려해야 할 경우 발생 가능 (+보류 중인 요청에 대해 여러 개의 큐 사용하는 방법)
크기 제한
특정 매개변수의 크기와 요청의 하위 깊이 제한
각 속성에 대한 Size Limit는 공식 문서 참고 https://developers.notion.com/reference/request-limits
⇒ 앞으로 수요와 안정성의 균형을 위해 조정할 계획