I use Notion as centralized storage for different things. I have a task list, a gym diary, a watchlist of films, books, articles, etc.
But I had one problem: I wanted to be able to add data to my databases as quick as possible. Normally, to do this you have to open Notion, open the required database, and click New. I needed a faster way to do this.
I solved this problem with Apple Shortcuts, here’s how.
The database
This is a Tasks database that I’ll use as an example. It has the default set of properties.
My goal is to add a new task to this DB as quick as possible while filling out the title of the task.
Notion API
I'll use Notion API to create entries in my database from the Apple Shortcuts.
First, let’s create a new Notion Integration on this page. The only required field is “Name”. Here’s an Integration I created called “Apple shortcuts”:
The “Secrets” section contains the Internal Integration token which I'll use later in the process.
The next step is to give the new Integration access to my database:
I also need to find an id of the database to send it in a request to the Notion API. To get it I'll “Copy link” to the DB and take the last part of the path: https://www.notion.so/89d85578640341d8a2e690f6cfe3938d?v=50886c8525b4453caebcb96299c9d844
Apple shortcut
The next step is to create a shortcut in the Apple Shortcuts that’ll
- Capture a title of a new task
- Call Notion API to add a new entry to the database.
I’ve created a shortcut and named it “Add a new task to Notion”.
The first step is to ask a user to input a name of a task. This is done with an “Ask for input” action:
The next action is called “Get Contents of URL”.
It requires an URL of the API endpoint, an HTTP method, optional headers, and a request body in case the HTTP method implies sending a body.
Here’s a doc that describes a request that we need to construct: link
- URL = https://api.notion.com/v1/pages
- Method = POST
- Two headers are required:
- "Authorization: Bearer {secret key from the Notion Integration page}"
- "Notion-Version: 2022-06-28" - current version can be checked here
The final boss is a request body. Here’s a JSON that we need to send:
{
"parent": {
"database_id": __id_extracted_from_database_url__
},
"properties": {
"Name": {
"title": [
{
"text": {
"content": __text_from_the_previous_action__
}
}
]
}
}
}
Building this JSON from the UI is a bit tedious, but I didn’t find a better way. Here’s the result:
Testing the shortcut
To run the shortcut we can just press the play button from the editing panel.
Here’s a result when I run it on Mac:
Everything went well, so a successful response from the Notion API is shown after the “Get Contents of URL” action.
Using the shortcut
Once the shortcut is ready I need to be able to quickly trigger it.
On Mac, I'll pin the shortcut to the menu bar and assign a keyboard shortcut to it:
On iPhone I'll add the shortcut to the home screen and in the "Today view" as a widget. But the fastest way to trigger a shortcut is via the Back Tap Accessibility feature.
Final thoughts
Apple Shortcuts and especially the “Get Contents of URL” action is a very useful tool that can be used with various different APIs to increase productivity bite by bite. I’ll definitely spend some more time investigating the things I can do with it.