Files
openclaw-backups/archive/inactive-skills/notion-sync/scripts/get-database-schema.js

48 lines
1.2 KiB
JavaScript

#!/usr/bin/env node
const https = require('https');
const NOTION_API_KEY = process.env.NOTION_API_KEY;
const NOTION_VERSION = '2025-09-03';
function notionRequest(path, method) {
return new Promise((resolve, reject) => {
const options = {
hostname: 'api.notion.com',
port: 443,
path: path,
method: method,
headers: {
'Authorization': `Bearer ${NOTION_API_KEY}`,
'Notion-Version': NOTION_VERSION,
'Content-Type': 'application/json'
}
};
const req = https.request(options, (res) => {
let body = '';
res.on('data', (chunk) => body += chunk);
res.on('end', () => {
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(JSON.parse(body));
} else {
reject(new Error(`HTTP ${res.statusCode}: ${body}`));
}
});
});
req.on('error', reject);
req.end();
});
}
(async () => {
const dbId = process.argv[2];
if (!dbId) {
console.error('Usage: get-database-schema.js <database-id>');
process.exit(1);
}
const db = await notionRequest(`/v1/databases/${dbId}`, 'GET');
console.log(JSON.stringify(db, null, 2));
})();