Notion: import CSV with Markdown page content

May 11, 2022

As I was migrating a GitHub project to Notion, one of the solutions I considered was to import a CSV using the native import feature.

Sadly, there was no way to set the page content from the rows in the CSV file. All the columns are imported as custom attributes and we canā€™t pick one to be used as page content.

So I ended up making a custom script using the Notion API. And while this script is very specific to my use case, I figured it would be good to generalize it and go back to my original CSV idea, this way other people can leverage it for their own projects!

The way it works

The idea is simple. First, we import a CSV using the native import feature, which results in our ā€œcontentā€ column being imported as a page attribute. Then we run a simple scripts that goes through all the pages with a non-empty ā€œcontentā€ column, and moves it to the page body instead!

I named this script Notion property to content (I know, I suck at naming things), and with a bit terminal fu, you can use it on your own Notion imports!

Running the script

It requires Node.js version 18 or later.

git clone https://github.com/valeriangalliat/notion-property-to-content
cd notion-property-to-content
npm install

From there, we need a Notion token. For this, you need to create a new integration. The default parameters should do. At the end Notion will give you a token that weā€™ll set in an environment variable (lines starting with $ means an actual command that you run, but donā€™t type the $):

$ read NOTION_TOKEN
Paste the token here
$ export NOTION_TOKEN

Now you need to share the database youā€™re working on with your newly created integration. On the top right corner of your database page, hit the ā€œshareā€ button:

Click on the search field to reveal your integration, and click ā€œinviteā€:

While youā€™re on the database page, copy its ID from the URL bar, for example if the current URL is:

https://www.notion.so/513bff94c55a4cf09a66a336c87e7964?v=0eb7b11463c94c3a84786bd3191e4032

Copy this part:

513bff94c55a4cf09a66a336c87e7964

Finally, back to the terminal, you can run the following command to move the property of your choice to the page content:

node property-to-content.js <database-id> <property> --remove

Where <database-id> is the ID of your database and <property> is the name of the property you want to use as page content. For example if your database ID is 513bff94c55a4cf09a66a336c87e7964 and your property is named ā€œPage Contentā€, run:

node property-to-content.js 513bff94c55a4cf09a66a336c87e7964 'Page Content' --remove

Note: I recommend you to run this on a test database first just to make sure it behaves the way you want with your data!

The --remove part is to empty the property after writing its value to the actual page content. It is useful so that if you were to run the script again, it doesnā€™t copy the content a second time at the end of the page, as the script only goes through non-empty content values.

If you plan to only run this once and want to keep the content in its original property, donā€™t add the --remove part.

Need some help?

If you need help with this, or importing data to your Notion workspace and working with the Notion API in general, donā€™t hesitate to shoot me an email, Iā€™ll be happy to help you on a consulting basis! Youā€™ll even get a 20% discount if you tell me youā€™re coming from this article. šŸ˜œ

Want to leave a comment?

Start a conversation on Twitter or send me an email! šŸ’Œ
This post helped you? Buy me a coffee! šŸ»