Jos*_*osh 5 javascript json notion-api
我可以使用 Notion API 创建一个新页面,作为该页面的一部分,我想创建并包含一个数据库表。我能够成功创建页面,但是当尝试使用 child_database 块创建数据库时,我收到状态 400 错误。下面的示例代码。任何帮助表示赞赏。
let payload = {
'parent': {'database_id': database_id_variable},
'properties': {
'Name': {
'title': [
{'text': {'content': 'My Grocery List Page'}}
]
}
},
'children': [
{
'object': 'block',
'type': 'child_database',
'child_database': {
'title': 'Grocery List',
'properties': {
'Grocery item': {
'type': 'title',
'title': [{ 'type': 'text', 'text': { 'content': 'Tomatoes' } }]
},
}
}
},
]
}
let response = await fetch('https://api.notion.com/v1/pages', {
method: 'POST',
body: JSON.stringify(payload),
headers: {
'Authorization' : 'Bearer secret_XXX',
'Content-Type': 'application/json',
'Notion-Version': '2021-08-16',
},
});
console.log(await response.json());
}
Run Code Online (Sandbox Code Playgroud)
虽然不是子数据库,但我能够通过创建一个简单的表来解决我的问题,因为 Notion 刚刚宣布 API 现在将支持简单的表:
https://developers.notion.com/reference/block#table-blocks