Open pol-dev-shinroo opened 1 year ago
Retrieving database
const { Client } = require("@notionhq/client");
const notion = new Client({ auth: process.env.NOTION_ACCESS_TOKEN });
const getNotionDB = async () => {
const dbId = process.env.NOTION_DB_ID;
const response = await notion.databases.retrieve({ database_id: dbId });
console.log(response);
};
module.exports = { getNotionDB };
posting to notion database
const testNotionDB = async () => {
const dbId = process.env.NOTION_DB_ID;
// post request
// req.body
const scrapeData = await getScrapeData();
console.log(scrapeData);
for (let i = 0; i < scrapeData.length; i++) {
const { id, main, desc } = scrapeData[i];
const response = await notion.pages.create(
notionParam({ dbId, id, main, desc })
);
}
};
body parameter
const notionParam = ({ dbId, id, main, desc }) => {
return {
parent: {
database_id: dbId,
},
properties: {
id: {
title: [
{
text: {
content: id,
},
},
],
},
main: {
rich_text: [
{
text: {
content: main,
},
},
],
},
desc: {
rich_text: [
{
text: {
content: desc,
},
},
],
},
},
};
};
module.exports = { notionParam };
With the data retrieved by web-scraping (https://openweathermap.org/weather-conditions), we now want to insert the data into our notion database