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
8 changes: 8 additions & 0 deletions .cursor/rules/notion-api.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
description:
globs:
alwaysApply: true
---
- This repository contains a series of API examples using Notion's official public JavaScript client found at https://github.com/makenotion/notion-sdk-js.
- We'll aim to cover most of the endpoints, including some API endpoints that are enterprise only (namely the SCIM API, examples of which are found in examples/scim).
- You'll use JavaScript and attempt to extract reusable components for accessing the APIs to the folder.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/gallium
lts/hydrogen
Binary file added examples/files/data/example.mp4
Binary file not shown.
Binary file added examples/files/data/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/files/data/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Here's an example file.
45 changes: 45 additions & 0 deletions examples/files/upload-cover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const path = require('path');
const { notion, yargs } = require('../shared');
const { uploadCoverImage } = require('../shared/files');
const props = require('../shared/props');
const titledDate = require('../shared/titled-date');
const { log } = require('../shared/utils');

const argv = yargs
.option('pageId', {
alias: 'p',
describe: 'The ID of the page to add the cover to',
})
.option('databaseId', {
alias: 'd',
describe: 'The ID of the database to create the page in',
default: process.env.OURA_JOURNAL_DATABASE_ID,
}).argv;

const filePath = path.join(__dirname, 'data/example.png');

(async () => {
let page;

if (!argv.pageId) {
// Create a new page
page = await notion.pages.create({
parent: {
type: 'database_id',
database_id: argv.databaseId,
},
icon: props.emoji('📄'),
properties: titledDate('Journal'),
});
} else {
// Get the existing page
page = await notion.pages.retrieve({
page_id: argv.pageId,
});
}

// Upload a file to the page in the "Daily Photo" property
const upload = await uploadCoverImage(filePath, page);

log(page);
})();
34 changes: 34 additions & 0 deletions examples/files/upload-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const path = require('path');
const { notion, yargs } = require('../shared');
const { uploadFileAttachment, attachFileToPage } = require('../shared/files');
const props = require('../shared/props');
const titledDate = require('../shared/titled-date');
const { log } = require('../shared/utils');

const argv = yargs.argv;
const databaseId = argv.databaseId || process.env.OURA_JOURNAL_DATABASE_ID;

const filePath = path.join(__dirname, 'data/example.txt');
const properties = titledDate('Uploaded File');

const params = {
parent: {
type: 'database_id',
database_id: databaseId,
},
icon: props.emoji('📄'),
properties,
};

(async () => {
// Create a new page
const page = await notion.pages.create(params);

// Upload a file to the page in the "Daily Photo" property
const upload = await uploadFileAttachment(filePath, page, 'Daily Photo', 'Example File');

// Upload a file to the page's body
await attachFileToPage(upload, page, 'Example File');

log(page);
})();
35 changes: 35 additions & 0 deletions examples/files/upload-multipart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const path = require('path');
const { notion, yargs } = require('../shared');
const { uploadFileAttachment, attachFileToPage } = require('../shared/files');
const props = require('../shared/props');
const titledDate = require('../shared/titled-date');
const { log } = require('../shared/utils');

const argv = yargs.argv;
const databaseId = argv.databaseId || process.env.OURA_JOURNAL_DATABASE_ID;

const filePath = path.join(__dirname, 'data/example.mp4');
const properties = titledDate('Uploaded Video');

const params = {
parent: {
type: 'database_id',
database_id: databaseId,
},
icon: props.emoji('📄'),
properties,
};

(async () => {
// Create a new page
const page = await notion.pages.create(params);

// Upload a file to the page in the "Daily Photo" property
const upload = await uploadFileAttachment(filePath, page, 'Daily Photo', 'Video File');

// Upload a video to the page's body
// Block type is inferred from the file's content type
await attachFileToPage(upload, page);

log(page);
})();
Loading