File tree Expand file tree Collapse file tree 8 files changed +419
-120
lines changed
pages/create-from-template Expand file tree Collapse file tree 8 files changed +419
-120
lines changed Original file line number Diff line number Diff line change 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+ } ) ( ) ;
Original file line number Diff line number Diff line change 11/**
22 * Arguments:
33 *
4- * --database-id: ID of the page to fetch
4+ * --database-id: ID of the database to fetch
55 */
66
77const { notion, yargs } = require ( '../../shared' ) ;
88const { log } = require ( '../../shared/utils' ) ;
99
10- const databaseId = '87a5721f46b146dca5b3bddf414e9f00 ' ;
10+ const databaseId = '1e7abab87ee8457799c1155cf69d502a ' ;
1111const argv = yargs . default ( { databaseId } ) . argv ;
1212
1313( async ( ) => {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+
2+ const { default : axios } = require ( 'axios' ) ;
3+ const dotenv = require ( 'dotenv' ) ;
4+ dotenv . config ( ) ;
5+
6+ const NOTION_VERSION = '2025-09-03'
7+
8+ const NOTION_HEADERS = {
9+ Authorization : `Bearer ${ process . env . NOTION_API_TOKEN } ` ,
10+ 'Notion-Version' : NOTION_VERSION ,
11+ } ;
12+
13+ const JSON_HEADERS = {
14+ ...NOTION_HEADERS ,
15+ Accept : 'application/json' ,
16+ 'Content-Type' : 'application/json' ,
17+ } ;
18+
19+ const notionAPI = axios . create ( {
20+ baseURL : 'https://api.notion.com/v1' ,
21+ headers : NOTION_HEADERS ,
22+ } ) ;
23+
24+ module . exports = notionAPI ;
Original file line number Diff line number Diff line change 1+ const { notion, yargs } = require ( '../shared' ) ;
2+ const { log } = require ( '../shared/utils' ) ;
3+
4+ const dataSourceId = 'acce37c4c4ee4b78aa786a944c2577cf' ;
5+ const template = 'default' ;
6+ const argv = yargs . default ( { dataSourceId, template } ) . argv ;
7+
8+ ( async ( ) => {
9+ // Existing endpoint POST /v1/pages
10+ // template[type]=none (default behavior) doesn't use a template
11+ // template[type]=default uses the default template
12+ // template[type]=template_id; template[template_id]=... uses the provided template id
13+
14+ const template = ! [ 'none' , 'default' ] . includes ( argv . template )
15+ ? { type : 'template_id' , template_id : argv . template }
16+ : { type : argv . template } ;
17+
18+ const params = {
19+ parent : {
20+ type : 'data_source_id' ,
21+ data_source_id : argv . dataSourceId ,
22+ } ,
23+ properties : {
24+ Name : {
25+ title : [
26+ {
27+ text : {
28+ content : 'Example page' ,
29+ } ,
30+ } ,
31+ ] ,
32+ } ,
33+ } ,
34+ template,
35+ } ;
36+
37+ const page = await notion . pages . create ( params ) ;
38+
39+ log ( page ) ;
40+ } ) ( ) ;
Original file line number Diff line number Diff line change 1+ const { notion, yargs } = require ( '../shared' ) ;
2+ const { log } = require ( '../shared/utils' ) ;
3+
4+ const dataSourceId = 'acce37c4c4ee4b78aa786a944c2577cf' ;
5+ const argv = yargs . default ( { dataSourceId } ) . argv ;
6+
7+ ( async ( ) => {
8+ const { templates } = await notion . dataSources . listTemplates ( {
9+ data_source_id : argv . dataSourceId ,
10+ } ) ;
11+
12+ log ( templates ) ;
13+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments