我一直在使用概念来跟踪我的习惯和财务状况。现在我想使用 Notion API 从数据库中获取数据。但是概念 API 需要数据库 ID,但我似乎找不到它。
我有一些 Python 代码,可以使用notion-client 库检索 Notion 数据库中的行。该代码确实设法检索所有行,但顺序错误。我查看了API 参考中的Sort 对象,但无法弄清楚如何使用它以行在 notion.so 上显示的确切顺序返回行。这是有问题的片段:
from notion_client import Client
notion = Client(auth=NOTION_API_TOKEN)
result = notion.databases.query(database_id='...')
for row in result['results']:
title = row['properties']['NAME_OF_PROPERTY']['title']
if len(title) == 0:
print('')
else:
print(title[0]['plain_text'])
Run Code Online (Sandbox Code Playgroud)
我缺少什么?
我对 Notion 非常陌生,我想在项目中使用该 API。
我应该如何在 Notion 数据库中插入数据?我知道如何读取有关数据库的信息,我知道如何更新架构,我知道如何从数据库检索数据,但我不知道如何向数据库插入数据或从数据库中删除数据。
谢谢。
我试图获取我的 Notion 工作区的所有页面,但搜索方法返回空响应,而我的个人工作区上有页面。
代码 :
import { Client, LogLevel } from '@notionhq/client'
const notion = new Client({
auth: '<hidden>',
logLevel: LogLevel.DEBUG
})
const databasesQuery = await notion.search({})
console.log(databasesQuery)
Run Code Online (Sandbox Code Playgroud)
输出
@notionhq/client info: request start { method: 'post', path: 'search' }
@notionhq/client info: request success { method: 'post', path: 'search' }
{ object: 'list', results: [], next_cursor: null, has_more: false }
Run Code Online (Sandbox Code Playgroud) 我正在使用 Notion API Beta,从具有我感兴趣的“文件和媒体”属性的表中读取页面。API 响应仅提供上传到那里的文件的名称,但我没有实际访问它们的 URL。我缺少什么?谢谢。
{
"Photo": {
"id": "xxxx",
"type": "files",
"files": [
{
"name": "000150748673-ofnuhb-t500x500.jpg"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
更新:参见答案。
我计划使用 notion api 制作一些博客。
我想使用 notion api 将 notion 页面降价并显示在我的博客上。
但是,我找不到获取页面内容..
有没有办法使用api导入页面markdown内容?
我想使用 Notion 作为 SPA 的内容网关。我可以使用 fetch 中的 Notion API 吗?我正在尝试使用 fetch 来获取数据,但由于 CORS 而无法正常工作。
let notion = fetch(import.meta.env.VITE_NOTION_API_URL+'/databases/'+import.meta.env.VITE_NOTION_APP_DATABASE+'/query', {
method: 'POST',
mode: 'cors',
credentials: 'omit',
headers: {
'Content-Type': 'application/json',
"Authorization": `Bearer ${import.meta.env.VITE_NOTION_API_SECRET}`,
"Notion-Version": `${import.meta.env.VITE_NOTION_API_VERSION}`,
}
})
Run Code Online (Sandbox Code Playgroud)
这可能吗?
有没有更有效的方法来获取所有数据库的列表?我尝试过使用https://api.notion.com/v1/databases
端点,但它现在已被弃用。另一个选项是/search
端点,但它也返回数据库中的所有记录。
有人可以提供更好的方法来列出集成访问的所有数据库吗?
是否可以通过 API 下载 PDF 格式的 Notion 页面?就像 UI 中提供的导出 -> PDF 功能一样?
我正在尝试自动化导出过程。我搜索了 Notion API 但找不到任何东西。