@andrzejchm/notion-cli 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,19 +1,22 @@
1
1
  # notion-cli
2
2
 
3
- > Read Notion pages and databases from your terminal — built for AI coding agents and developers.
3
+ > Read and write Notion pages from your terminal — built for AI coding agents and developers.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@andrzejchm/notion-cli.svg?style=flat&color=4B78E6)](https://www.npmjs.com/package/@andrzejchm/notion-cli)
6
+ [![homebrew tap](https://img.shields.io/badge/homebrew-andrzejchm%2Fnotion--cli-orange?style=flat&logo=homebrew)](https://github.com/andrzejchm/homebrew-notion-cli)
6
7
  [![Node.js >=22](https://img.shields.io/badge/node-%3E%3D22-brightgreen?style=flat)](https://nodejs.org)
7
8
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
8
9
 
9
10
  ```bash
10
- npm install -g @andrzejchm/notion-cli
11
- notion init # paste your Notion integration token once
12
- ```
11
+ # Homebrew (recommended)
12
+ brew tap andrzejchm/notion-cli
13
+ brew install notion-cli
13
14
 
14
- ![notion-cli demo](docs/demo.gif)
15
+ # npm (alternative)
16
+ npm install -g @andrzejchm/notion-cli
15
17
 
16
- ---
18
+ notion auth login # choose your auth method
19
+ ```
17
20
 
18
21
  ## For AI Agents
19
22
 
@@ -23,11 +26,18 @@ Fetch and follow instructions from https://raw.githubusercontent.com/andrzejchm/
23
26
 
24
27
  ---
25
28
 
29
+ ![notion-cli demo](docs/demo.gif)
30
+
31
+ ---
32
+
26
33
  ## Features
27
34
 
28
35
  - **`notion search`** — find any page or database by title
29
36
  - **`notion read`** — render any page as full-fidelity markdown
30
37
  - **`notion db query`** — filter, sort, and select columns from any database
38
+ - **`notion append`** — append markdown content to an existing page
39
+ - **`notion create-page`** — create a new page with markdown body, prints URL to stdout
40
+ - **`notion comment`** — add a comment to a page
31
41
  - **Agent-friendly** — plain text tables by default; `--json` for machine-readable output
32
42
  - **Flexible auth** — interactive setup or `NOTION_API_TOKEN` env var
33
43
  - **Accepts URLs** — pass full Notion URLs anywhere an ID is expected
@@ -47,8 +57,18 @@ notion db query "$DB_ID" --filter "Status=In Progress" --sort "Priority:asc"
47
57
  # Get JSON output for scripting / AI agents
48
58
  notion db query "$DB_ID" --filter "Status=Done" | jq '.[] | .properties.Title'
49
59
 
50
- # Inspect a database schema before querying
51
- notion db schema "$DB_ID"
60
+ # Append markdown blocks to an existing page
61
+ notion append "$PAGE_ID" -m "## Summary\nGenerated by AI agent."
62
+
63
+ # Create a new page and capture its URL
64
+ URL=$(notion create-page --parent "$PAGE_ID" --title "Meeting Notes" -m "# Agenda\n- Item 1")
65
+ echo "Created: $URL"
66
+
67
+ # Pipe content to a new page
68
+ my-summarize-command | notion create-page --parent "$PAGE_ID" --title "Auto Summary"
69
+
70
+ # Add a comment to a page
71
+ notion comment "$PAGE_ID" -m "Reviewed and approved."
52
72
 
53
73
  # List everything your integration can access
54
74
  notion ls
@@ -60,7 +80,11 @@ notion ls
60
80
 
61
81
  | Command | Description |
62
82
  |---------|-------------|
63
- | `notion init` | Set up your Notion integration token |
83
+ | `notion auth login` | Interactive auth setup choose OAuth or integration token |
84
+ | `notion auth logout` | Remove a profile and all its credentials |
85
+ | `notion auth status` | Show current auth state |
86
+ | `notion auth list` | List all saved profiles |
87
+ | `notion auth use <name>` | Switch the active profile |
64
88
  | `notion search <query>` | Search pages and databases by title |
65
89
  | `notion ls` | List all accessible pages and databases |
66
90
  | `notion open <id\|url>` | Open a page in your browser |
@@ -69,7 +93,9 @@ notion ls
69
93
  | `notion db query <id\|url>` | Query database entries with filtering and sorting |
70
94
  | `notion users` | List workspace members |
71
95
  | `notion comments <id\|url>` | Read page comments |
72
- | `notion profile list\|use\|remove` | Manage multiple auth profiles |
96
+ | `notion comment <id\|url> -m <text>` | Add a comment to a page |
97
+ | `notion append <id\|url> -m <markdown>` | Append markdown blocks to a page |
98
+ | `notion create-page --parent <id\|url> --title <title>` | Create a new page, prints URL |
73
99
  | `notion completion bash\|zsh\|fish` | Install shell tab completion |
74
100
 
75
101
  ### `notion db query` flags
@@ -98,36 +124,90 @@ The CLI auto-detects your context:
98
124
 
99
125
  ## Authentication
100
126
 
127
+ Two authentication methods are available. If both are configured, **OAuth takes precedence** for API calls.
128
+
129
+ Start with the interactive setup:
130
+
101
131
  ```bash
102
- # Interactive setup (recommended for first-time use)
103
- notion init
132
+ notion auth login # choose OAuth or integration token
133
+ ```
104
134
 
105
- # Environment variable (CI, Docker, agents)
106
- export NOTION_API_TOKEN=ntn_your_token_here
135
+ ### Tradeoff comparison
136
+
137
+ | Method | Best for | Write attribution | Requires |
138
+ |--------|----------|-------------------|----------|
139
+ | **OAuth user login** | Write-heavy workflows, personal use | Your Notion account | Browser (or `--manual` for headless) |
140
+ | **Integration token** | CI, Docker, automated agents | Integration bot | Token from notion.so/profile/integrations |
141
+ | `NOTION_API_TOKEN` env var | CI/Docker without config files | Integration bot | Token set in environment |
142
+
143
+ **Priority:** `NOTION_API_TOKEN` env var → OAuth token → integration token (first found wins)
144
+
145
+ ### OAuth user login
107
146
 
108
- # Multiple workspaces
109
- notion init # saves as "default"
110
- notion profile list
111
- notion profile use <name>
147
+ ```bash
148
+ notion auth login # interactive selector — choose OAuth
149
+ notion auth login --manual # headless: prints URL, prompts to paste redirect
150
+ notion auth status # show current auth state
151
+ notion auth logout # remove profile and credentials
152
+ ```
153
+
154
+ Comments and pages are attributed to your **actual Notion account**.
155
+ Access tokens expire after ~1 hour and are refreshed automatically.
156
+
157
+ ### Integration token
158
+
159
+ ```bash
160
+ notion auth login # interactive selector — choose "Integration token"
161
+
162
+ # or: environment variable (CI, Docker, agents — no profile needed)
163
+ export NOTION_API_TOKEN=ntn_your_token_here
112
164
  ```
113
165
 
166
+ Works everywhere (CI, headless, agents). Write operations are attributed to the **integration bot**.
167
+ You must manually connect the integration to each page (`⋯` → Add connections).
168
+
114
169
  Token format: starts with `ntn_` (new) or `secret_` (legacy integrations).
115
170
  Get a token: [notion.so/profile/integrations/internal](https://www.notion.so/profile/integrations/internal)
116
171
 
172
+ ### Profile management
173
+
174
+ ```bash
175
+ notion auth list # list all profiles
176
+ notion auth use <name> # switch active profile
177
+ notion auth logout # remove a profile (interactive selector)
178
+ notion auth logout --profile <name> # remove specific profile directly
179
+ ```
180
+
181
+ ### Integration capabilities
182
+
183
+ Read-only commands (`search`, `read`, `db query`, etc.) need **Read content** only.
184
+
185
+ Write commands require additional capabilities — enable in your integration settings ([notion.so/profile/integrations/internal](https://www.notion.so/profile/integrations/internal) → your integration → **Capabilities**):
186
+
187
+ | Command | Required capabilities |
188
+ |---------|----------------------|
189
+ | `notion append` | Read content, Insert content |
190
+ | `notion create-page` | Read content, Insert content |
191
+ | `notion comment` | Read content, Insert content, Read comments, Insert comments |
192
+
117
193
  ---
118
194
 
119
195
  ## Troubleshooting
120
196
 
121
197
  **Page not found (404):** Share the page with your integration — open the page → `⋯` → **Add connections**.
122
198
 
123
- **Unauthorized (401):** Run `notion init` to reconfigure, or check your `NOTION_API_TOKEN`.
199
+ **Unauthorized (401):** Run `notion auth login` to reconfigure, or check your `NOTION_API_TOKEN`.
124
200
 
125
201
  **Search returns nothing:** Search is title-only. The page must also be shared with your integration.
126
202
 
127
203
  **Empty database query:** Run `notion db schema <id>` first to see valid property names and values.
128
204
 
205
+ **`notion comment` returns "Insufficient permissions":** Enable **Read comments** and **Insert comments** in your integration capabilities: [notion.so/profile/integrations/internal](https://www.notion.so/profile/integrations/internal) → your integration → Capabilities.
206
+
207
+ **`notion append` / `notion create-page` returns "Insufficient permissions":** Enable **Insert content** in your integration capabilities.
208
+
129
209
  ---
130
210
 
131
211
  ## License
132
212
 
133
- MIT © [Andrzej Chm](https://github.com/andrzejchm)
213
+ MIT © [Andrzej Chmielewski](https://github.com/andrzejchm)