File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 1+ const notionAPI = require ( '../shared/notion-api' ) ;
2+ const { yargs } = require ( '../shared' ) ;
3+ const { log } = require ( '../shared/utils' ) ;
4+
5+ const databaseId = '1e7abab87ee8457799c1155cf69d502a' ;
6+ const template = 'default' ;
7+ const argv = yargs . default ( { databaseId, template } ) . argv ;
8+
9+ ( async ( ) => {
10+ // Existing endpoint POST /v1/pages
11+ // template[type]=none (default behavior) doesn't use a template
12+ // template[type]=default uses the default template
13+ // template[type]=template_id; template[template_id]=... uses the provided template id
14+
15+ const template = ! [ 'none' , 'default' ] . includes ( argv . template )
16+ ? { type : 'template_id' , template_id : argv . template }
17+ : { type : argv . template } ;
18+
19+ const params = {
20+ parent : {
21+ type : 'database_id' ,
22+ database_id : argv . databaseId ,
23+ } ,
24+ properties : {
25+ Name : {
26+ title : [
27+ {
28+ text : {
29+ content : 'Example page' ,
30+ } ,
31+ } ,
32+ ] ,
33+ } ,
34+ } ,
35+ template,
36+ } ;
37+
38+ const { data : page } = await notionAPI . post ( '/pages' , params ) ;
39+
40+ log ( page ) ;
41+ } ) ( ) ;
Original file line number Diff line number Diff line change @@ -6,7 +6,8 @@ const { log } = require('../shared/utils');
66 const { data : database } = await notionAPI . get ( '/databases/1e7abab87ee8457799c1155cf69d502a' ) ;
77 const { data_sources : [ data_source ] } = database ;
88
9- // Fetch templates
9+ // Fetch templates via data source
10+ // GET /v1/data_sources/:data_source_id/templates
1011 const { data : { templates } } = await notionAPI . get ( `/data_sources/${ data_source . id } /templates` ) ;
1112
1213 log ( templates ) ;
You can’t perform that action at this time.
0 commit comments