notion_api 1.1.0 notion_api: ^1.1.0 copied to clipboard
A wrapper for the public beta Notion API to manage it like a Notion SDK package for dart.
Notion API client for dart.
See the ROADMAP file to see what is coming next.
Usage #
Important: The methods return a NotionResponse
. You can find how to use it in its documentation.
NotionClient
class #
You only have to create a new instance of the NotionClient
class and all the API requests will be available as class methods.
NotionClient notion = NotionClient(token: 'YOUR SECRET TOKEN FROM INTEGRATIONS PAGE');
Individual classes #
You can also use individual request group class like NotionPagesClient
or NotionDatabasesClient
. They are used like the main client but the methods are class methods instead of class properties methods.
Example
// With main class
NotionClient notion = NotionClient(token: 'YOUR_TOKEN');
notion.databases.fetchAll();
// With individual class
NotionDatabasesClient databases = NotionDatabasesClient(token: 'YOUR_TOKEN');
databases.fetchAll();
A few examples #
To see more examples go here.
Append blocks children #
// Create children instance:
Children children = Children.withBlocks([
Heading(text: Text('Test')),
Paragraph(texts: [
Text('Lorem ipsum (A)'),
Text('Lorem ipsum (B)',
annotations: TextAnnotations(
bold: true,
underline: true,
color: ColorsTypes.Orange,
))
])
]);
// Send the instance to Notion
notion.blocks.append(
to: 'YOUR_BLOCK_ID',
children: children,
);
Create a page #
// Create a page instance
Page page = Page(
parent: Parent.database(id: 'YOUR_DATABASE_ID'),
title: Text('NotionClient (v1): Page test'),
);
// Send the instance to Notion.
notion.pages.create(page);
Contributions #
Please help, I don't even know if what I'm doing is right.
Rules #
Some rules to follow:
- Please follow the dart convention format:
- If you are adding a new function, please also add the documentation.
- If you are adding a new parameters, please also add it to the current documentation.
- (Optional) Run the tests to know that everything is working just fine (See how run the tests).
- This is optional because sometimes the tests fail on GitHub actions so anyway I will check this on my computer.
Tests #
To be able to run the tests you will have to have a .env
file on the root directory with the next variables:
- TOKEN: The secret token.
- TEST_DATABASE_ID: The database id where you will be working on.
- TEST_PAGE_ID: Some page id inside the database specified above.
- TEST_BLOCK_ID: Some block id inside the page specified above.
- TEST_BLOCK_HEADING_ID: Some heading block id inside the page specified above.
Example: #
The values are not valid of course.
TOKEN=secret_Oa24V8FbJ49JluJankVOQihyLiMXwqSQeeHuSFobQDW
TEST_DATABASE_ID=366da3d646bb458128071fdb2fbbf427
TEST_PAGE_ID=c3b53019-4470-443b-a141-95a3a1a44g60
TEST_BLOCK_ID=c8hac4bb32af48889228bf483d938e34
TEST_BLOCK_HEADING_ID=c8hac4bb32af48889228bf483d938e34
Next release #
I don't know yet. If you have suggestions feel free to create an Issue or to create a PR with the feature.