たいやばなな

20代後半SE?SI?な自称エンジニアの日々の気づきや、試したことを種種雑多に雑記します。

【祝公式ベータ公開】Notion の API について調べてみた・Quick Startのエラー

今回は最近私の中で盛り上がっているNotionです🔥🔥🔥

APIについてしらべました!

https://img.icons8.com/ios/452/notion.png

Notionを使っていて思うのは、、、

API使って自動化とか、整理・移行したい!」

ということで、NotionのAPIについて調べました!

(2021/05/09現在の情報です)

公式サポートはまだだよ → 5/21に公式ベータが公開されました!

  • 公式)によるとAPIの正式サポートは現在リリース準備中
  • 人数を絞ったベータ版の試験運用中
  • 公開版ベータを早期に使える事前登録(ウェイティングリスト入りできる)がある

公式ベータは以下からどうぞ developers.notion.com

有志によるAPIライブラリーはありそう

notionのAPIですが、NorthSand)さんによると有志による以下の言語のAPIライブラリーはありそうです

Pythonライブラリーを使ってみた

pip でライブラリーをインストールして

pip install notion

Notion-pyのGithubにあるクイックスタート)を実行してみます

トークンの取得はこちら)から

いざ実行

んん。エラーがでました。。。

requests.exceptions.HTTPError: Invalid input.

stackoverflowに同じひとがいました。

can't get page title from notion using api

notin-pyの以下2ファイルの limit の値を 100 に変更するとOKとのこと

  1. store.py
  2. client.py

実行してみると、、、

実行前

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0b32a843-c0ee-49ec-aa1d-e1e01a02e769/Untitled.png

実行後

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ae022b36-3ece-43f8-944c-a1a1edc819a3/Untitled.png

確かに変わっています

あーこれで、trello)から移行とかもスクリプトでできてしまいそうですね

Notion-pyの作者に共感しました

When my team introduced me to Notion, it was love at first sight. Notion brings together the best aspects of Trello, spreadsheets, relational databases, rich WYSIWYG Markdown editing, TODO lists, and more, into a single, seamless, flexible, and intuitive system. One problem: there was no documented API. The Notion team has posted about plans for an official API, and Krzysztof Kowalczyk posted a blog and code (in Go) last summer that could pull content from the internal Notion API to generate HTML. But I wanted something that a) gave me full read-write control over my Notion data, and b) was written in my language of choice, Python. from https://medium.com/@jamiealexandre/introducing-notion-py-an-unofficial-python-api-wrapper-for-notion-so-603700f92369

  • 訳文

    私のチームがNotionを紹介してくれたとき、一目で気に入りました。Notionは、Trello、スプレッドシート、リレーショナルデータベース、リッチなWYSIWYG Markdown編集、TODOリストなどの最良の側面を、単一の、シームレスで、柔軟で、直感的なシステムにまとめています。問題は、ドキュメント化されたAPIがなかったことです。Notionチームは公式APIの計画について投稿し、Krzysztof Kowalczykは昨年の夏、Notionの内部APIからコンテンツを引き出してHTMLを生成するブログとコード(Go言語)を投稿しました。しかし、私が欲しかったのは、a)Notionのデータを完全に読み書きできるもの、b)私の好きな言語であるPythonで書かれたもの、でした。

Notionは本物のAll in One ワークスペースかもしれません

今後にも期待ですし、公式APIにも期待ですね

(他サービスからの移行がラクになるといいですな🔥)