Giter Site home page Giter Site logo

notion-exporter's Introduction

UPDATE 2022-02-13: No longer maintained, as I don't use notion anymore. Sorry for the inconvience.

notion-exporter

Notion Exporter is a github action which allows you to export the content of your Notion (notion.so) pages and databases as markdown, to a github repo.

Both the target repo and the source workspace can be private. The Github free plan is good enough ๐Ÿ™. The action uses the internal Notion API.

Demo

See igor-kupczynski/notion-exporter-demo.

Usage

1. Create a github repo

Create repo

2. Find out the root page IDs you want to export

  • You need to provide the IDs of the root pages/databases that you want to export. All children will be exported automatically.
  • You can get the page IDs from the Share menu in Notion.
  • Say the web link is https://www.notion.so/e9ddb02b4745455097ad9d5fef6336a2?v=530e3734d3ef461c76fcc349e28b7b7a, then your page ID is e9ddb02b4745455097ad9d5fef6336a2.
  • You don't need to share the pages.
  • Provide all the page IDs separated by a comma, e.g. e9ddb02b4745455097ad9d5fef6336a2,e65ccf14e13b48d1a6d1b14cd84c4bed

Page IDs

3. Add a new workflow

  • Go to Actions tab and click Setup the workflow yourself.

Setup workflow

  • Paste the following code

    • Use your own page IDs in pages
    • Change 0/6 to how often you want to trigger the export. 0/6 means every 6 hours, 0/24 means every 24 hours.
name: Export my notion workspace

on:
  schedule:
    - cron: "0 */6 * * *"  # Call the export every 6 hours
  workflow_dispatch: {}

jobs:
  export:
    runs-on: ubuntu-latest
    steps:
      - uses: igor-kupczynski/[email protected]
        with:
          pages: "e9ddb02b4745455097ad9d5fef6336a2,e65ccf14e13b48d1a6d1b14cd84c4bed"  # Pages IDs identified in (step 2)  
          output-dir: notion-backup
          notion-token: ${{ secrets.NOTION_TOKEN }}
          github-token: ${{ secrets.GITHUB_TOKEN }}
  • Click Start commit

  • Click Commit new file

Commit workflow

4. Grab the notion token

  • We can't use the notion API unauthenticated. The export feature is not yet part of the public API (in beta), so we need to use the internal API.
  • We need the value of the token_v2 cookie.
  • You can grab it from your web browser. E.g. in chrome:
    1. Log-in to notion and go to your workspace.
    2. Open developer tools: Menu --> More Tools -> Developer Tools
    3. Go to Application tab
    4. Go tp Storage -> Cookies
    5. Copy the value of token_v2 cookie

(Screenshot from safari) Grab the notion token

5. Setup the token as a secret

  • Go to Settings tab, then Secretes and add a new secret.

8 Use NOTION_TOKEN as Name.

  • Paste the token_v2 as the Value.

Token as a secret

6. Trigger the export manually

  • Test if the export works by manually triggering it.

  • Go to Actions tab, then select Export my notion workspace on the left-hand side.

  • Then select Run workflow and again Run workflow.

Run workflow

  • In a minute or so you should see a successful run.

Successful run

  • Note the next runs should start automatically as per the schedule you've set up.

  • Check the notion-backup folder for the content.

Notion backup

How does it work?

The action relies on the notion export feature. To call it programmatically we rely on the unofficial notion API go client.

Inputs

pages

Comma-separated list of page to export the data from. Pages are exported recursively, including their children.

E.g. e9ddb02b4745455097ad9d5fef6336a2,e65ccf14e13b48d1a6d1b14cd84c4bed.

github-token

Github token to use to commit to the repo. Most of the time we can pass the default github action token:

github-token: ${{ secrets.GITHUB_TOKEN }}

notion-token

Value of the token_v2 cookie.

output-dir

Directory under your repo to sync the data to.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ Note the existing content of the directory will be deleted, use with care.

In the demo we set it to notion-backup.

(optional) force-branch

By default, the action discovers the branch to commit to from the GITHUB_REF var, but you can override it with force-branch input.

notion-exporter's People

Contributors

igor-kupczynski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

notion-exporter's Issues

PageID format changes

Hi,

Notion changed the format of the Page ID, it's no longer a random long value, but rather a page name and a random value.

The current workflow fails as it can't import it based on the page ID format.

022/02/11 11:03:11 can't export page: '********-c5454f30bbf24e7bbc061535e8666935' is not a valid notion id
Complete job

Any idea how to fix it?

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.