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: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 aPromise that resolves with the API response:
Query a Data Source
Here’s a more advanced example that queries a data source with filters: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 operationsnotion.databases- Database CRUD operationsnotion.dataSources- Data source operations and queryingnotion.pages- Page CRUD operationsnotion.users- User listing and retrievalnotion.comments- Comment CRUD operationsnotion.fileUploads- File upload lifecycle managementnotion.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