notion_api 0.0.1-beta1 notion_api: ^0.0.1-beta1 copied to clipboard
A client for the public beta of the Notion API
Content
Initialization #
Full instance #
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();
Pages #
Creating pages #
Page page = Page(
databaseId: 'YOUR DATABASE ID',
title: Text(content: 'The title of the new page'),
);
notion.pages.create(page);
Retrieving pages #
notion.pages.fetch('YOUR_PAGE_ID');
Databases #
Retrieving a database #
notion.databases.fetch('YOUR_DATABASE_ID');
Retrieving all databases #
Warning: This endpoint is not recommended by the Notion team.
Parameters:
- startCursor: If supplied, this endpoint will return a page of results starting after the cursor provided. If not supplied, this endpoint will return the first page of results.
- pageSize: The number of items from the full list desired in the response. Maximum: 100, otherwise will be ignored.
notion.databases.fetchAll();
Block children #
Retrieving block children #
notion.blocks.fetch('YOUR_BLOCK_ID');
Append block children #
Parameters:
- to: Identifier for a block.
- children: Child content to append to a container block as an array of block objects.
- Can receive a
Paragraph
orHeading
object. - The
Paragraph
object can contain onlyText
objects. Text
can receive aTextAnnotations
class with the style of the text.
- Can receive a
notion.blocks.append(
to: 'YOUR_BLOCK_ID',
children: Children(
heading: Heading('Test'),
paragraph: Paragraph([
Text('Lorem ipsum (A)'),
Text('Lorem ipsum (B)',
annotations: TextAnnotations(
bold: true,
underline: true,
color: RichTextColors.orange))
])));