Skip to content

Commit

Permalink
Additional validation of Notion database properties (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkelM authored Jan 8, 2023
1 parent a479d50 commit 8be0f50
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Run `npm install` to install the required dependencies first.

Following this, create a `config.json` file in the root directory of the project and fill it with your desired [configuration](#configuration).

If you haven't already done so, you can obtain a Notion integration key by creating an (internal) Notion integration for your workspace.
You can follow [this guide](https://developers.notion.com/docs/create-a-notion-integration) to learn how to do so.
You will need this key to run the integration locally.

**IMPORTANT: Don't forget to connect the integration to your database, as described in the guide! Otherwise, the import won't work.**

## Usage

After providing the `config.json` [configuration](#configuration) file, you can run the script using
Expand Down
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ await checkNotionPropertiesExistence();
main();

async function main() {
let objectsToSkip = [];
let numObjectsSkipped = 0;
if (CONFIG.skipExisting?.enabled) {
console.log("Skipping existing objects, querying database...");
var objectsToSkip = [];
var numObjectsSkipped = 0;
console.log("Skipping existing objects is enabled, querying database...");
objectsToSkip = await getPagesToSkipFromNotionDatabase();
}

console.log("Importing objects...");
console.log("Importing objects to Notion...");

let erroredObjects = [];
let errorMessages = [];

const progressBar = new cliProgress.SingleBar({
hideCursor: true,
format: '|{bar}| {percentage}% | {eta}s left | {value}/{total} objects imported'
format: '|{bar}| {percentage}% | {eta}s left | {value}/{total} objects imported or skipped'
}, cliProgress.Presets.legacy);

progressBar.start(Object.keys(INPUTFILE).length, 0);

// run the following for loop for each object in the input file
Expand Down
18 changes: 18 additions & 0 deletions js/notion.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ export async function checkNotionPropertiesExistence() {
}
}

// Add the field that is used to check for duplicates
if (CONFIG.skipExisting?.enabled) {
properties.push({
"notionPropertyName": CONFIG.skipExisting.notionProperty,
"notionPropertyType": CONFIG.skipExisting.propertyType
});
}

// Add all properties defined in extraProperties
if (CONFIG.extraProperties) {
for (const property of CONFIG.extraProperties) {
properties.push({
"notionPropertyName": property.notionPropertyName,
"notionPropertyType": property.notionPropertyType
});
}
}

const response = await NOTION.databases.retrieve({
database_id: databaseId
});
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "json-to-notion",
"type": "module",
"version": "1.1.0",
"version": "1.1.1",
"description": "Utility that is able to \"import\" JSON files to Notion - for cases where a CSV file is simply not available, and the conversion from JSON to CSV would be too complicated.",
"main": "index.js",
"dependencies": {
Expand Down

0 comments on commit 8be0f50

Please sign in to comment.