Gumroad Sales Tracker (feat. Notion API)
Tags: gumroad, notion, notionapi, python
Published: 2021-08-29 11:59:47

# 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] (https://app.gumroad.com/api) that allows the creator to programmatically retrieve their products and user data for analysis/ maintenance purposes. 

Notion also provides [API](https://developers.notion.com) 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

---


![Gumroad Sales Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d3oe0q39mtovsnn2xlu3.png)


# 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](https://developers.notion.com/docs#step-1-create-an-in)]

- Go to [https://www.notion.com/my-integrations](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](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`](https://app.gumroad.com/settings/advanced) url in your browser
- Scroll down to `Create Application` Section that looks like this,

    ![Create Gumroad Application](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9e3vc4xx10b22pclmcm.png)

- Give the application a Icon (optional), `Name` and `Redirect URI` (Set `redirect uri` value to [`http://127.0.0.1`](http://127.0.0.1/) as our notion integration doesn't involve any oauth2 authorisation code flow)
    ![Setting Application Data](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/80qaxfvdcgyby46qasoo.png)

- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bfxl0u42scfzmq2hk9cv.png)


- 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 😄

- Clone to this GitHub Repository to your local device

    [GitHub - tnvmadhav/notion-gumroad-integration](https://github.com/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,

   ![Saving Gumroad and Notion secret tokens](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sd0pbvlw3anrppoo8coj.png)

---

## [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 ,

    ```bash
    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

    ```bash
    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](https://twitter.com/TnvMadhav) and let me know 😁 

You can find the Notion Template + Demo here :- 

[Gumroad Sales Tracker](https://gum.co/gumroad-notion-integration)