Skip to main content
Before you begin, make sure you’ve followed Notion’s Getting Started Guide to create an integration and obtain an API token.

Installation

First, install the Notion SDK:

Initialize the Client

Import and initialize a client using your integration token:
Never hardcode your API token directly in your code. Always use environment variables or a secure configuration management system.

Make Your First API Call

Once initialized, you can make requests to any Notion API endpoint. Here’s an example that lists all users in your workspace:

Example Response

Each method returns a Promise that resolves with the API response:

Query a Data Source

Here’s a more advanced example that queries a data source with filters:
Endpoint parameters are grouped into a single object. You don’t need to remember which parameters go in the path, query, or body.

Complete Example

Here’s a complete working example that creates a new page in a database:
1

Set up your environment

Create a .env file in your project root:
2

Create your script

Create a file called create-page.js:
3

Run your script

Execute the script:

Error Handling

Always wrap your API calls in try-catch blocks to handle errors gracefully:
The SDK provides typed error codes through the APIErrorCode enum, making it easy to handle specific error scenarios.

Available Endpoints

The client provides access to all Notion API endpoints through intuitive namespaces:
  • notion.blocks - Block CRUD operations
  • notion.databases - Database CRUD operations
  • notion.dataSources - Data source operations and querying
  • notion.pages - Page CRUD operations
  • notion.users - User listing and retrieval
  • notion.comments - Comment CRUD operations
  • notion.fileUploads - File upload lifecycle management
  • notion.search() - Search across workspace
For a complete list of available methods and parameters, see the API Reference.

Next Steps

Authentication

Learn about authentication options including OAuth

Error Handling

Master error handling with typed error codes

TypeScript Support

Leverage full TypeScript support and type guards

Examples

Explore more examples in the Notion Cookbook