使用 Notion API 新增 Notion 表格数据
-
获取 Notion API 访问令牌
-
登录 Notion 并创建一个 integrations(Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.)
-
点击 New Integration
- 点击Submit
- 获取访问令牌:点击
Internal Integration Token
的Show → Copy
-
-
找到要更新的表格的数据库 ID
- 在 Notion 中打开表格数据库
-
从 URL 中复制数据库 ID:Copy link to view
获取的链接最后一个路径的名称就是tableID:
[https://www.notion.so/tableID?v=111](https://www.notion.so/tableID?v=111)
-
Add Connection
-
使用 Notion API 新增数据
API文档:Introduction
const request = require('request');// 设置访问令牌和数据库 ID const token = 'your_token_here'; const databaseId = 'your_database_id_here';// 设置要添加的数据 const reqData = {"parent": { "database_id": `${databaseId}` },"properties": {"Name": {"title": [{"text": {"content": "New Value"}}]}} };// 发送 POST 请求 request({url: `https://api.notion.com/v1/pages`,method: 'POST',json: reqData,headers: {'Authorization': `Bearer ${token}`,'Content-Type': 'application/json','Notion-Version': '2021-08-16'} }, function(error, response, body) {if (!error && response.statusCode == 200) {console.log('New data added successfully');} else {console.log(`Error adding new data: ${response.statusCode} - ${body.message}`);} });
-
查看Notion 表格是否添加成功
使用OpenAI API:
OpenAI API 文档:https://platform.openai.com/docs/introduction/overview
1、创建一个OpenAI账户,获取API密钥
2、请求接口
const request = require('request');// 您的API密钥
const apiKey = 'apiKey';// 输入文本
const query = '咖啡花了24块'
let data = {"model": "text-davinci-003","prompt": `Parse following my bill information:"${query}". The information starts with item and price,please use "food、drink、travel、makeup" to choose one according to the information matching classification, please return valid json object with properties:{"item":"",price:"",type:""}`,"max_tokens":500,"temperature":0.5
}
console.log(data)
// 发送POST请求
let opt = {url: 'https://api.openai.com/v1/completions',method: 'POST', headers: {'Authorization': `Bearer ${apiKey}`,'Content-Type': 'application/json'},json: data
}request(opt, function (error, response, body) {if (error) {console.error(error);} else {if(body && body.choices && body.choices.length){console.log(JSON.stringify(JSON.parse(body.choices[0].text.replace(/\n/g,""))));}else{console.log('no result: ',JSON.stringify(body))}}
});
便捷记账
获取捷径:https://www.icloud.com/shortcuts/e6e068adb7fd401099e10d711c3b7f84
使用IOS ShortCut<听写文本> ⇒ OpenAI API ⇒ Notion API ⇒ New Record