Code Monkey home page Code Monkey logo

notion-cli's Introduction

notion-cli

This is a Notion CLI tool written by TypeScript. And some commands can be executed in interactive mode.

Features

  • Support for multiple output formats including csv and JSON
  • Support interactive mode for CRUD operation.

Quick Start

Retrieves a page object using the ID specified.

$ export NOTION_TOKEN=secret_xxx...
$ notion-cli page retrieve <PAGE_ID>

Using docker image:

$ docker run -e NOTION_TOKEN=secret_xxx... ghcr.io/litencatt/notion-cli page retrieve <PAGE_ID>

# -it flag is required to run interactive mode using docker
$ docker run -it -e NOTION_TOKEN=secret_xxx... ghcr.io/litencatt/notion-cli db retrieve

Multiple output formats

oclif ux.table supported output formats are table, csv, json, yaml. And notion-cli supports output raw json response with --raw.

default: table

Output columns are only title, object, id, url now.

$ notion-cli page retireve c77dbaf240174ea1ac1e93a87269f3ea
 Title      Object Id                                   Url
 ────────── ────── ──────────────────────────────────── ─────────────────────────────────────────────────────────────────
 Page title page   c77dbaf2-4017-4ea1-ac1e-93a87269f3ea https://www.notion.so/Page-title-c77dbaf240174ea1ac1e93a87269f3ea

csv

$ notion-cli page retrieve c77dbaf240174ea1ac1e93a87269f3ea --output csv
Title,Object,Id,Url
Page title,page,c77dbaf2-4017-4ea1-ac1e-93a87269f3ea,https://www.notion.so/Page-title-c77dbaf240174ea1ac1e93a87269f3ea

json

$ notion-cli page retrieve c77dbaf240174ea1ac1e93a87269f3ea --output json
[
  {
    "title": "Page title",
    "object": "page",
    "id": "c77dbaf2-4017-4ea1-ac1e-93a87269f3ea",
    "url": "https://www.notion.so/Page-title-c77dbaf240174ea1ac1e93a87269f3ea"
  }
]

yaml

$ notion-cli page retrieve c77dbaf240174ea1ac1e93a87269f3ea --output yaml
- title: Page title
  object: page
  id: c77dbaf2-4017-4ea1-ac1e-93a87269f3ea
  url: 'https://www.notion.so/Page-title-c77dbaf240174ea1ac1e93a87269f3ea'

Raw json

This flag returns the raw json response from the Notion API, so you can get all the data for a given resource. You can also process the response using jq or other tools.

$ notion-cli page retrieve c77dbaf240174ea1ac1e93a87269f3ea --raw | head
{
  "object": "page",
  "id": "c77dbaf2-4017-4ea1-ac1e-93a87269f3ea",
  "created_time": "2023-05-07T09:08:00.000Z",
  "last_edited_time": "2023-08-15T01:08:00.000Z",
  "created_by": {
    "object": "user",
    "id": "3555ae80-4588-4514-bb6b-2ece534157de"
  },
  "last_edited_by": {
...

Interactive mode in db command

  1. Start interactive mode execute db command without args
  2. Select a database from list
  3. Build filter conditions
    • And then you can choose whether to save the conditions to a json file or not.
  4. Query to db with the filter conditions
  5. Saved json files can be reused by passing them as flags at the next execution.

interactive-mode

Install

npm:

$ npm install -g @litencatt/notion-cli

docker:

$ docker pull ghcr.io/litencatt/notion-cli

Commands

Supported API and functions

Endpoint API Support multi-format* interactive mode
Authentication Create a token      
Blocks Append a block children o o  
Blocks Retrieve a block o o  
Blocks Retrieve a block children o o  
Blocks Update a block o o  
Blocks Delete a block o o  
Pages Create a page o o  
Pages Retrieve a page o o  
Pages Update a page o o  
Database Create a database o o o
Database Retrieve a database o o o
Database Update a database o o o
Database Query a database o o o
Users List all users o o  
Users Retrieve a user o o  
Users Retrieve your token's bot user o o  
Comments Create a comment      
Comments Retrieve a comment      
Search Search by title o o

* multi-format NOT supported commands output only raw json response

notion-cli's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar litencatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

donvargax

notion-cli's Issues

Nonexistent flag '-o'

The help text has this sample command:

Query a db with a specific database_id and output format
$ notion-cli db query -o csv DATABASE_ID

But when I try this, I get:
Error: Nonexistent flag: -o
See more help with --help

This is:
» notion-cli --version
@litencatt/notion-cli/0.14.1 wsl-x64 node-v20.10.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.