Skip to content

Instantly share code, notes, and snippets.

@alessandrobelli
Created March 27, 2022 15:26
Show Gist options
  • Save alessandrobelli/0c790ceb37d415969975aa2ddccbe6d9 to your computer and use it in GitHub Desktop.
Save alessandrobelli/0c790ceb37d415969975aa2ddccbe6d9 to your computer and use it in GitHub Desktop.
Get Started with Notion API
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