Skip to content

How to Fix Notion API Token Invalid or Unauthorized Errors

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about How to Fix Notion API Token Invalid or Unauthorized Errors. We cover key concepts, practical examples, and best practices.

The Notion API uses integration tokens to authenticate requests. When your API call returns 401 Unauthorized or 400 Bad Request: Invalid token, the token was revoked, the integration was not shared with the database, or the token lacks the required capabilities.

The Problem

POST /v1/pages
Authorization: Bearer secret_abc123

Returns:

{
  "object": "error",
  "status": 401,
  "code": "unauthorized",
  "message": "API token is invalid."
}

Wrong approach — hardcoding a different token in the source code.

The Fix

Verify the token is active:

1. Go to https://www.notion.so/my-integrations
2. Find your integration
3. If the token was revoked, click "Show" and copy the new token
4. Update your code with the new token

Ensure the integration has access to the database:

1. Open the Notion database
2. Click "Share" (top-right)
3. In "Invite," search for your integration name
4. Click "Invite" — the integration now has access

Check the capabilities granted:

1. In the integration settings, check "Capabilities"
2. Read content, Update content, Insert content, etc.
3. If your API call requires "Insert content" but only "Read content" is granted, it will fail
4. Update capabilities and re-share the integration with the database

Expected output:

API returns 200 with the requested data
Pages can be created, read, updated, and searched
No 401 or 403 errors for any endpoint

Prevention Tips

  • Store API tokens in environment variables, not in code
  • Rotate tokens periodically for security
  • Grant the minimum required capabilities to each integration
  • After changing capabilities, re-share the integration with all databases it needs
  • Test API calls with a tool like Postman before implementing in code

Common Mistakes with api token

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world NOTION code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### How do I share a Notion integration with a database?

Open the database in Notion, click "Share" in the top-right corner, and in the "Invite" field search for your integration name. Click "Invite." The integration can now query and modify that database, limited by its capabilities.

Why does my integration work for some databases but not others?

Each database must be individually shared with the integration. Going to a database and clicking "Share" → invite the integration. The integration has no access to databases it has not been invited to, even if they are in the same workspace.

Can I use a single integration token for multiple applications?

Yes, a single integration token can be used by multiple applications, but this is not recommended for security. Each application should have its own integration with the minimum required capabilities. If one app is compromised, the others are not affected.

Related: DodaTech's API Token Manager securely stores Notion integration tokens, monitors usage, and rotates tokens automatically on a configurable schedule. Use with DodaZIP for encrypted token backup.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro