iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🤖
Created a Google Apps Script Library for Interacting with Notion
Introduction
I created a library to make the Notion API easier to use.
Library Installation
Here is the Script ID.
1P5ARr7gp69EnBgiNMVEVboO-M-XESgTSycWU2WWBuIvdxtFsYk4MlyG0
The current latest version is version 3 (December 19, 22:27).
Reference
Usage
Example
const NOTION_CONFIG = {
token: '', // token
db_id: {
test: '', // Database ID
},
};
// Instantiating the manager class
const notionManager = Notion.initManager(NOTION_CONFIG.token);
// Instantiating the record class
const record = Notion.initRecord();
// Setting the title
notionRecord.setTitle('name', '新版 市場を創る:バザールからネット取引まで');
// Setting the icon
notionRecord.setIcon('📗');
// Setting the URL property. The first argument is the property name.
notionRecord.setPropertiesUrl('url', 'https://www.amazon.co.jp/dp/4766427831');
// Creating a record with the configured content in Notion.
notionManager.createRecord(NOTION_CONFIG.db_id.test, record);

List of Methods
Source
Inserting the Body Text
notionRecord.pushChildrenText('This is the body text');

Setting Properties
Date
const date = dayjs.dayjs();
notionRecord.setPropertiesDate('日付', date);
// If there is an end date/time
const startDate = dayjs.dayjs();
const endDate = dayjs.dayjs();
notionRecord.setPropertiesDate('日付', startDate, endDate);
// If including time
notionRecord.setPropertiesDatetime('日付', startDate, endDate);
Select
notionRecord.setPropertiesSelect('タグ', '本');
Number
notionRecord.setPropertiesNumber('ポイント', 500);
You can find implemented and pending features here. If you have any feature requests, please post them in this project and I might take a look.
Discussion
このライブラリを使ってみたいのですが、イマイチ使い方がわからなくてコメントさせていただきました。
このライブラリを使ったら、Notionにつかったデータベースの内容をスプレッドシートに転記することは可能でしょうか?
可能ですね!
queryというメソッドを用意しているんですが、それを使ってNotionの全レコードを取得することが可能です。 ↑の記事が「Notionにあるお知らせDBからお知らせをとってくる」のような使い方をしているので参考にしてみてください。