notion_api 1.0.0-beta2 copy "notion_api: ^1.0.0-beta2" to clipboard
notion_api: ^1.0.0-beta2 copied to clipboard

outdated

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.

Example #

Heading & Paragraph

Code
// Create children instance:
// * Old 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,
        ))
  ])
]);

// * 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,
        ))
  ]));

// Send the instance to Notion
notion.blocks.append(
  to: 'YOUR_BLOCK_ID',
  children: childrenB, // or `childrenA`, both are the same.
);
Result

heading&paragraph

To do

Code
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),
          ),
        ],
      ),
    ],
  );

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

todo

27
likes
0
pub points
46%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http

More

Packages that depend on notion_api