Skip to content

Commit ef2e4d9

Browse files
committed
Use data source and templates apis from sdk
1 parent 43e5c53 commit ef2e4d9

File tree

6 files changed

+338
-97
lines changed

6 files changed

+338
-97
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Arguments:
3+
*
4+
* --data-source-id: ID of the data source to fetch
5+
*/
6+
7+
const { notion, yargs } = require('../../shared');
8+
const { log } = require('../../shared/utils');
9+
10+
const dataSourceId = 'acce37c4c4ee4b78aa786a944c2577cf';
11+
const argv = yargs.default({ dataSourceId }).argv;
12+
13+
(async () => {
14+
const ds = await notion.dataSources.retrieve({
15+
data_source_id: argv.dataSourceId,
16+
});
17+
18+
log(ds);
19+
})();

examples/databases/retrieve/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* Arguments:
33
*
4-
* --database-id: ID of the page to fetch
4+
* --database-id: ID of the database to fetch
55
*/
66

77
const { notion, yargs } = require('../../shared');
88
const { log } = require('../../shared/utils');
99

10-
const databaseId = '87a5721f46b146dca5b3bddf414e9f00';
10+
const databaseId = '1e7abab87ee8457799c1155cf69d502a';
1111
const argv = yargs.default({ databaseId }).argv;
1212

1313
(async () => {

examples/templates/create-from.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
const notionAPI = require('../shared/notion-api');
2-
const { yargs } = require('../shared');
1+
const { notion, yargs } = require('../shared');
32
const { log } = require('../shared/utils');
43

5-
const databaseId = '1e7abab87ee8457799c1155cf69d502a';
4+
const dataSourceId = 'acce37c4c4ee4b78aa786a944c2577cf';
65
const template = 'default';
7-
const argv = yargs.default({ databaseId, template }).argv;
6+
const argv = yargs.default({ dataSourceId, template }).argv;
87

98
(async () => {
109
// Existing endpoint POST /v1/pages
@@ -18,8 +17,8 @@ const argv = yargs.default({ databaseId, template }).argv;
1817

1918
const params = {
2019
parent: {
21-
type: 'database_id',
22-
database_id: argv.databaseId,
20+
type: 'data_source_id',
21+
data_source_id: argv.dataSourceId,
2322
},
2423
properties: {
2524
Name: {
@@ -35,7 +34,7 @@ const argv = yargs.default({ databaseId, template }).argv;
3534
template,
3635
};
3736

38-
const { data: page } = await notionAPI.post('/pages', params);
37+
const page = await notion.pages.create(params);
3938

4039
log(page);
4140
})();

examples/templates/list.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
const notionAPI = require('../shared/notion-api');
1+
const { notion, yargs } = require('../shared');
22
const { log } = require('../shared/utils');
33

4-
(async () => {
5-
// Fetch data source from database
6-
const { data: database } = await notionAPI.get('/databases/1e7abab87ee8457799c1155cf69d502a');
7-
const { data_sources: [data_source] } = database;
4+
const dataSourceId = 'acce37c4c4ee4b78aa786a944c2577cf';
5+
const argv = yargs.default({ dataSourceId }).argv;
86

9-
// Fetch templates via data source
10-
// GET /v1/data_sources/:data_source_id/templates
11-
const { data: { templates } } = await notionAPI.get(`/data_sources/${data_source.id}/templates`);
7+
(async () => {
8+
const { templates } = await notion.dataSources.listTemplates({
9+
data_source_id: argv.dataSourceId,
10+
});
1211

1312
log(templates);
1413
})();

0 commit comments

Comments
 (0)