3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

NotionAPIを使用する第一歩(データベースのデータ取得)

Posted at

はじめに

NotionAPIを使用してNotionのデータベースの情報を取得してみましょう。

環境

  • Windows
  • Python(pipのインストール)

notion-clientを使用しました
notion-client

モジュールのインストール

pip install notion-client

Notionのデータベース情報をコンソールへ出力

ファイル名はnotion.pyとしました

# Notion APIクライアントをインポート
from notion_client import Client
import json

# Notion APIキーとデータベースIDを設定
notion_api_key = "your_notion_api_key"
database_id = "your_database_id"

# Notion APIクライアントを作成
notion = Client(auth=notion_api_key)

# 指定されたデータベースIDのデータベースを取得する関数
def fetch_database(database_id):
    # データベースを取得して返す
    database = notion.databases.retrieve(database_id)
    return database

# メイン処理
if __name__ == "__main__":
    # データベースを取得
    database = fetch_database(database_id)
    # データベースの内容を整形してJSON形式で出力
    database_json = json.dumps(database, indent=2)
    # JSON形式のデータベース内容を表示
    print(database_json)

ファイル実行

PS C:\Users> python .\notion.py
{
  "object": "database",
....結果が出力

最後に

Notion APIを使用するとデータベースの入力に手間取っていた日々から解放されます。
皆さんで、いろんな使用方法を共有していきましょう!

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?