🤖

GASでNotionを操作するライブラリを作成した

2022/12/18に公開

はじめに

Notion APIを使いやすくするライブラリを作成しました。

ライブラリの導入

スクリプトIDはこちら。

1P5ARr7gp69EnBgiNMVEVboO-M-XESgTSycWU2WWBuIvdxtFsYk4MlyG0

現時点の最新はバージョン 3(12月19日 22:27)です。

参考
https://gadgelaun.com/?p=27642#:~:text=まとめ-,GASのライブラリ追加方法,追加することができる。

使い方

const NOTION_CONFIG = {
  token: '', // token
  db_id: {
    test: '', // データベースID
  },
};

// マネージャークラスのインスタンス化
const notionManager = Notion.initManager(NOTION_CONFIG.token);

// レコードクラスのインスタンス化
const record = Notion.initRecord();

// タイトルの設定
notionRecord.setTitle('name', '新版 市場を創る:バザールからネット取引まで');
// アイコンの設定
notionRecord.setIcon('📗');
// urlプロパティの設定。第1引数はプロパティ名。
notionRecord.setPropertiesUrl('url', 'https://www.amazon.co.jp/dp/4766427831');

// Notionに設定した内容でレコードを作成。
notionManager.createRecord(NOTION_CONFIG.db_id.test, record);

メソッド一覧

ソース

https://github.com/nag8/NotionManagerGAS

本文の挿入

notionRecord.pushChildrenText('本文だよ');

プロパティの設定

日付

const date = dayjs.dayjs();
notionRecord.setPropertiesDate('日付', date);


// 終了日時がある場合
const startDate = dayjs.dayjs();
const endDate = dayjs.dayjs();
notionRecord.setPropertiesDate('日付', startDate, endDate);

// 時間も含める場合
notionRecord.setPropertiesDatetime('日付', startDate, endDate);

セレクト

notionRecord.setPropertiesSelect('タグ', '本');

数値

notionRecord.setPropertiesNumber('ポイント', 500);

できた機能、まだ実装していない機能はこちら。機能要望はこのprojectに書いてもらえるとなんかするかもしれないです。
https://github.com/users/nag8/projects/1

Discussion