Skip to content
Merged
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
19 changes: 19 additions & 0 deletions examples/data-sources/retrieve/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Arguments:
*
* --data-source-id: ID of the data source to fetch
*/

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

const dataSourceId = 'acce37c4c4ee4b78aa786a944c2577cf';
const argv = yargs.default({ dataSourceId }).argv;

(async () => {
const ds = await notion.dataSources.retrieve({
data_source_id: argv.dataSourceId,
});

log(ds);
})();
4 changes: 2 additions & 2 deletions examples/databases/retrieve/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* Arguments:
*
* --database-id: ID of the page to fetch
* --database-id: ID of the database to fetch
*/

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

const databaseId = '87a5721f46b146dca5b3bddf414e9f00';
const databaseId = '1e7abab87ee8457799c1155cf69d502a';
const argv = yargs.default({ databaseId }).argv;

(async () => {
Expand Down
24 changes: 0 additions & 24 deletions examples/pages/create-from-template/index.js

This file was deleted.

24 changes: 24 additions & 0 deletions examples/shared/notion-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

const { default: axios } = require('axios');
const dotenv = require('dotenv');
dotenv.config();

const NOTION_VERSION = '2025-09-03'

const NOTION_HEADERS = {
Authorization: `Bearer ${process.env.NOTION_API_TOKEN}`,
'Notion-Version': NOTION_VERSION,
};

const JSON_HEADERS = {
...NOTION_HEADERS,
Accept: 'application/json',
'Content-Type': 'application/json',
};

const notionAPI = axios.create({
baseURL: 'https://api.notion.com/v1',
headers: NOTION_HEADERS,
});

module.exports = notionAPI;
40 changes: 40 additions & 0 deletions examples/templates/create-from.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { notion, yargs } = require('../shared');
const { log } = require('../shared/utils');

const dataSourceId = 'acce37c4c4ee4b78aa786a944c2577cf';
const template = 'default';
const argv = yargs.default({ dataSourceId, template }).argv;

(async () => {
// Existing endpoint POST /v1/pages
// template[type]=none (default behavior) doesn't use a template
// template[type]=default uses the default template
// template[type]=template_id; template[template_id]=... uses the provided template id

const template = !['none', 'default'].includes(argv.template)
? { type: 'template_id', template_id: argv.template }
: { type: argv.template };

const params = {
parent: {
type: 'data_source_id',
data_source_id: argv.dataSourceId,
},
properties: {
Name: {
title: [
{
text: {
content: 'Example page',
},
},
],
},
},
template,
};

const page = await notion.pages.create(params);

log(page);
})();
13 changes: 13 additions & 0 deletions examples/templates/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { notion, yargs } = require('../shared');
const { log } = require('../shared/utils');

const dataSourceId = 'acce37c4c4ee4b78aa786a944c2577cf';
const argv = yargs.default({ dataSourceId }).argv;

(async () => {
const { templates } = await notion.dataSources.listTemplates({
data_source_id: argv.dataSourceId,
});

log(templates);
})();
Loading