API token is invalid.
kamilklkn opened this issue · 11 comments
Hi,
First of all thanks for the project. I tried with my database.
I take the database id and write it instead. Does it mean "NOTION_TOKEN" from API tokon in this error?
If so, where exactly should I access the "NOTION_TOKEN" value? Because when I tried it with "Internal Integration Token" value, it didn't work either.
NOTION_TOKEN
is the Internal Integration Token itself, I suspect some kind of error accessing the token. Can you log the NOTION_TOKEN
and check if it's present.
building the error Client warn: request fail { code: 'unauthorized', message: 'API token is invalid.' } APIResponseError: API token is invalid. at Object.buildRequestError (/Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/@notionhq/client/build/src/errors.js:77:20) at Client.request (/Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/@notionhq/client/build/src/Client.js:206:43) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async getDatabase (webpack-internal:///./lib/notion.js:14:20) at async getStaticProps (webpack-internal:///./pages/index.js:227:20) at async renderToHTML (/Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/next/dist/next-server/server/render.js:28:1689) at async /Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/next/dist/next-server/server/next-server.js:111:97 at async __wrapper (/Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/next/dist/lib/coalesced-function.js:1:330) at async DevServer.renderToHTMLWithComponents (/Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/next/dist/next-server/server/next-server.js:136:387) at async DevServer.renderToHTML (/Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/next/dist/next-server/server/next-server.js:137:610) { code: 'unauthorized', status: 401, headers: { date: 'Thu, 20 May 2021 07:14:34 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '87', connection: 'close', 'x-dns-prefetch-control': 'off', 'x-frame-options': 'SAMEORIGIN', 'strict-transport-security': 'max-age=5184000; includeSubDomains', 'x-download-options': 'noopen', 'x-content-type-options': 'nosniff', 'x-xss-protection': '1; mode=block', 'referrer-policy': 'same-origin', 'content-security-policy': "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://gist.github.com https://apis.google.com https://api.amplitude.com https://widget.intercom.io https://js.intercomcdn.com https://logs-01.loggly.com https://cdn.segment.com https://analytics.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://embed.typeform.com https://admin.typeform.com https://public.profitwell.com js.sentry-cdn.com https://platform.twitter.com https://cdn.syndication.twimg.com https://www.googletagmanager.com https://x.clearbitjs.com; connect-src 'self' https://msgstore.www.notion.so wss://msgstore.www.notion.so ws://localhost:* https://notion-emojis.s3-us-west-2.amazonaws.com https://s3-us-west-2.amazonaws.com https://s3.us-west-2.amazonaws.com https://notion-production-snapshots-2.s3.us-west-2.amazonaws.com https: http: https://api.amplitude.com https://api.embed.ly https://js.intercomcdn.com https://api-iam.intercom.io wss://nexus-websocket-a.intercom.io https://logs-01.loggly.com https://api.segment.io https://api.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://cdn.contentful.com https://preview.contentful.com https://images.ctfassets.net https://www2.profitwell.com https://api.unsplash.com https://boards-api.greenhouse.io; font-src 'self' data: https://cdnjs.cloudflare.com https://js.intercomcdn.com; img-src 'self' data: blob: https: https://platform.twitter.com https://syndication.twitter.com https://pbs.twimg.com https://ton.twimg.com www.googletagmanager.com; style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com https://github.githubassets.com https://platform.twitter.com https://ton.twimg.com; frame-src https: http:; media-src https: http:", 'x-content-security-policy': "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://gist.github.com https://apis.google.com https://api.amplitude.com https://widget.intercom.io https://js.intercomcdn.com https://logs-01.loggly.com https://cdn.segment.com https://analytics.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://embed.typeform.com https://admin.typeform.com https://public.profitwell.com js.sentry-cdn.com https://platform.twitter.com https://cdn.syndication.twimg.com https://www.googletagmanager.com https://x.clearbitjs.com; connect-src 'self' https://msgstore.www.notion.so wss://msgstore.www.notion.so ws://localhost:* https://notion-emojis.s3-us-west-2.amazonaws.com https://s3-us-west-2.amazonaws.com https://s3.us-west-2.amazonaws.com https://notion-production-snapshots-2.s3.us-west-2.amazonaws.com https: http: https://api.amplitude.com https://api.embed.ly https://js.intercomcdn.com https://api-iam.intercom.io wss://nexus-websocket-a.intercom.io https://logs-01.loggly.com https://api.segment.io https://api.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://cdn.contentful.com https://preview.contentful.com https://images.ctfassets.net https://www2.profitwell.com https://api.unsplash.com https://boards-api.greenhouse.io; font-src 'self' data: https://cdnjs.cloudflare.com https://js.intercomcdn.com; img-src 'self' data: blob: https: https://platform.twitter.com https://syndication.twitter.com https://pbs.twimg.com https://ton.twimg.com www.googletagmanager.com; style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com https://github.githubassets.com https://platform.twitter.com https://ton.twimg.com; frame-src https: http:; media-src https: http:", 'x-webkit-csp': "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://gist.github.com https://apis.google.com https://api.amplitude.com https://widget.intercom.io https://js.intercomcdn.com https://logs-01.loggly.com https://cdn.segment.com https://analytics.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://embed.typeform.com https://admin.typeform.com https://public.profitwell.com js.sentry-cdn.com https://platform.twitter.com https://cdn.syndication.twimg.com https://www.googletagmanager.com https://x.clearbitjs.com; connect-src 'self' https://msgstore.www.notion.so wss://msgstore.www.notion.so ws://localhost:* https://notion-emojis.s3-us-west-2.amazonaws.com https://s3-us-west-2.amazonaws.com https://s3.us-west-2.amazonaws.com https://notion-production-snapshots-2.s3.us-west-2.amazonaws.com https: http: https://api.amplitude.com https://api.embed.ly https://js.intercomcdn.com https://api-iam.intercom.io wss://nexus-websocket-a.intercom.io https://logs-01.loggly.com https://api.segment.io https://api.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://cdn.contentful.com https://preview.contentful.com https://images.ctfassets.net https://www2.profitwell.com https://api.unsplash.com https://boards-api.greenhouse.io; font-src 'self' data: https://cdnjs.cloudflare.com https://js.intercomcdn.com; img-src 'self' data: blob: https: https://platform.twitter.com https://syndication.twitter.com https://pbs.twimg.com https://ton.twimg.com www.googletagmanager.com; style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com https://github.githubassets.com https://platform.twitter.com https://ton.twimg.com; frame-src https: http:; media-src https: http:", 'set-cookie': [ 'notion_browser_id=3534fc0f-6d84-4293-9bee-3b9044ae6aa1; Domain=www.notion.so; Path=/; Expires=Sun, 26 Jan 2053 09:01:14 GMT; Secure' ], etag: 'W/"57-QCRLT3IovYEW+CkwyJQlFtiXiG8"', vary: 'Accept-Encoding', 'cf-cache-status': 'DYNAMIC', 'cf-request-id': '0a2a3955d000000f8a5d252000000001', 'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', server: 'cloudflare', 'cf-ray': '6523c4cfbcdd0f8a-VIE' }, body: '{"object":"error","status":401,"code":"unauthorized","message":"API token is invalid."}' } building the error Client warn: request fail { code: 'unauthorized', message: 'API token is invalid.' } APIResponseError: API token is invalid. at Object.buildRequestError (/Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/@notionhq/client/build/src/errors.js:77:20) at Client.request (/Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/@notionhq/client/build/src/Client.js:206:43) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async getDatabase (webpack-internal:///./lib/notion.js:14:20) at async getStaticProps (webpack-internal:///./pages/index.js:227:20) at async renderToHTML (/Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/next/dist/next-server/server/render.js:28:1689) at async /Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/next/dist/next-server/server/next-server.js:111:97 at async __wrapper (/Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/next/dist/lib/coalesced-function.js:1:330) at async DevServer.renderToHTMLWithComponents (/Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/next/dist/next-server/server/next-server.js:136:387) at async DevServer.renderToHTML (/Users/kamilklkn/Downloads/notion-blog-nextjs-master/node_modules/next/dist/next-server/server/next-server.js:137:610) { code: 'unauthorized', status: 401, headers: { date: 'Thu, 20 May 2021 07:25:03 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '87', connection: 'close', 'x-dns-prefetch-control': 'off', 'x-frame-options': 'SAMEORIGIN', 'strict-transport-security': 'max-age=5184000; includeSubDomains', 'x-download-options': 'noopen', 'x-content-type-options': 'nosniff', 'x-xss-protection': '1; mode=block', 'referrer-policy': 'same-origin', 'content-security-policy': "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://gist.github.com https://apis.google.com https://api.amplitude.com https://widget.intercom.io https://js.intercomcdn.com https://logs-01.loggly.com https://cdn.segment.com https://analytics.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://embed.typeform.com https://admin.typeform.com https://public.profitwell.com js.sentry-cdn.com https://platform.twitter.com https://cdn.syndication.twimg.com https://www.googletagmanager.com https://x.clearbitjs.com; connect-src 'self' https://msgstore.www.notion.so wss://msgstore.www.notion.so ws://localhost:* https://notion-emojis.s3-us-west-2.amazonaws.com https://s3-us-west-2.amazonaws.com https://s3.us-west-2.amazonaws.com https://notion-production-snapshots-2.s3.us-west-2.amazonaws.com https: http: https://api.amplitude.com https://api.embed.ly https://js.intercomcdn.com https://api-iam.intercom.io wss://nexus-websocket-a.intercom.io https://logs-01.loggly.com https://api.segment.io https://api.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://cdn.contentful.com https://preview.contentful.com https://images.ctfassets.net https://www2.profitwell.com https://api.unsplash.com https://boards-api.greenhouse.io; font-src 'self' data: https://cdnjs.cloudflare.com https://js.intercomcdn.com; img-src 'self' data: blob: https: https://platform.twitter.com https://syndication.twitter.com https://pbs.twimg.com https://ton.twimg.com www.googletagmanager.com; style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com https://github.githubassets.com https://platform.twitter.com https://ton.twimg.com; frame-src https: http:; media-src https: http:", 'x-content-security-policy': "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://gist.github.com https://apis.google.com https://api.amplitude.com https://widget.intercom.io https://js.intercomcdn.com https://logs-01.loggly.com https://cdn.segment.com https://analytics.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://embed.typeform.com https://admin.typeform.com https://public.profitwell.com js.sentry-cdn.com https://platform.twitter.com https://cdn.syndication.twimg.com https://www.googletagmanager.com https://x.clearbitjs.com; connect-src 'self' https://msgstore.www.notion.so wss://msgstore.www.notion.so ws://localhost:* https://notion-emojis.s3-us-west-2.amazonaws.com https://s3-us-west-2.amazonaws.com https://s3.us-west-2.amazonaws.com https://notion-production-snapshots-2.s3.us-west-2.amazonaws.com https: http: https://api.amplitude.com https://api.embed.ly https://js.intercomcdn.com https://api-iam.intercom.io wss://nexus-websocket-a.intercom.io https://logs-01.loggly.com https://api.segment.io https://api.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://cdn.contentful.com https://preview.contentful.com https://images.ctfassets.net https://www2.profitwell.com https://api.unsplash.com https://boards-api.greenhouse.io; font-src 'self' data: https://cdnjs.cloudflare.com https://js.intercomcdn.com; img-src 'self' data: blob: https: https://platform.twitter.com https://syndication.twitter.com https://pbs.twimg.com https://ton.twimg.com www.googletagmanager.com; style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com https://github.githubassets.com https://platform.twitter.com https://ton.twimg.com; frame-src https: http:; media-src https: http:", 'x-webkit-csp': "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://gist.github.com https://apis.google.com https://api.amplitude.com https://widget.intercom.io https://js.intercomcdn.com https://logs-01.loggly.com https://cdn.segment.com https://analytics.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://embed.typeform.com https://admin.typeform.com https://public.profitwell.com js.sentry-cdn.com https://platform.twitter.com https://cdn.syndication.twimg.com https://www.googletagmanager.com https://x.clearbitjs.com; connect-src 'self' https://msgstore.www.notion.so wss://msgstore.www.notion.so ws://localhost:* https://notion-emojis.s3-us-west-2.amazonaws.com https://s3-us-west-2.amazonaws.com https://s3.us-west-2.amazonaws.com https://notion-production-snapshots-2.s3.us-west-2.amazonaws.com https: http: https://api.amplitude.com https://api.embed.ly https://js.intercomcdn.com https://api-iam.intercom.io wss://nexus-websocket-a.intercom.io https://logs-01.loggly.com https://api.segment.io https://api.pgncs.notion.so https://o324374.ingest.sentry.io https://checkout.stripe.com https://js.stripe.com https://cdn.contentful.com https://preview.contentful.com https://images.ctfassets.net https://www2.profitwell.com https://api.unsplash.com https://boards-api.greenhouse.io; font-src 'self' data: https://cdnjs.cloudflare.com https://js.intercomcdn.com; img-src 'self' data: blob: https: https://platform.twitter.com https://syndication.twitter.com https://pbs.twimg.com https://ton.twimg.com www.googletagmanager.com; style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com https://github.githubassets.com https://platform.twitter.com https://ton.twimg.com; frame-src https: http:; media-src https: http:", 'set-cookie': [ 'notion_browser_id=3d6701c7-0855-4258-9b7a-e752c2c7591e; Domain=www.notion.so; Path=/; Expires=Sun, 26 Jan 2053 09:11:43 GMT; Secure' ], etag: 'W/"57-QCRLT3IovYEW+CkwyJQlFtiXiG8"', vary: 'Accept-Encoding', 'cf-cache-status': 'DYNAMIC', 'cf-request-id': '0a2a42eeb500000f8a12104000000001', 'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', server: 'cloudflare', 'cf-ray': '6523d42ab8230f8a-VIE' }, body: '{"object":"error","status":401,"code":"unauthorized","message":"API token is invalid."}' }
I checked it the way you said. The token is registered but I get the same error.
Make sure you are using the correct token (it should start with secret_
) and that it's added it to a file called .env.local
in the root of your project.
You can try adding the tokens to the .env.example
file and rename it if you're having issues.
It was fixed when I deleted the project and reinstalled all the packages. Thanks for your help.
changing the .env.local
to just .env
fixed it for me.
@Dipeshwagle I noticed that the tokjn is not going through, as shown in this screenshot. I already reinstalled, changed the .env.local to .env, but the problem remains. Any ideas I could try here? Thanks in advance
You can use the deploy to vercel button if you are having issues. It will deploy the repo directly to Vercel and force you to enter the tokens correctly.
Is there a tutorial you can point me to so I can prettify the slugs?
@iankilmister You have to edit the data fetching functions to query for the slug instead of id. Here's a post from another blog giving some guidance: https://www.coryetzkorn.com/blog/how-the-notion-api-powers-my-blog