/
1-create-a-database.js
59 lines (51 loc) · 1.24 KB
/
1-create-a-database.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Client } from "@notionhq/client"
import { config } from "dotenv"
config()
const pageId = process.env.NOTION_PAGE_ID
const apiKey = process.env.NOTION_API_KEY
const notion = new Client({ auth: apiKey })
/*
---------------------------------------------------------------------------
*/
/**
* Resources:
* - Create a database endpoint (notion.databases.create(): https://developers.notion.com/reference/create-a-database)
* - Working with databases guide: https://developers.notion.com/docs/working-with-databases
*/
async function main() {
// Create a new database
const newDatabase = await notion.databases.create({
parent: {
type: "page_id",
page_id: pageId,
},
title: [
{
type: "text",
text: {
content: "New database name",
},
},
],
properties: {
// These properties represent columns in the database (i.e. its schema)
"Grocery item": {
type: "title",
title: {},
},
Price: {
type: "number",
number: {
format: "dollar",
},
},
"Last ordered": {
type: "date",
date: {},
},
},
})
// Print the new database response
console.log(newDatabase)
}
main()