Skip to content

Commit 065032c

Browse files
authored
Updated integration to work with Notion API version 2025-09-03 (#18)
1 parent 38d6ac4 commit 065032c

File tree

7 files changed

+53
-128
lines changed

7 files changed

+53
-128
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ The ID of the database you want to run the integration on. You can find the ID i
6767
| `string` | `""` | A valid Notion database ID | Yes |
6868
</details>
6969

70+
<details>
71+
<summary><code>notionDataSourceId</code></summary>
72+
73+
The ID of the data source you want to run the integration on. This is required if you have multiple data sources in your database. You can find the ID under the `Manage data sources` menu in the database settings. If you only have one data source (which is the default), you can leave this property empty.
74+
75+
<img src="images/CopyDataSourceId.png" alt="Notion data source ID location" style="height:600px;">
76+
77+
| Type | Default value | Possible values | Required |
78+
|---|---|---|---|
79+
| `string` | `""` | A valid data source ID of one of the data sources in your database | Yes, if you have multiple data sources in your database. |
80+
</details>
81+
7082
<details>
7183
<summary><code>inputFile</code></summary>
7284

config.default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"$schema": "config.schema.json",
33
"notionIntegrationKey": "",
44
"notionDatabaseId": "",
5+
"notionDataSourceId": "",
56
"inputFile": "input.json",
67
"skipExisting": {
78
"enabled": false,

config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"type": "string",
2121
"default": ""
2222
},
23+
"notionDataSourceId": {
24+
"description": "The ID of the data source you want to run the integration on. This is required if you have multiple data sources in your database. You can find the ID under the \"Manage data sources\" menu in the database settings. If you only have one data source (which is the default), you can leave this property empty.",
25+
"type": "string",
26+
"default": ""
27+
},
2328
"inputFile": {
2429
"description": "The JSON file to import to Notion.",
2530
"type": "string",

images/CopyDataSourceId.png

63.7 KB
Loading

js/notion.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ const NOTION = new Client({
77
auth: CONFIG.notionIntegrationKey,
88
logLevel: LogLevel.ERROR
99
});
10-
const databaseId = CONFIG.notionDatabaseId;
10+
const DATABASE_ID = CONFIG.notionDatabaseId;
11+
// Will be set to the only available data source if none is provided in the config and only one exists in the database
12+
let DATASOURCE_ID = CONFIG.notionDataSourceId || null;
1113

1214
export async function createNotionPage(properties) {
1315
// Create a new page in the database
1416
await NOTION.pages.create({
1517
parent: {
16-
database_id: databaseId
18+
data_source_id: DATASOURCE_ID
1719
},
1820
properties: properties.properties,
1921
cover: properties.cover,
@@ -79,8 +81,24 @@ export async function checkNotionPropertiesExistence() {
7981
}
8082
}
8183

82-
const response = await NOTION.databases.retrieve({
83-
database_id: databaseId
84+
const databaseResponse = await NOTION.databases.retrieve({
85+
database_id: DATABASE_ID
86+
});
87+
88+
if (CONFIG.notionDataSourceId) {
89+
if (databaseResponse.data_sources.find(ds => ds.id === CONFIG.notionDataSourceId) === undefined) {
90+
console.error("Error validating configuration file: Notion database does not contain a data source with the ID specified in the configuration file. Check the \"notionDataSourceId\" property in your config.json");
91+
process.exit(1);
92+
}
93+
} else if (databaseResponse.data_sources.length == 1) {
94+
DATASOURCE_ID = databaseResponse.data_sources[0].id;
95+
} else {
96+
console.error("Error validating configuration file: Notion database contains multiple data sources, but no data source ID to use is specified in the configuration file. Provide the \"notionDataSourceId\" property in your config.json");
97+
process.exit(1);
98+
}
99+
100+
const response = await NOTION.dataSources.retrieve({
101+
data_source_id: DATASOURCE_ID
84102
});
85103

86104
// If any of the properties are not found in the database, exit the program
@@ -181,8 +199,8 @@ export async function getExistingPagesFromNotionDatabase() {
181199

182200
// Fetch all pages from the database that have the specified property set to anything but null
183201
async function queryDatabase(cursor) {
184-
return await NOTION.databases.query({
185-
database_id: databaseId,
202+
return await NOTION.dataSources.query({
203+
data_source_id: DATASOURCE_ID,
186204
page_size: 100,
187205
start_cursor: cursor,
188206
filter: {

package-lock.json

Lines changed: 8 additions & 119 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"name": "json-to-notion",
33
"type": "module",
4-
"version": "1.2.0",
4+
"version": "1.3.0",
55
"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.",
66
"author": {
77
"name": "Nikkel Mollenhauer",
8-
"email": "nikkelm.dev@gmail.com"
8+
"email": "contact@nikkelm.dev"
99
},
1010
"main": "index.js",
1111
"dependencies": {
12-
"@notionhq/client": "^1.0.1",
12+
"@notionhq/client": "^5.0.0",
1313
"cli-progress": "^3.11.2",
1414
"jsonschema": "^1.4.1"
1515
}

0 commit comments

Comments
 (0)