Screen Shot 2021-05-19 at 11 06 46 PM

I thought the Notion API might be a fun thing to play with via Script Kit. I have a singular "tasks" database that I use to capture all manner of things, so I always want to insert pages into it in order to process them later. These scripts will require you to update the databaseID value in the code itself. I could see an expansion of this script to allow for the selection of a specific Notion database from a list.

The second script below takes a second input in order to insert content into the new page -- I was wondering if there is a way to allow multiline text input via Script Kit, which would make that script more robust.

You can get a Notion API token here and find quick-start instructions here, as well as the API reference here.

For a quick overview of the data model, check out Chris Biscardi's video here. For a more in-depth overview, check out this Notion blog post.

Install notion-add-task

let notionToken = await env('NOTION_USER_TOKEN')
let databaseID = "3859b567fda3464ea5a69d5ccb56274b"
let content = await arg('Enter Task')
let {data} = await post(
'https://api.notion.com/v1/pages', {
"parent": { "database_id": databaseID },
"properties": {
"Name": {
"title": [
{
"text": {
"content": content
}
}
]
}
}
},
{
headers: {
Authorization: `Bearer ${notionToken}`,
}
})
let pageID = data.id.replace(/-/g, "");
let pageURL = `https://notion.so/${databaseID}?p=${pageID}`
copy(pageURL)

Install notion-add-task-with-content

let notionToken = await env('NOTION_USER_TOKEN')
let databaseID = "3859b567fda3464ea5a69d5ccb56274b"
let content = await arg('Enter Task')
let {data} = await post(
'https://api.notion.com/v1/pages', {
"parent": { "database_id": databaseID },
"properties": {
"Name": {
"title": [
{
"text": {
"content": content
}
}
]
}
}
},
{
headers: {
Authorization: `Bearer ${notionToken}`,
"Content-Type": "application/json",
"Notion-Version": "2021-05-13"
}
})
let bodyContent = await arg('Enter Content')
let {bodyData} = await patch(
`https://api.notion.com/v1/blocks/${data.id}/children`, {
"children": [
{
"object": "block",
"type": "paragraph",
"paragraph": {
"text": [
{
"type": "text",
"text": {
"content": bodyContent
}
}
]
}
}
]
},
{
headers: {
Authorization: `Bearer ${notionToken}`,
"Content-Type": "application/json",
"Notion-Version": "2021-05-13"
}
})
let pageID = data.id.replace(/-/g, "");
let pageURL = `https://notion.so/${databaseID}?p=${pageID}`
copy(pageURL)

(I just noticed that I haven't updated the first script to pass the "Notion-Version" header, but it seems unnecessary for now.)