Published
Edited
Mar 20, 2022
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
async function getNotionDb(token, db) {
// if db is undefined returns all the accessible databases
// if db returns the db content
try {
if (!db) {
const res = await fetch(
`https://notion2json.herokuapp.com/databases?token=${token}`
);
const source = JSON.parse(await res.text());
return source;
} else {
const resdb = await fetch(
`https://notion2json.herokuapp.com/database?token=${token}&id=${db}`
);
const sourcedb = JSON.parse(await resdb.text());
return sourcedb;
}
} catch (error) {
return "token or id invalid";
}
}
Insert cell
async function getNotionPage(token, page) {
try {
const resrow = await fetch(
`https://notion2json.herokuapp.com/page?token=${token}&id=${page}`
);
const sourcerow = JSON.parse(await resrow.text());
return sourcerow;
} catch (error) {
return "token or id invalid";
}
}
Insert cell
Insert cell
Insert cell
AllDbs = getNotionDb(Secret("NOTION_TOKEN"))
Insert cell
Insert cell
OneDb = getNotionDb(Secret("NOTION_TOKEN"), AllDbs[0].id)
Insert cell
## One page
Insert cell
getNotionPage(Secret("NOTION_TOKEN"), OneDb.results[1].id)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more