Connecting to Notion
To authenticate to Notion, you can use the OAuth standard to connect to your own data or to allow other users to connect to their data. Alternatively, you can use an Integration Token (APIKey) for internal integrations.
Using OAuth Authentication
First you will need to create an OAuth integration. To do so, navigate to https://www.notion.so/my-integrations and click "New integration". Select "Public integration" to enable OAuth. Configure your integration with a name and workspace, then navigate to the "OAuth Domain & URIs" section. Add your redirect URI (this will be your CallbackUrl). The OAuth client ID and OAuth client secret from the "Secrets" section will be your OAuthClientId and OAuthClientSecret.
After setting the following connection properties, you are ready to connect:
- AuthScheme: Set this to OAuth.
- InitiateOAuth: Set this to GETANDREFRESH. You can use InitiateOAuth to manage the process to obtain the OAuthAccessToken.
- OAuthClientId: Set this to the OAuth client ID that is specified in your integration settings.
- OAuthClientSecret: Set this to the OAuth client secret that is specified in your integration settings.
- CallbackURL: Set this to the redirect URI you specified in your integration settings.
Example Connection String
Profile=Notion.apip;Authscheme=OAuth;InitiateOAuth=GETANDREFRESH;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;CallbackUrl=your_callback_url;
Using APIKey Authentication
To use an Integration Token (Internal Integration), create an internal integration at https://www.notion.so/my-integrations. Click "New integration" and configure it with a name and workspace. After creating the integration, copy the "Internal Integration Token" from the "Secrets" section. You will need to share your Notion pages and databases with this integration to grant it access.
After obtaining your Integration Token, set the following connection properties:
- AuthScheme: Set this to APIKey.
- APIKey: Set this to your Integration Token in the ProfileSettings property.
Example Connection String
Profile=Notion.apip;ProfileSettings='APIKey=your_integration_token';Authscheme=APIKey;
Available Tables
The Notion API Profile provides access to the following tables:
- Pages: Notion pages with their properties, icons, and cover images. Supports create and update.
- PageProperties: Paginated property values for individual Notion page properties. Requires PageId and PropertyId filters.
- Blocks: Individual content blocks within pages and databases. Supports update and delete. Requires Id filter.
- BlockChildren: Child blocks nested within a specific Notion block. Requires BlockId filter.
- Comments: Comments on pages and blocks. Supports create and delete. Requires BlockId filter for list queries.
- Databases: Notion databases with title, description, icon, and cover. Supports create and update. Requires Id filter.
- DataSources: Data sources within a database, defining the property schema. Supports create and update. Requires Id filter.
- FileUploads: File upload metadata for attaching files to Notion content. Supports create.
- Search: Search Notion pages and databases by text query and object type.
- Users: Notion workspace users. Read-only.
Usage Examples
Pages:
SELECT * FROM Pages WHERE Id = 'page-uuid'
INSERT INTO Pages (Parent, Properties, Icon, Cover, Children)
VALUES (
'{"type":"page_id","page_id":"parent-page-uuid"}',
'{"title":{"title":[{"text":{"content":"My New Page"}}]}}',
'{"type":"external","external":{"url":"https://www.notion.so/icons/document_gray.svg"}}',
'{"type":"external","external":{"url":"https://www.notion.so/images/page-cover/woodcuts_1.jpg"}}',
'[{"type":"paragraph","paragraph":{"rich_text":[{"text":{"content":"Hello from CData"}}]}}]'
)
UPDATE Pages SET Properties = '{"title":{"title":[{"text":{"content":"Updated Title"}}]}}', InTrash = 'false' WHERE Id = 'page-uuid'
PageProperties:
SELECT * FROM PageProperties WHERE PageId = 'page-uuid' AND PropertyId = 'property-uuid'
Blocks:
SELECT * FROM Blocks WHERE Id = 'block-uuid'
UPDATE Blocks SET Type = 'paragraph', Content = '{"rich_text":[{"type":"text","text":{"content":"Updated text"}}]}' WHERE Id = 'block-uuid'
UPDATE Blocks SET InTrash = 'true' WHERE Id = 'block-uuid'
DELETE FROM Blocks WHERE Id = 'block-uuid'
BlockChildren:
SELECT * FROM BlockChildren WHERE BlockId = 'block-uuid'
Comments:
SELECT * FROM Comments WHERE BlockId = 'page-uuid'
INSERT INTO Comments (Parent, RichText)
VALUES (
'{"type":"page_id","page_id":"page-uuid"}',
'[{"type":"text","text":{"content":"My comment"}}]'
)
INSERT INTO Comments (DiscussionId, RichText)
VALUES ('discussion-uuid', '[{"type":"text","text":{"content":"Reply in thread"}}]')
DELETE FROM Comments WHERE Id = 'comment-uuid'
Databases:
SELECT * FROM Databases WHERE Id = 'database-uuid'
INSERT INTO Databases (Parent, Title, Description, Icon, Cover, IsInline)
VALUES (
'{"type":"page_id","page_id":"page-uuid"}',
'[{"type":"text","text":{"content":"My Database"}}]',
'[{"type":"text","text":{"content":"Database description"}}]',
'{"type":"external","external":{"url":"https://www.notion.so/icons/database_gray.svg"}}',
'{"type":"external","external":{"url":"https://www.notion.so/images/page-cover/woodcuts_1.jpg"}}',
'false'
)
UPDATE Databases SET Title = '[{"type":"text","text":{"content":"Renamed Database"}}]', InTrash = 'false' WHERE Id = 'database-uuid'
DataSources:
SELECT * FROM DataSources WHERE Id = 'data-source-uuid'
INSERT INTO DataSources (Parent, Title, Properties, Icon)
VALUES (
'{"type":"database_id","database_id":"database-uuid"}',
'[{"type":"text","text":{"content":"My DataSource"}}]',
'{"Name":{"name":"Name","type":"title","title":{}},"Status":{"name":"Status","type":"select","select":{"options":[{"name":"Active","color":"green"}]}}}',
'{"type":"external","external":{"url":"https://www.notion.so/icons/database_gray.svg"}}'
)
UPDATE DataSources SET Title = '[{"type":"text","text":{"content":"Renamed DataSource"}}]', InTrash = 'false' WHERE Id = 'data-source-uuid'
FileUploads:
SELECT * FROM FileUploads WHERE Id = 'file-upload-uuid'
INSERT INTO FileUploads (Filename, ContentType) VALUES ('report.pdf', 'application/pdf')
INSERT INTO FileUploads (Mode, Filename, ExternalUrl)
VALUES ('external_url', 'logo.png', 'https://example.com/public/logo.png')
Search:
SELECT * FROM Search WHERE Query = 'Meeting Notes' AND Filter = 'page'
Connection Properties
The connection string properties are the various options that can be used to establish a connection. This section provides a complete list of the options you can configure in the connection string for this provider.
| Property | Description |
| APIKey | Identifies the Notion Integration Token for your internal integration. |
| AuthScheme | Identifies the user authentication scheme in use. Allowed values are: BASIC, NONE, NTLM, OAUTH, APIKEY, OAUTH_CLIENT, OAUTH_PASSWORD |
| CallbackURL | Identifies the URL users return to after authenticating to API via OAuth (Custom OAuth applications only). |
| InitiateOAuth | Specifies the process for obtaining or refreshing the OAuth access token, which maintains user access while an authenticated, authorized user is working. Allowed values are: OFF, REFRESH, GETANDREFRESH |
| OAuthAccessToken | Specifies the OAuth access token used to authenticate requests to the data source. This token is issued by the authorization server after a successful OAuth exchange. |
| OAuthClientId | Specifies the client ID (also known as the consumer key) assigned to your custom OAuth application. This ID is required to identify the application to the OAuth authorization server during authentication. |
| OAuthClientSecret | Specifies the client secret assigned to your custom OAuth application. This confidential value is used to authenticate the application to the OAuth authorization server. (Custom OAuth applications only.). |
| OAuthExpiresIn | Specifies the duration in seconds, of an OAuth Access Token's lifetime. The token can be reissued to keep access alive as long as the user keeps working. |
| OAuthRefreshToken | Specifies the OAuth refresh token used to request a new access token after the original has expired. |
| OAuthSettingsLocation | Specifies the location of the settings file where OAuth values are saved. |
| OAuthTokenTimestamp | Displays a Unix epoch timestamp in milliseconds that shows how long ago the current access token was created. |
| OAuthVerifier | Specifies a verifier code returned from the OAuthAuthorizationURL . Used when authenticating to OAuth on a headless server, where a browser can't be launched. Requires both OAuthSettingsLocation and OAuthVerifier to be set. |