Gatsby source plugin for working with official Notion API.
Here's a Postman collection to play around with the API if you're interested: https://www.postman.com/notionhq/workspace/notion-s-public-api-workspace/overview
This is a source plugin for pulling content into Gatsby from official public Notion API (currently in beta). With this plugin, you will be able to query your Notion pages in Gatsby using GraphQL.
An example (...coming soon)
yarn add gatsby-source-notion-api
or
npm install --save gatsby-source-notion-api
Before using this plugin, make sure you
- Created a Notion integration (sign in to Notion, go to
Settings & Memberships
βIntegrations
βDevelop your own integrations
, short link to the Integrations creation section). It's OK to use an internal one. Don't forget to copy the token: - Go to the database you want to have access to from Gatsby, and share it with the integration (
Share
β Select the integration in theInvite
dropdown). Don't forget the database in the URL. It's a series of characters after the last slash and before the question mark.Here's a reference: https://www.notion.so/{USER}/**{DATABASE_ID}**?{someotherirrelevantstuff}
- Then add this to your
gatsby-config.json
:
plugins: [
{
resolve: `gatsby-source-notion-api`,
options: {
token: `$INTEGRATION_TOKEN`,
databaseId: `$DATABASE_ID`,
},
},
// ...
]
token
[string][required]
Integration token.
databaseId
[string][required]
The identifier of the database you want to get pages from. The integration identified by provided token must have access to the database with given id.
You can query for pages with notion
or grab all of them with allNotion
. The raw content of the
page is available under raw
property.
query {
allNotion {
edges {
node {
title
properties
archived
createdAt
updatedAt
children
raw
}
}
}
}
Unique page identifier. This is not a Notion page identifier. You can get the Notion page id under raw.id
.
Parend Node.
Blocks that belong to the page.
Page title joined into one string.
Properties of the page. An object with keys representing database columns (snake-cased), and the following value:
Notion column id
Readable name of the column (without snake case).
Value of the column for the page. Might have different structure depending on the type.
Notion type of the column.
Boolean. Is true if the pages was marked removed but not removed permanently.
Date of page creation.
Date of the last page update.
Untouched contents of whatever Notion API returned.
- Due to the fact that Notion API only appeared recently, and it is still in beta, some blocks are marked "unsupported". Among others, images cannot be fetched for now
- Currently,
gatsby-source-notion-api
can only work with one provided database. In further releases, all databases reachable by the Integration will be available for querying Nested blocks are currently skipped. E.g. if a list item has a nested sublist, it's contents will be omitted. This will be fixed in the nearest releasesNested blocks are supported as of0.4.0
!Only raw content is available. Raw meaning whatever Notion returns. Further releases will aim at providing a more convenient data format apart from the raw one0.3.0
features support for archived, createdAt, updatedAt, properties and title.
Thanks for reaching to the end of the readme!