Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
notion-api-js
Advanced tools
![npm](https://img.shields.io/npm/v/notion-api-js.svg) ![npm bundle size](https://img.shields.io/bundlephobia/min/notion-api-js.svg)
This repository contains an unofficial port of the Notion API to Node.js. Important: It only works in the backend using Node.js and not in a client-side environment.
IMPORTANT: You need a token to use the Notion API. You can obtain one by reading your local cookie. You can find instructions for that below.
You can either use npm
or yarn
to install it:
npm i --save notion-api-js
yarn add notion-api-js
To create an instance, simply pass an object with the token you read from the cookie:
// ES Modules syntax
import Notion from "notion-api-js";
// require syntax
const Notion = require("notion-api-js").default;
const notion = new Notion({
token: "YOUR_TOKEN_V2"
});
You can also provide options for the HTML parsing:
const notion = new Notion({
token: "YOUR_TOKEN_V2",
options: {
colors: {
orange: 'CSS COLOR HERE'
},
pageUrl: 'ABSOLUTE PAGE URL (e.g. /posts/'),
}
});
Right now there is no official way of accessing the Notion API but there is a little work-around to get your credentials.
You need to have an account on Notion.so and need to be logged in.
Most of the modern web browsers support inspecting cookies visually using the browser's devtools. You can read how to do it in your browser here:
After you found the Notion.so cookie, look for an entry called token_v2
. It is the necessary credential for the Notion
instance. Simply copy it into your code when you create the instance.
The options are optionally passed to the instance as a parameter. Those options contain information on how the HTML will be parsed and returned using the instance methods.
Contains definitions for the colors. If this option is omitted the default HTML colors like orange, pink and blue are used. You can change this behavior by passing an object containing color definitions. Example:
options: {
colors: {
red: 'tomato',
blue: 'rgb(100, 149, 237)',
purple: '#9933cc',
}
}
Possible colors are:
The PageUrl is the string passed to the <a>
tag and is used to build the href of it. The id is inserted after the passed string.
By default it looks like this /page?id=
, which results in <a href="/page?id=SOME_ID">Hello World</a>
Gets all pages of the user by the userId passed to the Notion
instance. All pages are parsed to HTML.
Example
notion.getPages().then(pages => {
// Your Code here
});
Gets a Notion page by the pageId and returns the parsed HTML.
Parameters:
Parameter | Type | Opt/Required |
---|---|---|
pageId | string | Required |
Example
notion.getPageById("pageId").then(page => {
// Your code here
});
Gets a Notion page by the given pageId and all subpages of that page. Useful if you want to use a homepage.
Parameters:
Parameter | Type | Opt/Required |
---|---|---|
pageId | string | Required |
Example
notion.getPagesByIndexId("pageId").then(page => {
// Your code here
});
Gets the HTML for all pages.
notion.getAllHTML().then(html => {
// Your Ccode here
});
It's really WIP right now but I would highly appreciate if you would like to contribute to the project. Just fork this repository and create a PR 😄
FAQs
![npm](https://img.shields.io/npm/v/notion-api-js.svg) ![npm bundle size](https://img.shields.io/bundlephobia/min/notion-api-js.svg)
The npm package notion-api-js receives a total of 10 weekly downloads. As such, notion-api-js popularity was classified as not popular.
We found that notion-api-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.