Tracking your Gumroad sales using Python (feat. Notion API)
Introduction
Notion is an incredible software that allows creators develop, publish, maintain content with little to no effort. Creator economy is the new deal. If you are a creator who sells ebooks, presets, software bundles like Notion Templates, you mustâve heard about Gumroad. Creators, like myself and many more use Gumroad on a day to day basis.
Gumroad Provides [API] that allows the creator to programmatically retrieve their products and user data for analysis/ maintenance purposes.
Notion also provides [API] support to read and write into the notion workspace with granular scopes w.r.t resources.
So this would naturally mean, one can read gumroad product data and write them into Notion Pages/ Databases using code.
I am here to present just that.
đ My Expectations
1. Open a Notion page,
2. Check my Product Sales,
3. Close the page
Process
[1] Notion Integration
In order to provide edit capabilities on my sales dashboard, I would want to provide access token with edit scope to my updation script (here python).
To get the access token (secret key), I would want to create an internal integration. The steps to create an integration for a database can be found here
Steps to setup an Integration: [Referenced from Official Notion Doc]
- Go to https://www.notion.com/my-integrations
- Click the â+ New integrationâ button.
- Give your integration a name, say âGumroad-Notion-Integrationâ
- Select the workspace where you want to install this integration.
- Click âSubmitâ to create the integration.
- Copy the âInternal Integration Tokenâ on the next page and keep it aside
A user must share specific pages with an integration in order for those pages to be accessed using the API.
The script must update the Database as well as the Parent Page. Therefore, we would want to give access to both.
Bear in mind to give database access before parent page access
Share the integration with the Notion Database
Open âMy Productsâ Database as a Page & click on the `Share` button and use the selector to find your integration by its name, then click `Invite`. Your integration now has permission to read, write, and edit the new database.
Ensure that this created integration is not used by any other database
Share the integration with the Parent Page
Open the Gumroad Sales Page & click on the `Share` button and use the selector to find your integration by its name, then click `Invite`. Your integration now has permission to read, write, and edit the new database.
[2] Gumroad Integration
To get your gumroad product information, you need to get a gumroad account `secret token` that will be used by the python script, to pull your product data and push them to your notion database
- Login to your gumroad account and visit https://app.gumroad.com/settings/advanced url in your browser
- Scroll down to `Create Application` Section that looks like this,
- Give the application a Icon (optional),
Name
andRedirect URI
Set `Redirect Uri` value to `http://127.0.0.1`
đ This is because our notion integration doesnât involve any oauth2 authorisation code flow)
- Click on âCreate applicationâ to create the application. This will advance you to the next screen, showing the new application
- Click `Generate access token` button to get your access token
- Your access token will be displayed. Copy the Access token
[3] Setting up Code Environment
đ„ Leveraging Notion and Gumroad API
Now that we have completed creation of Notion API and Gumroad API Integration. You should have 2 Secret tokens pasted in your text editor safely :-- Notion API Secret Token
- Gumroad API Secret Token
These two will be used by the python script to :-
1. Update Products to your Notion Page
2. Read Product list from your Gumroad Store
Letâs walk you through to get it done đ
- Clone to this GitHub Repository to your local device
GitHub â tnvmadhav/notion-gumroad-integration
- Open
my_variables.yml
file using a code/ text editor - Paste the `Notion` and `Gumroad` secret tokens like this and save file,
[4] Running Code
1. After updating your notion and gumroad secret tokens into the `my_variables.yml` , we can now install the python dependencies to run the code
2. Running the following command to install python dependencies ,
pip3 install -r requirements.txt# use `py -m pip install -r requirements.txt` (for Windows System)
3. Run the following command to start python server
python3 gumroad_notion_product.py# Use `py gumroad_notion_product.py` if you are on Windows!
4. đđ» Watch your gumroad products appear / get updated one by one in 5 to 10 second time intervals!
Note:
If a product sale happens, the sales count will be updated immediately as long as the python script is running!
Conclusion
This was yet another fun experiment of mine and if you liked this, do follow me on Twitter and let me know đ.
You can find the Notion Template here :-