Gumroad Sales Tracker (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.

ICYAC: Link to the template at the end of article 👇🏻

👓 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

    https://res.cloudinary.com/practicaldev/image/fetch/s--uZZDt2f0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1oahl11m9nhlv2j6qkw.gif

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,

    Create Gumroad Application

  • Give the application a Icon (optional), Name and Redirect URI (Set redirect uri value to http://127.0.0.1 as our notion integration doesn't involve any oauth2 authorisation code flow)
    Setting Application Data

  • 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

    Generate Gumroad 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 :-

i. Notion API Secret Token
ii. Gumroad API Secret Token

These two will be used by the python script to :-

  1. Read Product list from your Gumroad Store

  2. Update Products to your Notion Page

Let's walk you through to get it done 😄

[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 + Demo here :-

21