react-notion-x
react-notion-x copied to clipboard
Private notion-client API returns 400 sometimes (while using auth token)
Problem
In the earlier iteration of my website, I have used notion client but without auth, thus making my collection public. Everything worked as expected. In the latest iteration of my website, I tried out the auth based approach. But it seems that some collections are fetched all right, but some of them return this error:
HTTPError: Response code 400 (Bad Request)
at Request.<anonymous> (/home/humble_d/Projects/fullstack/pipe-runner-website/node_modules/got/dist/source/as-promise/index.js:117:42)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
code: 'ERR_NON_2XX_3XX_RESPONSE',
timings: {
start: 1648073614408,
socket: 1648073614408,
lookup: 1648073614552,
connect: 1648073614699,
secureConnect: 1648073614848,
upload: 1648073614848,
response: 1648073615594,
end: 1648073615595,
error: undefined,
abort: undefined,
phases: {
wait: 0,
dns: 144,
tcp: 147,
tls: 149,
request: 0,
firstByte: 746,
download: 1,
total: 1187
}
}
}
Exploration from my end
I have experimented a bit and it seems like in whichever blogs, I have uploaded an image, this error shows up. Only when I make the collection public, it returns the response correctly. This is not the case for other collections which do not have an image. There they work without making them public.
Answering some obvious questions:
This is how I am using the auth based version of the client.
const notion = new NotionAPI({
activeUser: process.env.NOTION_ACTIVE_USER,
authToken: process.env.NOTION_TOKEN_V2
});
and yes, I have tested this with a non-public collection and it returns collections that don't have images.
Thanks for the report; definitely seems like a bug, though if I'm being honest the private auth use case is pretty low priority.
I'm not sure how helpful I can be since this is an area of notion's private API that I haven't explored much.
If you find a fix, however, we'd be happy to merge a PR.
Hi, I already made a PR fixing this issue
Hi,
I'm facing the same error on each NextJS build, without private auth involved:
[ ===] info - Generating static pages (75/193)NotionAPI getSignedfileUrls error HTTPError: Response code 400 (Bad Request)
at Request.<anonymous> (project_name/node_modules/got/dist/source/as-promise/index.js:117:42)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'ERR_NON_2XX_3XX_RESPONSE',
timings: {
start: 1658933110956,
socket: 1658933110956,
lookup: 1658933110957,
connect: 1658933110967,
secureConnect: 1658933110978,
upload: 1658933110978,
response: 1658933111187,
end: 1658933111187,
error: undefined,
abort: undefined,
phases: {
wait: 0,
dns: 1,
tcp: 10,
tls: 11,
request: 0,
firstByte: 209,
download: 0,
total: 231
}
}
}
is there any update on this