Open muke5hy opened 1 month ago
I got exactly same issue.
in my case,
"dependencies" : { "react-notion-x": "^6.16.0" }
and actual version is 6.16.0.
Description
I am constatnly getting following error, token and database ID works with
@notionhq/client
but it is not working withnotion-client
What am I doing wrong?⨯ Internal error: HTTPError: Response code 401 (Unauthorized) at Request.eval (./node_modules/.pnpm/got@11.8.6/node_modules/got/dist/source/as-promise/index.js:118:42) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) digest: "1102196494"
Notion Test Page ID
NOTION_AUTH_TOKEN=secret_thisisasecreat NOTION_DATABASE_ID=8a42e373328c49a9a495ddd05fce7fa3
I have resolved my issue. In case you encounter a similar situation, please refer to this.
The NotionAPI class has a problem with the authToken option, but if you just need to retrieve some data, you don’t need to authorize.
import { Client } from "@notionhq/client";
import { DatabaseObjectResponse } from "@notionhq/client/build/src/api-endpoints";
import { NotionAPI } from "notion-client";
const notionToken = process.env.NOTION_KEY;
const notionDatabaseId = process.env.NOTION_DATABASE_ID;
const notion = new Client({
auth: notionToken,
});
const notionApi = new NotionAPI();
export async function getPosts() {
const response = await notion.databases.query({
database_id: notionDatabaseId as string,
filter: {
property: "상태",
status: {
equals: "공개",
},
},
});
return response.results as DatabaseObjectResponse[];
}
export async function getPage(id: string) {
const response = await notionApi.getPage(id);
return response;
}
authToken for NotionAPI is not secret key. you need to check token_v2
for chrome developer tool.
authToken for NotionAPI is not secret key. you need to check
token_v2
for chrome developer tool.
Will this token_v2 ever changes, say when user logs out of Notion?
I am hesitant to rely on this cookie token thing personally. I found another way via the Notion official API if you want to retrieve a private page.
https://github.com/NotionX/react-notion-x/tree/master/packages/notion-compat
import { Client } from '@notionhq/client'
import { NotionCompatAPI } from 'notion-compat'
const notion = new NotionCompatAPI(
new Client({ auth: process.env.NOTION_TOKEN })
)
const recordMap = await notion.getPage(pageId)
Note that there are some compatibility limitations if you use notion-compat
.
Description
I am constatnly getting following error, token and database ID works with
@notionhq/client
but it is not working withnotion-client
What am I doing wrong?⨯ Internal error: HTTPError: Response code 401 (Unauthorized) at Request.eval (./node_modules/.pnpm/got@11.8.6/node_modules/got/dist/source/as-promise/index.js:118:42) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) digest: "1102196494"
Notion Test Page ID
NOTION_AUTH_TOKEN=secret_thisisasecreat NOTION_DATABASE_ID=8a42e373328c49a9a495ddd05fce7fa3