From b4734276444fdc13445dac64b29efce022d3a1e9 Mon Sep 17 00:00:00 2001 From: Benjamin Borowski Date: Mon, 16 Mar 2026 14:53:04 -0700 Subject: [PATCH 1/3] basic views endpoints testing --- examples/data-sources/retrieve/index.js | 8 +++- examples/views/README.md | 20 ++++++++ examples/views/create.js | 62 +++++++++++++++++++++++++ examples/views/delete.js | 22 +++++++++ examples/views/list.js | 24 ++++++++++ examples/views/read.js | 22 +++++++++ examples/views/update.js | 39 ++++++++++++++++ 7 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 examples/views/README.md create mode 100644 examples/views/create.js create mode 100644 examples/views/delete.js create mode 100644 examples/views/list.js create mode 100644 examples/views/read.js create mode 100644 examples/views/update.js diff --git a/examples/data-sources/retrieve/index.js b/examples/data-sources/retrieve/index.js index 838cb57..3a321b0 100644 --- a/examples/data-sources/retrieve/index.js +++ b/examples/data-sources/retrieve/index.js @@ -7,8 +7,12 @@ const { notion, yargs } = require('../../shared'); const { log } = require('../../shared/utils'); -const dataSourceId = 'acce37c4c4ee4b78aa786a944c2577cf'; -const argv = yargs.default({ dataSourceId }).argv; +const dataSourceId = '45808fcd2698412a97df10e19c36cc21'; +const argv = yargs.option('dataSourceId', { + alias: 'd', + describe: 'The ID of the data source to create the page in', + default: dataSourceId, +}).argv; (async () => { const ds = await notion.dataSources.retrieve({ diff --git a/examples/views/README.md b/examples/views/README.md new file mode 100644 index 0000000..8f66058 --- /dev/null +++ b/examples/views/README.md @@ -0,0 +1,20 @@ +# Views + +## Endpoints + +### Basics + +[x] GET /v1/views?database_id=DATABASE_ID - List all views for a database +[x] GET /v1/views/VIEW_ID - Retrieve a specific view +[x] PATCH /v1/views/VIEW_ID - Update a view +[x] DELETE /v1/views/VIEW_ID - Delete a view + +### Requires bugfix + +[ ] POST /v1/views - Create a new view + +### Queries + +[ ] POST /v1/views/VIEW_ID/queries - Query a view (create query) +[ ] GET /v1/views/VIEW_ID/queries/QUERY_ID - Paginate query results +[ ] DELETE /v1/views/VIEW_ID/queries/QUERY_ID - Cleanup query diff --git a/examples/views/create.js b/examples/views/create.js new file mode 100644 index 0000000..f4b99dc --- /dev/null +++ b/examples/views/create.js @@ -0,0 +1,62 @@ +/** + * Arguments: + * + * --data-source-id, -d: ID of the data source to create a view for + * --database-id, -b: ID of the database to create a top-level view in (optional) + */ + +const notionAPI = require('../shared/notion-api'); +const { log } = require('../shared/utils'); +const { yargs } = require('../shared'); + +const dataSourceId = '45808fcd-2698-412a-97df-10e19c36cc21'; +const databaseId = '3101c1cce3f380b2afa2dd5e35566bd2'; + +const argv = yargs + .option('dataSourceId', { + alias: 'd', + default: dataSourceId, + }) + .option('databaseId', { + alias: 'b', + default: dataSourceId, + }).argv; + +(async () => { + const params = { + data_source_id: argv.dataSourceId, + name: 'My New View', + type: 'list', + // TODO: implement when this endpoint is fixed + // filter: { + // }, + // sorts: [ + // { + // property: 'Date', + // direction: 'ascending', + // }, + // ], + // configuration: { + // type: 'list', + // properties: [ + // { + // property_id: 'Status', + // visible: true, + // status_show_as: 'checkbox', + // width: 0, + // }, + // ], + // }, + }; + + // Add database_id if provided for top-level views + if (argv.databaseId) { + params.database_id = argv.databaseId; + } + + // TODO: this is failing, looks like some conflict with the data_source_id and database_id + // TODO: test again when issues with UUID fixed + const { data: view } = await notionAPI.post('/views', params); + + log(view); +})(); diff --git a/examples/views/delete.js b/examples/views/delete.js new file mode 100644 index 0000000..2488bed --- /dev/null +++ b/examples/views/delete.js @@ -0,0 +1,22 @@ +/** + * Arguments: + * + * --view-id: ID of the view to delete + */ + +const notionAPI = require('../shared/notion-api'); +const { log } = require('../shared/utils'); +const { yargs } = require('../shared'); + +const viewId = '3101c1cce3f3804d8481000c37e852fa'; + +const argv = yargs.option('viewId', { + alias: 'v', + default: viewId, +}).argv; + +(async () => { + const { data: view } = await notionAPI.delete(`/views/${argv.viewId}`); + + log(view); +})(); diff --git a/examples/views/list.js b/examples/views/list.js new file mode 100644 index 0000000..69a23e4 --- /dev/null +++ b/examples/views/list.js @@ -0,0 +1,24 @@ +/** + * Arguments: + * + * --database-id: ID of the database to list views of + */ + +const notionAPI = require('../shared/notion-api'); +const { log } = require('../shared/utils'); +const { yargs } = require('../shared'); + +const databaseId = '3101c1cce3f380b2afa2dd5e35566bd2'; + +const argv = yargs.option('databaseId', { + alias: 'd', + default: databaseId, +}).argv; + +(async () => { + const { data: views } = await notionAPI.get('/views', { + params: { database_id: argv.databaseId }, + }); + + log(views); +})(); diff --git a/examples/views/read.js b/examples/views/read.js new file mode 100644 index 0000000..abcb659 --- /dev/null +++ b/examples/views/read.js @@ -0,0 +1,22 @@ +/** + * Arguments: + * + * --view-id: ID of the view to retrieve + */ + +const notionAPI = require('../shared/notion-api'); +const { log } = require('../shared/utils'); +const { yargs } = require('../shared'); + +const viewId = '3101c1cce3f3804d8481000c37e852fa'; + +const argv = yargs.option('viewId', { + alias: 'v', + default: viewId, +}).argv; + +(async () => { + const { data: view } = await notionAPI.get(`/views/${argv.viewId}`); + + log(view); +})(); diff --git a/examples/views/update.js b/examples/views/update.js new file mode 100644 index 0000000..b67925b --- /dev/null +++ b/examples/views/update.js @@ -0,0 +1,39 @@ +/** + * Arguments: + * + * --view-id: ID of the view to update + */ + +const notionAPI = require('../shared/notion-api'); +const { log } = require('../shared/utils'); +const { yargs } = require('../shared'); + +const viewId = '3101c1cce3f3804d8481000c37e852fa'; + +const argv = yargs.option('v', { + alias: 'viewId', + default: view, +}).argv; + +(async () => { + const { data: view } = await notionAPI.patch(`/views/${argv.viewId}`, { + name: 'Todo', + sorts: [ + { + property: 'Date', + direction: 'ascending', + }, + ], + configuration: { + type: 'table', + // TODO: group_by person not implemented? + // group_by: { + // type: 'person', + // id: '%3Cji~', + // sort: 'ascending', + // }, + }, + }); + + log(view); +})(); From 62c13ba8f8cc2cc398148d9c8fda6def2f00ae05 Mon Sep 17 00:00:00 2001 From: Benjamin Borowski Date: Mon, 16 Mar 2026 14:54:45 -0700 Subject: [PATCH 2/3] readme can be pr desc --- examples/views/README.md | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 examples/views/README.md diff --git a/examples/views/README.md b/examples/views/README.md deleted file mode 100644 index 8f66058..0000000 --- a/examples/views/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Views - -## Endpoints - -### Basics - -[x] GET /v1/views?database_id=DATABASE_ID - List all views for a database -[x] GET /v1/views/VIEW_ID - Retrieve a specific view -[x] PATCH /v1/views/VIEW_ID - Update a view -[x] DELETE /v1/views/VIEW_ID - Delete a view - -### Requires bugfix - -[ ] POST /v1/views - Create a new view - -### Queries - -[ ] POST /v1/views/VIEW_ID/queries - Query a view (create query) -[ ] GET /v1/views/VIEW_ID/queries/QUERY_ID - Paginate query results -[ ] DELETE /v1/views/VIEW_ID/queries/QUERY_ID - Cleanup query From a573b21f65117dcab87f1aba0d24c71997b6b165 Mon Sep 17 00:00:00 2001 From: Benjamin Borowski Date: Mon, 16 Mar 2026 15:11:56 -0700 Subject: [PATCH 3/3] props --- examples/views/create.js | 50 ++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/examples/views/create.js b/examples/views/create.js index f4b99dc..e502030 100644 --- a/examples/views/create.js +++ b/examples/views/create.js @@ -19,34 +19,40 @@ const argv = yargs }) .option('databaseId', { alias: 'b', - default: dataSourceId, + default: databaseId, }).argv; (async () => { const params = { data_source_id: argv.dataSourceId, name: 'My New View', - type: 'list', - // TODO: implement when this endpoint is fixed - // filter: { - // }, - // sorts: [ - // { - // property: 'Date', - // direction: 'ascending', - // }, - // ], - // configuration: { - // type: 'list', - // properties: [ - // { - // property_id: 'Status', - // visible: true, - // status_show_as: 'checkbox', - // width: 0, - // }, - // ], - // }, + type: 'table', + position: { + type: 'start', + }, + sorts: [ + { + property: 'Date', + direction: 'ascending', + }, + ], + configuration: { + type: 'table', + // TODO: this is not working + properties: [ + { + property_id: '%7DUlu', + visible: true, + status_show_as: 'checkbox', + width: 0, + }, + { + property_id: 'k%5CSg', + visible: true, + }, + ], + subtasks: null, + }, }; // Add database_id if provided for top-level views