admin管理员组文章数量:1403516
I'm trying to query a Notion database using Google Apps Script, but I keep getting a 404 Not Found
error.
My Setup
- Using Google Apps Script (GAS) to query a Notion Database.
- Notion API Version: 2022-06-28
- Database ID: 1b950a040a82xxxxxxxxxxxxxxc72fc
- Integration:
gas_note_bot_v5
(with Full Access to the database) - Tested with Postman but still getting
404 Not Found
.
My Code (Google Apps Script)
const NOTION_API_KEY = "ntn_xxxxxxxxxxxxxxxxxxxxxxx";
const DATABASE_ID = "1b950a040a82xxxxxxxxxxxxxxc72fc";
function testNotionAPI() {
const url = `/${DATABASE_ID}/query`;
const options = {
method: "post",
headers: {
"Authorization": `Bearer ${NOTION_API_KEY}`,
"Notion-Version": "2022-06-28",
"Content-Type": "application/json"
},
muteHttpExceptions: true
};
const response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
Error Message
{
"object": "error",
"status": 404,
"code": "object_not_found",
"message": "Could not find database with ID: 1b950a040a82807b8209e36b588c72fc. Make sure the relevant pages and databases are shared with your integration."
}
What I've Tried
✅ Double-checked the Database ID from the Notion page URL
✅ Verified that the API Key is correct
✅ Ensured that Integration (gas_note_bot_v5) has Full Access to the
database
✅ Tried querying using Postman, but still got 404 Not Found
I'm trying to query a Notion database using Google Apps Script, but I keep getting a 404 Not Found
error.
My Setup
- Using Google Apps Script (GAS) to query a Notion Database.
- Notion API Version: 2022-06-28
- Database ID: 1b950a040a82xxxxxxxxxxxxxxc72fc
- Integration:
gas_note_bot_v5
(with Full Access to the database) - Tested with Postman but still getting
404 Not Found
.
My Code (Google Apps Script)
const NOTION_API_KEY = "ntn_xxxxxxxxxxxxxxxxxxxxxxx";
const DATABASE_ID = "1b950a040a82xxxxxxxxxxxxxxc72fc";
function testNotionAPI() {
const url = `https://api.notion/v1/databases/${DATABASE_ID}/query`;
const options = {
method: "post",
headers: {
"Authorization": `Bearer ${NOTION_API_KEY}`,
"Notion-Version": "2022-06-28",
"Content-Type": "application/json"
},
muteHttpExceptions: true
};
const response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
Error Message
{
"object": "error",
"status": 404,
"code": "object_not_found",
"message": "Could not find database with ID: 1b950a040a82807b8209e36b588c72fc. Make sure the relevant pages and databases are shared with your integration."
}
What I've Tried
✅ Double-checked the Database ID from the Notion page URL
✅ Verified that the API Key is correct
✅ Ensured that Integration (gas_note_bot_v5) has Full Access to the
database
✅ Tried querying using Postman, but still got 404 Not Found
- 1 Does this answer your question? stackoverflow/q/74818210 – TheMaster Commented Mar 21 at 0:26
1 Answer
Reset to default 0The question doesn't include enought details about the steps that should be followed to use the Notion API in Google Apps Script and might be interchanging concepts like workpsace, page and database. Below there a quick overvieow of the requirements, stops and a boilerplate code.
Requirements
- Have a Google account with access to Google Apps Script.
Note: Google Workspace admin might block access to Google Apps Script. - Have a Notion account.
- Be the owner of the Notion workspace
Steps
- Create a new integration in Notion. For details, see https://developers.notion/docs/create-a-notion-integration#create-your-integration-in-notion.
- Get your API secret. For details, see https://developers.notion/docs/create-a-notion-integration#create-your-integration-in-notion.
- Grab the required page ids and database ids.
When using a free Notion plan and a personal workspace - a page URL ooks like this
https://www.notion.so/Integration-Test-1be65a23f29f80a1af8dd1688afebc39
.
The page id is1be65a23f29f80a1af8dd1688afebc39
.
- A database URL looks like this
https://www.notion.so/1be65a23f29f80f18ab3f7f36509bf61?v=1be65a23f29f80a48dc2000ccf143d01
.
The database id is1be65a23f29f80f18ab3f7f36509bf61
. - If you haven't done yet, create a new Apps Script project.
- Add the JavaScript code with the
fetch
orfetchAll
methods from Class UrlFetchApp.
What about the following boilerplate?
const NOTION_API_KEY = "";
const NOTION_PAGE_ID = "";
const NOTION_DATABASE_ID = "";
function myFunction(){
const url = "https://api.notion/v1/databases/" + NOTION_DATABASE_ID;
// const url = "https://api.notion/v1/pages/" + NOTION_PAGE_ID;
const options = {
method: "get",
// method: "post",
// method: "patch",
muteHttpExceptons: false,
headers: {
"Authorization": `Bearer ${NOTION_API_KEY}`,
"Notion-Version": "2022-06-28",
"Content-Type": "application/json"
},
muteHttpExceptions: true
};
const response = UrlFetchApp.fetch(url, options);
Logger.log(JSON.stringify(response.getContentText(), null, " "));
}
Regarding querying a Notion's database, the code in the question missed the payload. See https://developers.notion/reference/post-database-query
本文标签: Notion API 404 Error Cannot Find Database when querying from Google Apps ScriptStack Overflow
版权声明:本文标题:Notion API 404 Error: Cannot Find Database when querying from Google Apps Script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744395793a2604208.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论