{"id":13770681,"url":"https://github.com/yannbolliger/notion-exporter","last_synced_at":"2025-04-12T11:50:00.038Z","repository":{"id":63058387,"uuid":"354516768","full_name":"yannbolliger/notion-exporter","owner":"yannbolliger","description":"CLI and library for exporting .md and .csv files from any Notion.so page.","archived":false,"fork":false,"pushed_at":"2025-03-14T12:29:35.000Z","size":1947,"stargazers_count":156,"open_issues_count":1,"forks_count":18,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-05T04:02:06.918Z","etag":null,"topics":["cli","markdown","notion","notion-api","npm","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yannbolliger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-04T10:37:36.000Z","updated_at":"2025-04-01T12:43:27.000Z","dependencies_parsed_at":"2024-01-12T13:49:11.233Z","dependency_job_id":"809063a5-f9ac-4487-b487-f87eef5861c6","html_url":"https://github.com/yannbolliger/notion-exporter","commit_stats":{"total_commits":53,"total_committers":3,"mean_commits":"17.666666666666668","dds":0.3207547169811321,"last_synced_commit":"0b07079c731c127477fff720615fc68879da42e6"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannbolliger%2Fnotion-exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannbolliger%2Fnotion-exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannbolliger%2Fnotion-exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannbolliger%2Fnotion-exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yannbolliger","download_url":"https://codeload.github.com/yannbolliger/notion-exporter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248564940,"owners_count":21125412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","markdown","notion","notion-api","npm","typescript"],"created_at":"2024-08-03T17:00:40.576Z","updated_at":"2025-04-12T11:50:00.032Z","avatar_url":"https://github.com/yannbolliger.png","language":"TypeScript","funding_links":[],"categories":["APIs","TypeScript"],"sub_categories":[],"readme":"# Notion Exporter 🛫\n\nA simple CLI tool and TypeScript library for exporting Markdown and CSV files\nfrom any [Notion.so](https://notion.so) page. The tool relies on the export\nfeature of Notion's web-app, hence you get exactly the Markdown and CSV you'd\nget from clicking through: _••• \u003e Export \u003e Markdown \u0026 CSV, no subpages, OK._\n\n## CLI\n\nThe CLI let's you download pages as part of any script, build step or content\npipeline. For example, you can use Notion as a CMS to write your blog, export\nthe Markdown in a Github action and build a static Hugo page. 🎉\n\n```bash\nnpm install -g notion-exporter\nnotion-exporter 3af0a1e347dd40c5ba0a2c91e234b2a5 -t csv \u003e list.csv\n```\n\nFor more options, try `notion-exporter --help` and read about the\n[needed Cookies](#needed-cookies).\n\n## Library\n\nWith the library you can do more elaborate things like directly parse and use\nyour CSV, inject the Markdown in any React/Next.js/Vue page or interact with the\nunderlying [`AdmZip`](https://github.com/cthackers/adm-zip) object.\n\n```ts\nimport NotionExporter from \"notion-exporter\"\n\nconst tokenV2 = ...\nconst fileToken = ...\nconst blockId = \"3af0a1e347dd40c5ba0a2c91e234b2a5\"\n\nawait new NotionExporter(tokenV2, fileToken).getMdString(blockId)\n```\n\n### API\n\nCheck the doc comments in [`NotionExporter.ts`](./src/NotionExporter.ts) for the\nmost accurate information.\n\n#### Constructor\n\nProvide the [required Cookies](#needed-cookies) as authentification to create a\nnew exporter client. For configuration options,\n[refer to the definition](./src/config.ts).\n\n```ts\nconst exporter = new NotionExporter(tokenV2: string, fileToken: string, config?: Config)\n```\n\n#### Methods\n\nDownload and extract the first file of the requested type and return it as\nstring.\n\n```ts\nexporter.getCsvString(blockIdOrUrl: string): Promise\u003cstring\u003e\nexporter.getMdString(blockIdOrUrl: string): Promise\u003cstring\u003e\n```\n\nStart an export of the given block and get the exported archive's URL. The\nsecond method also downloads the ZIP and gives full access to the\n[`AdmZip`](https://github.com/cthackers/adm-zip) object.\n\n```ts\nexporter.getZipUrl(blockIdOrUrl: string): Promise\u003cstring\u003e\nexporter.getZip(blockIdOrUrl: string): Promise\u003cAdmZip\u003e\n```\n\nTo get all files of the exported zip use:\n\n```ts\nexporter.getMdFiles(blockIdOrUrl: string, folderPath: string): Promise\u003cvoid\u003e\n```\n\n## Needed Cookies\n\nTo export anything from Notion, one needs to authenticate oneself with some\nCookies (like a browser would). These cookies are called `token_v2` and\n`file_token`. They are set on all requests of a logged in user when using the\nNotion web-app.\n\n### How to retrieve the Cookies?\n\n- Go to [notion.so](https://notion.so).\n- Log in with your account.\n- Open the developer tools of your browser, open Application \u003e Storage \u003e Cookies\n  (Chrome); Storage tab (Firefox).\n- Copy the value of the Cookies called `token_v2` and `file_token` and paste\n  them somewhere safe.\n\n### How to get the block ID of a page?\n\nTo download a page or table you need its block ID. The block ID is usually the\nlast part of its URL. For example on\n[this page](https://www.notion.so/Notion-Official-83715d7703ee4b8699b5e659a4712dd8)\nwith URL:\n\n```\nhttps://www.notion.so/Notion-Official-83715d7703ee4b8699b5e659a4712dd8\n```\n\nthe ID is `83715d7703ee4b8699b5e659a4712dd8`. So you can get the page as\nMarkdown by doing `notion-exporter 83715d7703ee4b8699b5e659a4712dd8`.\n\nFor tables, the ID is the first of the two long hexadecimal strings. Take\n[this gallery](https://www.notion.so/228eea9d563a47f09fc594d0a89a2e18?v=d5bcf2644d2940b1b18a9ba9cc11c9b6)\nfor example with URL:\n\n```\nhttps://www.notion.so/228eea9d563a47f09fc594d0a89a2e18?v=d5bcf2644d2940b1b18a9ba9cc11c9b6\n```\n\nthe ID is `228eea9d563a47f09fc594d0a89a2e18`. So, you can get the table as CSV\nby doing `notion-exporter 228eea9d563a47f09fc594d0a89a2e18 -t csv`.\n\n## Note on Stability\n\nThis tool completely relies on the export/download feature of the official _but\ninternal_ Notion.so API. The advantage is, that we do not generate any markup\nourselves, just download and extract some ZIPs. While the download feature seems\nto be pretty stable, keep in mind that it still is an internal API, so it **may\nbreak anytime**.\n\n## Contributing\n\nWant to help improve this tool, spotted a typo or need to add a new use-case?\nPlease submit issues and pull requests on\n[Github](https://github.com/yannbolliger/notion-exporter).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyannbolliger%2Fnotion-exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyannbolliger%2Fnotion-exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyannbolliger%2Fnotion-exporter/lists"}