a Notion API integration to create Atomic Habits style tracker
I was lucky enough to see a virtual presentation by James Clear on his book Atomic Habits. During the presentation I was chatting with coworkers via Slack and shared that I had created a version of his habit tracker in Notion.so
Some folks asked me to share. Instead I created this script to create the tracker programmatically.
If you just need the trackers, I've shared them on Notion
Notion has an API to read, create, and modify database, pages and blocks. It appears to be in beta, and is a bit hard to use. Lots of nested arrays and dictionaries.
The folks at Orbit have created a Ruby wrapper client. Similar clients exist for python.
The ruby client just wraps the API calls. It doesn't create objects that represent Notion objects.
git clone git@github.com:jimgraham/notion-tracker-create.git
The script depends on the Ruby client. To install, run
bundle install
The Notion API seems to only work through an "integration" tied to a particular workspace. The Notion API documents detail how to create an integration
Create a parent page in Notion to which the trackers will be added. I created "Public Habit Trackers".
Using the "Share" button, add the integration to this page
You can modify the code to
- define the start month (it will run to the end of the year)
- add the columns you want to track
From the command line, run the integration like:
> NOTION_API_TOKEN=<integration_secret_token> NOTION_PARENT_ID=<32-char-id> ruby create_tracker.rb
The two inputs are
NOTION_API_TOKEN
: this is the secret token used to identify your integration to Notion. You can find it in your settings. It typically starts withsecret_
NOTION_PARENT_ID
: this is the identifier of the page under which the tracker will be created. It is a 32 character unique identifier. You can retrieve it from the URL of the page.- e.g.
https://jimgraham.notion.site/Public-Habit-Trackers-01ca41b1588e41bab650fb0d49b0c998
the ID is01ca41b1588e41bab650fb0d49b0c998
- e.g.
The API is not fully-formed, so some of the things I wanted to do were not available. For example,
- API columns are alphabetically sorted, so I had to add a prefix (e.g. "a Date", "b Exercise"). You will have to edit the columns afterwards to remove these (the order will be preserved)
- Can't add the "Calculate" programmatically. One nice feature of having the check list in Notion is that you can add a "Calculate" function to each column. You can add "Percentage checked" and get a percentage of how many days you did the action. This is not available to be set in the API.