Home

Awesome

notion-sdk-deno

deno doc

nest badge

Deno Notion SDK

Note: The Notion API is in beta phase

Supported APIs

If this package needs update, please raise an issue or a PR.

Requirement

Example

// pick 1 to import
import { Notion } from "https://deno.land/x/notion_sdk_deno@v0.3.9/mod.ts";
import { Notion } from "https://x.nest.land/notion-sdk-deno@0.3.9/mod.ts";
import { Notion } from "https://denopkg.com/yeukfei02/notion-sdk-deno@v0.3.9/mod.ts";
const notion = new Notion({
  token: <yourNotionToken>,
});

getUsers

const userList = await notion.getUsers();
console.log("userList = ", userList);
// userList
userList = [
  {
    object: "user",
    id: "17001963-9201-4d13-bf2d-9f842304d44a",
    name: "Donald Wu",
    avatar_url: null,
    type: "person",
    person: { email: "yeukfei02@gmail.com" },
  },
  {
    object: "user",
    id: "e5a677d2-20b8-4307-b21a-fca586918675",
    name: "notion-api",
    avatar_url: null,
    type: "bot",
    bot: {},
  },
];

getUserById

const user = await notion.getUserById(userId);
console.log("user = ", user);
// user
user =  {
  object: "user",
  id: "17001963-9201-4d13-bf2d-9f842304d44a",
  name: "Donald Wu",
  avatar_url: null,
  type: "person",
  person: { email: "yeukfei02@gmail.com" }
}

getDatabases

const databases = await notion.getDatabases();
console.log("databases = ", databases);

getDatabaseById

const database = await notion.getDatabaseById();
console.log("database = ", database);

getPageById

const page = await notion.getPageById(pageId);
console.log("page = ", page);
// page
page = {
  object: "page",
  id: "33bfc7be-6511-4b5e-9db2-4e64dd98d855",
  created_time: "2020-06-21T02:18:34.784Z",
  last_edited_time: "2021-05-20T09:00:00.000Z",
  parent: { type: "workspace", workspace: true },
  archived: false,
  properties: { title: { id: "title", type: "title", title: [ [Object] ] } }
}

getPageChildrenById

const pageChildren = await notion.getPageChildrenById(blockId);
console.log("pageChildren = ", pageChildren);
// pageChildren
pageChildren = [
  {
    object: "block",
    id: "25d74f8a-19d1-47af-8e62-d46f546feae0",
    created_time: "2020-06-21T02:18:34.784Z",
    last_edited_time: "2020-06-21T02:18:34.784Z",
    has_children: false,
    type: "unsupported",
    unsupported: {}
  },
  {
    object: "block",
    id: "a84ef5ba-75d7-4b21-a7e3-529871d70314",
    created_time: "2020-07-25T06:29:00.000Z",
    last_edited_time: "2020-09-13T03:13:00.000Z",
    has_children: false,
    type: "paragraph",
    paragraph: { text: [ [Object] ] }
  },
  ...
]

Testing and run

// run test case
$ deno test --allow-read --allow-env --allow-net

// linter
$ deno lint --unstable

// format code
$ deno fmt