32 lines
891 B
JavaScript
32 lines
891 B
JavaScript
// import variables from `.env`
|
|
require('dotenv').config();
|
|
const { Client } = require('@notionhq/client');
|
|
|
|
const notion = new Client({auth: process.env.NOTION_KEY});
|
|
|
|
const databaseID = process.env.NOTION_DATABASE_ID;
|
|
|
|
async function addItem(text) {
|
|
try {
|
|
const response = await notion.pages.create({
|
|
parent: {database_id: databaseID},
|
|
properties: {
|
|
title: {
|
|
title: [
|
|
{
|
|
"text": {
|
|
"content": text
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
})
|
|
console.log(response);
|
|
console.log("Success! Entry added.");
|
|
} catch (error) {
|
|
console.error(error.body);
|
|
}
|
|
}
|
|
|
|
addItem("Yurts in Big Sur, California"); |