notion_api 1.1.0 copy "notion_api: ^1.1.0" to clipboard
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.

example/example.md

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 properties 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 #

Create a page #

You have to define the parent of the page. It can be:

  • database
  • page
  • workspace

There is a constructor for each one (see example below) but the main constructor can be used as well but the ParentType will be required.

// With database parent
Page page = Page(
  parent: Parent.database(id: 'YOUR_DATABASE_ID'), // <- database
  title: Text('NotionClient (v1): Page test'),
);

// With page parent
Page page = Page(
  parent: Parent.page(id: 'YOUR_PAGE_ID'), // <- page
  title: Text('NotionClient (v1): Page test'),
);

notion.pages.create(page);

Retrieve a page #

notion.pages.fetch('YOUR_PAGE_ID');

Databases #

Retrieve a database #

notion.databases.fetch('YOUR_DATABASE_ID');

List 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 #

Retrieve 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, Heading & ToDo object.
    • The Paragraph object can contain only Text objects.
    • Text can receive a TextAnnotations class with the style of the text.

Heading & Paragraph #

Code

// Create children instance:
// * Deprecated way
// Children oldWay = Children(
//  heading: Heading('Test'),
//  paragraph: Paragraph(
//   content: [
//      Text('Lorem ipsum (A)'),
//      Text(
//        'Lorem ipsum (B)',
//        annotations: TextAnnotations(
//          bold: true,
//          underline: true,
//          color: ColorsTypes.orange,
//        ),
//      ),
//    ],
//  ),
//);
//
// * New way using `addAll()`
Children childrenA = Children().addAll([
  Heading(text: Text('Test')),
  Paragraph(texts: [
    Text('Lorem ipsum (A)'),
    Text(
      'Lorem ipsum (B)',
      annotations: TextAnnotations(
        bold: true,
        underline: true,
        color: ColorsTypes.Orange,
      ),
    ),
  ], children: [
    Heading(text: Text('Subtitle'), type: 3),
  ]),
]);

// * New way using single `add()`
Children childrenB =
  Children().add(Heading(text: Text('Test'))).add(Paragraph(texts: [
    Text('Lorem ipsum (A)'),
    Text('Lorem ipsum (B)',
      annotations: TextAnnotations(
        bold: true,
        underline: true,
        color: ColorsTypes.Orange,
      ),
    ),
  ], children: [
    Heading(text: Text('Subtitle'), type: 3),
  ],
));

// * New way using `withBlocks()` constructor
Children childrenC = 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,
      ),
    ),
  ], children: [
    Heading(text: Text('Subtitle'), type: 3),
  ]),
]);

// Send the instance to Notion
notion.blocks.append(
  to: 'YOUR_BLOCK_ID',
  children: childrenA, // or `childrenB` or `childrenC`, any of these will produce the same result.
);

Result

heading&paragraph

To do #

Code

// Create children instance:
// * Deprecated way
// Children children = 
//   Children(
//     toDo: [
//       ToDo(text: Text('This is a todo item A')),
//       ToDo(
//         texts: [
//           Text('This is a todo item'),
//           Text(
//             'B',
//             annotations: TextAnnotations(bold: true),
//           ),
//         ],
//       ),
//     ],
//   );
//
// * New way
Children children =
  Children.withBlocks([
    ToDo(text: Text('This is a todo item A')),
    ToDo(
      texts: [
        Text('This is a todo item'),
        Text(
          'B',
          annotations: TextAnnotations(bold: true),
        ),
      ],
    ),
    ToDo(text: Text('Todo item with children'), children: [
      BulletedListItem(text: Text('A')),
      BulletedListItem(text: Text('B')),
    ]),
  ],
);

// Send the instance to Notion
notion.blocks.append(
  to: 'YOUR_BLOCK_ID',
  children: children,
);

Result todo

Toggle #

Code

Children children =
  Children.withBlocks([
    Toggle(
      text: Text('This is a toggle block'),
      children: [
        Paragraph(
          texts: [
            Text(
                'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas venenatis dolor sed ex egestas, et vehicula tellus faucibus. Sed pellentesque tellus eget imperdiet vulputate.')
          ],
        ),
        BulletedListItem(text: Text('A')),
        BulletedListItem(text: Text('B')),
        BulletedListItem(text: Text('B')),
      ],
    ),
  ],
);

// Send the instance to Notion
notion.blocks.append(
  to: 'YOUR_BLOCK_ID',
  children: children,
);

Result toggle

Bulleted List Item #

Code

Children children =
  Children.withBlocks([
    BulletedListItem(text: Text('This is a bulleted list item A')),
    BulletedListItem(text: Text('This is a bulleted list item B')),
    BulletedListItem(
      text: Text('This is a bulleted list item with children'),
      children: [
        Paragraph(texts: [
          Text('A'),
          Text('B'),
          Text('C'),
        ])
      ],
    ),
  ],
);

// Send the instance to Notion
notion.blocks.append(
  to: 'YOUR_BLOCK_ID',
  children: children,
);

Result bulletedListItem

Numbered List Item #

Code

Children children =
  Children.withBlocks([
    NumberedListItem(text: Text('This is a numbered list item A')),
    NumberedListItem(text: Text('This is a numbered list item B')),
    NumberedListItem(
      text: Text('This is a bulleted list item with children'),
      children: [
        Paragraph(texts: [
          Text('A'),
          Text('B'),
          Text('C'),
        ])
      ],
    ),
  ],
);

// Send the instance to Notion
notion.blocks.append(
  to: 'YOUR_BLOCK_ID',
  children: children,
);

Result numberedListItem

27
likes
140
points
16
downloads

Publisher

unverified uploader

Weekly Downloads

A wrapper for the public beta Notion API to manage it like a Notion SDK package for dart.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

http

More

Packages that depend on notion_api