Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions examples/data-sources/retrieve/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
68 changes: 68 additions & 0 deletions examples/views/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* 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: databaseId,
}).argv;

(async () => {
const params = {
data_source_id: argv.dataSourceId,
name: 'My New View',
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
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);
})();
22 changes: 22 additions & 0 deletions examples/views/delete.js
Original file line number Diff line number Diff line change
@@ -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);
})();
24 changes: 24 additions & 0 deletions examples/views/list.js
Original file line number Diff line number Diff line change
@@ -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);
})();
22 changes: 22 additions & 0 deletions examples/views/read.js
Original file line number Diff line number Diff line change
@@ -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);
})();
39 changes: 39 additions & 0 deletions examples/views/update.js
Original file line number Diff line number Diff line change
@@ -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);
})();