Created
March 27, 2022 15:26
-
-
Save alessandrobelli/0c790ceb37d415969975aa2ddccbe6d9 to your computer and use it in GitHub Desktop.
Get Started with Notion API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Client } from "@notionhq/client"; | |
import "dotenv/config"; | |
console.log(process.env.NOTION_KEY); | |
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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment