@andrzejchm/notion-cli 0.1.2 → 0.2.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.
@@ -0,0 +1,77 @@
1
+ # notion-cli for OpenCode
2
+
3
+ Complete guide for using notion-cli with [OpenCode](https://opencode.ai).
4
+
5
+ ## Quick Install
6
+
7
+ Tell OpenCode:
8
+
9
+ ```
10
+ Fetch and follow instructions from https://raw.githubusercontent.com/andrzejchm/notion-cli/main/docs/README.opencode.md
11
+ ```
12
+
13
+ ## Installation
14
+
15
+ ### 1. Install the CLI
16
+
17
+ ```bash
18
+ # Homebrew (recommended)
19
+ brew tap andrzejchm/notion-cli
20
+ brew install notion-cli
21
+
22
+ # npm (alternative)
23
+ npm install -g @andrzejchm/notion-cli
24
+ ```
25
+
26
+ Homebrew bundles Node.js automatically. npm requires Node.js ≥ 22.
27
+
28
+ ### 2. Install the skill file
29
+
30
+ ```bash
31
+ mkdir -p ~/.config/opencode/skills/using-notion-cli
32
+ curl -fsSL https://raw.githubusercontent.com/andrzejchm/notion-cli/main/docs/skills/using-notion-cli/SKILL.md \
33
+ -o ~/.config/opencode/skills/using-notion-cli/SKILL.md
34
+ ```
35
+
36
+ ### 3. Authenticate
37
+
38
+ **Internal integration token** (read-only and automated agents):
39
+ ```bash
40
+ notion init
41
+ # or: export NOTION_API_TOKEN=ntn_your_token_here
42
+ ```
43
+
44
+ Get a token: https://www.notion.so/profile/integrations/internal
45
+
46
+ **OAuth login** (recommended for write operations — attributes comments/pages to your user):
47
+ ```bash
48
+ notion auth login # opens browser
49
+ notion auth login --manual # headless: prints URL, paste redirect back
50
+ ```
51
+
52
+ ### 4. Share pages with your integration
53
+
54
+ Open any Notion page → `⋯` → **Add connections** → select your integration.
55
+
56
+ ### 5. Verify
57
+
58
+ ```bash
59
+ notion --version # CLI installed
60
+ notion ls # auth works
61
+ ```
62
+
63
+ Restart OpenCode after installing. The skill is now discoverable via the `skill` tool.
64
+
65
+ ## Updating
66
+
67
+ ```bash
68
+ # Homebrew
69
+ brew upgrade notion-cli
70
+
71
+ # npm
72
+ npm install -g @andrzejchm/notion-cli
73
+
74
+ # Update skill file (either install method)
75
+ curl -fsSL https://raw.githubusercontent.com/andrzejchm/notion-cli/main/docs/skills/using-notion-cli/SKILL.md \
76
+ -o ~/.config/opencode/skills/using-notion-cli/SKILL.md
77
+ ```
package/docs/demo.gif ADDED
Binary file
package/docs/demo.tape ADDED
@@ -0,0 +1,26 @@
1
+ Output demo.gif
2
+
3
+ Set FontSize 14
4
+ Set Width 800
5
+ Set Height 400
6
+ Set Theme "Dracula"
7
+ Set Padding 20
8
+ Set TypingSpeed 40ms
9
+ Env PATH "/Users/andrzejchm/.nvm/versions/node/v24.13.0/bin:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin"
10
+
11
+ Sleep 500ms
12
+
13
+ Type "notion search demo"
14
+ Sleep 500ms
15
+ Enter
16
+ Sleep 3s
17
+
18
+ Type "notion read 314e707e00688087b2eef0af1de30033"
19
+ Sleep 500ms
20
+ Enter
21
+ Sleep 4s
22
+
23
+ Type "notion db schema 314e707e-0068-8035-8e42-000b2f2ded85"
24
+ Sleep 500ms
25
+ Enter
26
+ Sleep 3s
Binary file
@@ -0,0 +1,186 @@
1
+ ---
2
+ name: using-notion-cli
3
+ description: Reads and writes Notion pages using the `notion` CLI tool. Use when accessing Notion content, searching workspace pages, querying database entries, reading page markdown, appending content, creating pages, or adding comments from the terminal or within automated workflows.
4
+ license: MIT
5
+ compatibility: opencode
6
+ ---
7
+
8
+ ## Setup
9
+
10
+ Install once:
11
+ ```bash
12
+ npm install -g @andrzejchm/notion-cli
13
+ notion init # enter your Notion integration token
14
+ ```
15
+
16
+ Or set env var (preferred for CI/agents):
17
+ ```bash
18
+ export NOTION_API_TOKEN=ntn_your_token_here
19
+ ```
20
+
21
+ Get token: https://www.notion.so/profile/integrations/internal
22
+
23
+ Pages must be shared with your integration: open page → `⋯` → **Add connections**.
24
+
25
+ **Integration capabilities** (set at notion.so/profile/integrations/internal → your integration → Capabilities):
26
+ - Read-only commands: **Read content** only
27
+ - `notion append`, `notion create-page`: also need **Insert content**
28
+ - `notion comment`: also need **Read comments** + **Insert comments**
29
+
30
+ ---
31
+
32
+ ## Authentication
33
+
34
+ Two auth methods are available. If both are configured, **OAuth takes precedence**.
35
+
36
+ ### Internal integration token (default)
37
+ Set up via `notion init`. Comments and pages created via this method are attributed to the **integration bot** (not a real user).
38
+
39
+ ```bash
40
+ notion init # interactive setup (requires TTY)
41
+ export NOTION_API_TOKEN=ntn_… # or via environment variable
42
+ ```
43
+
44
+ ### OAuth user login (recommended for write operations)
45
+ Set up via `notion auth login`. Comments and pages are attributed to your **actual Notion user account**.
46
+
47
+ ```bash
48
+ notion auth login [--profile <name>] [--manual] # opens browser OAuth flow; --manual for headless
49
+ notion auth logout [--profile <name>] # removes OAuth tokens
50
+ notion auth status [--profile <name>] # shows current auth state
51
+ ```
52
+
53
+ **Headless / remote servers:** `notion auth login --manual` prints the auth URL for you to open in a local browser, then prompts you to paste the redirect URL back.
54
+
55
+ ---
56
+
57
+ ## Output Modes
58
+
59
+ | Context | Default | Override |
60
+ |---------|---------|----------|
61
+ | Terminal (TTY) | Formatted tables | `--json` |
62
+ | Piped / agent | Plain text tables | `--json` |
63
+
64
+ `notion read` always outputs **markdown** — in terminal and when piped.
65
+
66
+ Pipe any command to get JSON:
67
+ ```bash
68
+ notion search "query" | jq '.[0].id'
69
+ notion ls | jq '.[] | select(.type == "database")'
70
+ ```
71
+
72
+ ---
73
+
74
+ ## Commands
75
+
76
+ ### Search & Discovery
77
+
78
+ ```bash
79
+ notion search "query" # search all pages/databases by title
80
+ notion search "query" --type page # pages only
81
+ notion search "query" --type database # databases only
82
+ notion ls # list everything accessible to integration
83
+ notion users # list workspace members
84
+ notion comments <id|url> # list page comments
85
+ notion open <id|url> # open in browser
86
+ ```
87
+
88
+ ### Reading Pages
89
+
90
+ ```bash
91
+ notion read <id|url> # markdown (always, even when piped)
92
+ notion read <id|url> --json # raw Notion JSON block tree
93
+ ```
94
+
95
+ ### Database Operations
96
+
97
+ ```bash
98
+ notion db schema <id|url> # inspect properties + valid values
99
+ notion db query <id|url> # all rows
100
+ notion db query <id|url> --filter "Status=Done" # filter (repeatable)
101
+ notion db query <id|url> --sort "Created:desc" # sort (repeatable)
102
+ notion db query <id|url> --columns "Title,Status" # limit columns
103
+ notion db query <id|url> --json | jq '.[] | .properties'
104
+ ```
105
+
106
+ ### Write Operations
107
+
108
+ ```bash
109
+ notion append <id|url> -m "## Heading\nParagraph text" # append markdown blocks to a page
110
+ notion append <id|url> -m "$(cat notes.md)" # append file contents
111
+
112
+ notion create-page --parent <id|url> --title "Title" # title-only page
113
+ notion create-page --parent <id|url> --title "Title" -m "# Hello" # with markdown body
114
+ echo "# Content" | notion create-page --parent <id|url> --title "Title" # from stdin
115
+ URL=$(notion create-page --parent <id|url> --title "Summary" -m "...") # capture URL
116
+
117
+ notion comment <id|url> -m "Reviewed and approved." # add comment to a page
118
+ ```
119
+
120
+ ### Auth
121
+
122
+ ```bash
123
+ notion init # interactive setup (requires TTY)
124
+ notion profile list # show saved profiles
125
+ notion profile use <name> # switch active profile
126
+ notion profile remove <name> # delete a profile
127
+ ```
128
+
129
+ ---
130
+
131
+ ## ID Formats
132
+
133
+ All commands accept any of:
134
+ - `abc123def456789012345678901234ab` (32-char hex)
135
+ - `abc123de-f456-7890-1234-5678901234ab` (UUID)
136
+ - `https://www.notion.so/workspace/Page-Title-abc123` (full URL)
137
+
138
+ ---
139
+
140
+ ## Agent Patterns
141
+
142
+ ```bash
143
+ # Find page by title, read it
144
+ PAGE_ID=$(notion search "Meeting Notes" --type page | jq -r '.[0].id')
145
+ notion read "$PAGE_ID"
146
+
147
+ # Get database ID, then query with filter
148
+ DB_ID=$(notion search "Project Tracker" --type database | jq -r '.[0].id')
149
+ notion db query "$DB_ID" --filter "Status=In Progress" | jq '.[] | .properties'
150
+
151
+ # Always check schema before filtering (see valid property names/values)
152
+ notion db schema "$DB_ID"
153
+ notion db query "$DB_ID" --filter "Status=Done"
154
+
155
+ # Extract page section
156
+ notion read "$PAGE_ID" | grep -A 10 "## Action Items"
157
+
158
+ # Summarize a page and append the summary back
159
+ SUMMARY=$(notion read "$PAGE_ID" | your-summarize-command)
160
+ notion append "$PAGE_ID" -m "## AI Summary\n$SUMMARY"
161
+
162
+ # Create a page and capture its URL for further use
163
+ URL=$(notion create-page --parent "$PAGE_ID" --title "Report $(date +%Y-%m-%d)" -m "# Report\n...")
164
+ echo "Created: $URL"
165
+
166
+ # Pipe command output into a new page
167
+ my-report-command | notion create-page --parent "$PAGE_ID" --title "Auto Report"
168
+ ```
169
+
170
+ ---
171
+
172
+ ## Troubleshooting
173
+
174
+ **404 / page not found** — Share the page with your integration: page → `⋯` → **Add connections**.
175
+
176
+ **401 / unauthorized** — Run `notion init` or set `NOTION_API_TOKEN`.
177
+
178
+ **Search returns nothing** — Search is title-only. Page must be shared with integration.
179
+
180
+ **Empty db query** — Run `notion db schema <id>` to see valid property names and values.
181
+
182
+ **`notion init` fails in agent** — Requires TTY. Use `NOTION_API_TOKEN` env var instead.
183
+
184
+ **`notion comment` returns "Insufficient permissions"** — Enable **Read comments** + **Insert comments** in integration capabilities: notion.so/profile/integrations/internal → your integration → Capabilities.
185
+
186
+ **`notion append` / `notion create-page` returns "Insufficient permissions"** — Enable **Insert content** in integration capabilities.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrzejchm/notion-cli",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Read Notion pages and databases from the terminal. Built for AI agents and developers.",
5
5
  "keywords": [
6
6
  "notion",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "files": [
27
27
  "dist/",
28
- "docs/agent-skill.md",
28
+ "docs/",
29
29
  "README.md"
30
30
  ],
31
31
  "type": "module",