Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@notionhq/client

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@notionhq/client

A simple and easy to use client for the Notion API

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
444K
increased by8.22%
Maintainers
1
Weekly downloads
 
Created

What is @notionhq/client?

@notionhq/client is an official JavaScript client for the Notion API. It allows developers to interact with Notion's databases, pages, and blocks programmatically. This package is useful for automating workflows, integrating Notion with other services, and building custom applications that leverage Notion's capabilities.

What are @notionhq/client's main functionalities?

Retrieve a Database

This feature allows you to retrieve information about a specific database in Notion. You need to provide the database ID and your Notion API key.

const { Client } = require('@notionhq/client');

const notion = new Client({ auth: process.env.NOTION_API_KEY });

(async () => {
  const databaseId = 'your-database-id';
  const response = await notion.databases.retrieve({ database_id: databaseId });
  console.log(response);
})();

Query a Database

This feature allows you to query a database with specific filters. In this example, it filters the database to return only entries where the 'Status' property is 'In Progress'.

const { Client } = require('@notionhq/client');

const notion = new Client({ auth: process.env.NOTION_API_KEY });

(async () => {
  const databaseId = 'your-database-id';
  const response = await notion.databases.query({
    database_id: databaseId,
    filter: {
      property: 'Status',
      select: {
        equals: 'In Progress'
      }
    }
  });
  console.log(response.results);
})();

Create a Page

This feature allows you to create a new page in a specified database. You need to provide the database ID and the properties for the new page.

const { Client } = require('@notionhq/client');

const notion = new Client({ auth: process.env.NOTION_API_KEY });

(async () => {
  const response = await notion.pages.create({
    parent: { database_id: 'your-database-id' },
    properties: {
      Name: {
        title: [
          {
            text: {
              content: 'New Page'
            }
          }
        ]
      }
    }
  });
  console.log(response);
})();

Update a Page

This feature allows you to update properties of an existing page. In this example, it updates the 'Status' property of a page to 'Completed'.

const { Client } = require('@notionhq/client');

const notion = new Client({ auth: process.env.NOTION_API_KEY });

(async () => {
  const pageId = 'your-page-id';
  const response = await notion.pages.update({
    page_id: pageId,
    properties: {
      Status: {
        select: {
          name: 'Completed'
        }
      }
    }
  });
  console.log(response);
})();

Retrieve a Block

This feature allows you to retrieve information about a specific block in Notion. You need to provide the block ID.

const { Client } = require('@notionhq/client');

const notion = new Client({ auth: process.env.NOTION_API_KEY });

(async () => {
  const blockId = 'your-block-id';
  const response = await notion.blocks.retrieve({ block_id: blockId });
  console.log(response);
})();

Other packages similar to @notionhq/client

Keywords

FAQs

Package last updated on 13 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc