Notion API client for dart

Overview

Notion API client for dart.

CI codecov

See the ROADMAP file to see what is coming next.

API implemented

Endpoint Avaliable Notes
Retrieve a database βœ…
Query a database πŸ— Working on it
List databases βœ…
Create a database βœ… Workin on more properties
Retrieve a page βœ…
Create a page βœ… Workin on more properties
Update a page βœ… Workin on more properties
Retrieve block children βœ…
Append block children βœ…
Retrieve a user
List all users
Search

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

A page created and filled using only this package:
https://jonathangomz.notion.site/notion_api-example-0893dd2cb38a413d90165cb810b3c019

To see code to create the page above or 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);

Errors

Some errors that I have encounter and still don't know how to solve because are errors that also occur on Postman are:

Create page with chidren

When the parent is a page the error is:

"body failed validation: body.properties.title.type should be an array, instead was `\"array\"`."

But when the parent is a database then the error is:

"body failed validation: body.parent.page_id should be defined, instead was `undefined`."

You can create the page first and then add the children as shown in the examples.

Contributions

Please help, I don't even know if what I'm doing is right.

Rules

Some rules to follow:

  1. Please follow the dart convention format:
    1. Effective dart
    2. dart format
  2. If you are adding a new function, please also add the documentation.
  3. If you are adding a new parameters, please also add it to the current documentation.
  4. (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

v1.2.1:

Release date: 02/Aug/2021

  • Add constructors with only single text content with default style for:
    • Paragraph.text('some text here...')
    • ToDo.text('some text here...', checked: true)
    • Heading.text('some text here...', type: 2)
    • BulletedListItem.text('some text here...')
    • NumberedListItem.text('some text here...')
    • Toggle.text('some text here...', children: [])
  • Add more constructors for Heading class:
    • one: Heading with type 1 by default.
    • two: Heading with type 2 by default.
    • three: Heading with type 3 by default.
  • Add more constructors for Text class:
    • code: Text with code style by default.
    • italic: Text with italic style by default.
    • bold: Text with bold style by default.
    • [Opt] list: List of words separated by comma (by default).
      • Example: Text.list() will receive a list of Text and will be concatenated separated with comma by default. It may be unnecessary. Can help to make the code more readable.
    • [Opt] sep: Text separator.
      • Example: Text.sep(), by default, will insert " " in a list of Text instances, but it will be able to do more things that I don't know yet, hehe. It may be unnecessary. Can help to make the code more readable.
Comments
  • Add Notion API versioning date

    Add Notion API versioning date

    When I first using this package, the package did not work because Notion enforcing "Notion-Version" header requirement for all API requests on July 1st. Because of that, I add the header requirement into this package.

    Sorry, I didn't do unit testing the code beforehand, I hope it will works just fine.

    opened by bagaswastu 4
  • New version (v1.2.0)

    New version (v1.2.0)

    • Implement new endpoints
      • Update page: https://developers.notion.com/reference/patch-page#archive-delete-a-page
      • Create database: https://developers.notion.com/reference/create-a-database
    • Add Page support for responses
    • Add more colors for Text
    • Add list of endpoints implemented on package
    • Improve coverage
    opened by jonathangomz 3
  • v1.2.1

    v1.2.1

    This PR branch started for the version 1.2.1 but because of the breaking changes this will be a new beta for a new major version: 2.0.0

    New feature: 🐣 Breaking change: πŸ—

    • 🐣 Add constructor for empty Database. βœ…
    • 🐣 Add parameter blocks for Children constructor. βœ…
    • πŸ— Remove deprecated code: βœ…
      • textSeparation
      • Parameter constructors for Children:
        • heading
        • paragraph
        • toDo
    • 🐣 Add suggestions on issue #11: βœ…
      • Update exports to improve usage
      • Add private folder (src/)
    • 🐣 Add constructors with only single text content with default style for: βœ…
      • Paragraph: Paragraph.text('some text here...')
      • ToDo: ToDo.text('some text here...', checked: true)
      • Heading: Heading.text('some text here...', type: 2)
      • BulletedListItem: BulletedListItem.text('some text here...')
      • NumberedListItem: NumberedListItem.text('some text here...')
      • Toggle: Toggle.text('some text here...', children: [])
    • 🐣 Add more constructors for Heading class:
      • one: Heading with type 1 by default.
      • two: Heading with type 2 by default.
      • three: Heading with type 3 by default.
    • 🐣 Add more constructors for Text class: βœ…
      • code: Text with code style by default.
      • italic: Text with italic style by default.
      • bold: Text with bold style by default.
      • underline: Text with underline style by default.
      • color: Text with different color of default.
    • 🐣 Add list(List<Text> texts, String separator, String lastSeparator): βœ…
    opened by jonathangomz 2
  • v1.1.0

    v1.1.0

    • Add more blocks support for (PATCH): block children endpoint
      • BulletedListItem block
      • NumberedListItem block
      • Toggle block
    • Add children field for blocks:
      • BulletedListItem
      • NumberedListItem
      • ToDo
      • Toggle
      • Paragraph
    • Add methods to manipulate content and children for blocks:
      • addText(String text, {TextAnnotations? annotations})
      • addChild(Block block)
      • addChildren(List<Block> blocks)
    • Add Children.withBlocks(List<Block> blocks) constructor
    • Add final for type fields to not allow overwrite:
      • Objects
      • Blocks
    • Add BaseClient class to avoid duplicated code for clients
    • Add deprecated annotations for future changes:
      • Remove textSeparation parameter/field
      • Remove add(Text text) function
      • Remove texts getter for Paragraph
      • Remove named parameters for Children class
    • Update documentation
    opened by jonathangomz 1
  • v1.0.0-beta

    v1.0.0-beta

    Entry point for all changes for the ßeta version of 1.0.0

    v1.0.0-beta1:

    • Improve code implementation
      • Refactor package structure
      • Refactor some properties & function names
      • Add useful functions
      • Separate classes to avoid duplicated code
    • Add more tests
      • Tests for every piece of code
      • Separate tests by sections
    • Improve code documentation
    • Improve Pub Points
    • Add custom response
    • Remove dependency for flutter

    v1.0.0-beta2:

    • Fix any error
    • Tests for every piece of code
    • Improve test coverage
    • Improve docs
    opened by jonathangomz 1
  • v0.0.1-beta1

    v0.0.1-beta1

    First beta version of the Notion API package.

    What this change includes:

    • Update to null-safety
    • Improve environment variables implementation
    • Add CI with GitHub Actions
    • Add notion api endpoints: block children
      • Retrieve block children
      • Append block children
        • Note: Only Paragraph (with Text) & Heading types are working
    • Add block children API request tests
    opened by jonathangomz 1
  • v0.0.1 dev.2

    v0.0.1 dev.2

    Changes:

    • Add notion api endpoints: databases
      • Retrieve a database
      • Retrieve all databases
        • Note: page_size & start_cursor query parameters are available
    • Add database tests
    • Add title field to Page constructor
    • Add static API information (host, api version) on separated file
    opened by jonathangomz 0
  • How to work with typed blocks by design?

    How to work with typed blocks by design?

    Hi, please explain how you design work with typed Block (e.g. Paragraph) after retrieve Page?

      NotionResponse resBlocks =
          await notion.blocks.list(block_id: 'YYYYYYYYY');
      Pagination paging = resBlocks.content;
      for (Block block in paging.blocks) {
        if (block.isParagraph) {
          //<-- HOW TO GET Paragraph Object ?
        }
      }
    `
    
    opened by broderix 2
  • Parent mapping throws exception

    Parent mapping throws exception

    Thanks for the api, I'm eager to use it!

    Databases attached to workspaces returns following part for parent mapping. Since id is set by using type property, json[json["type"]] returns true and fail to cast string.

    Here is sample from response:

     "parent": {
        "type": "workspace",
        "workspace": true
     }
    
    opened by ahmetcj4 1
  • User accesses texts from an own page dynamically

    User accesses texts from an own page dynamically

    With this lib is it possible for users to dynamically access information from 1 page itself? It can only be texts. Example: User A accesses - Page A, User B accesses - Page B.

    opened by lukiinhas1616 1
  • v2.0.0

    v2.0.0

    Update at 24/Feb/2022 at the 02:53 am, because why not: I'm doing a huuuuuge update for this package and I will be using this version (2.0.0) for that update. Practically I'm going to break all (even me) and do it again. I'm going to reuse a lot of code but I HAVE TO update and fix a lot of logic bugs. I don't know when I'm going to finish but to say something let say 31/03/2022.

    If someone read this please wish me luck.

    See my notes here in Notion of course.

    • [x] Update default versioning usage: always will work with only the last version. If any other version is needed then should install a previous version of the package for that version to avoid errors on differences between versions.
    • [ ] Access child type from parent
      • [ ] Properties
        • [x] Database properties
        • [ ] Page properties
      • [ ] Blocks
      • [ ] Objects
    • [ ] Refactor sections
      • [ ] Utils
        • [ ] Extension for enums to have a toString() (and maybe toType()) built-in instead of fromXTypeToString and that stuff.
      • [ ] Properties
        • [x] Database properties (Properties objects)
        • [ ] Page properties (Properties value)
        • [ ] Properties items
      • [x] Databases
        • [x] Create
        • [x] Update
        • [x] Retrieve
      • [ ] Pages
        • [ ] Retrieve
        • [ ] Create
        • [ ] Update
        • [ ] Archive (Delete)
        • [ ] Retrieve a page property
      • [ ] Blocks
        • [ ] Children
          • [ ] Retrieve a block children
          • [ ] Append block children
        • [ ] Delete
    • [ ] Fix GitHub issues.
      • [ ] #16 Problem: The users cannot access to the block content from pagination because use the Block class and it not contains a content field or something like that. Solution: See how new database properties works and do the same for blocks.
      • [ ] #15 Problem: ? Solution: I don’t even understand the problem.
      • [ ] #14 Problem: The package use a different structure from the official package on JavaScript. Solution: Follow a similar structure. At least at usage level.

    Important: Some of the changes bellow will be canceled even they where accomplished just in the name of YAGNI (You Ain't Gonna Need It), and other will be added... actually a lot of things will change and even me, who is making them, don't know how is going to end, so yeah, don't pay attention to the list bellow.


    This PR will be open until the next release (tentative date 04/08/2021). It will contain any pre-release update for this version.

    New feature: 🐣 Breaking change: πŸ—

    • 🐣 Add constructor for empty Database.βœ…
    • 🐣 Add parameter blocks for Children constructor. βœ…
    • πŸ— Remove deprecated code: βœ…
      • textSeparation
      • Parameter constructors for Children:
        • heading
        • paragraph
        • toDo
    • πŸ— Add suggestions on issue #11: βœ…
      • Copy some terminologies from notion-sdk-js
      • Update exports to improve usage
      • Add private folder (src/)
    • 🐣 Add constructors with only single text content with default style for: βœ…
      • Paragraph: Paragraph.text('some text here...')
      • ToDo: ToDo.text('some text here...', checked: true)
      • Heading: Heading.text('some text here...', type: 2)
      • BulletedListItem: BulletedListItem.text('some text here...')
      • NumberedListItem: NumberedListItem.text('some text here...')
      • Toggle: Toggle.text('some text here...', children: [])
    • [CANCELED] ~~🐣 Add more constructors for Heading class:~~
      • ~~one: Heading with type 1 by default.~~
      • ~~two: Heading with type 2 by default.~~
      • ~~three: Heading with type 3 by default.~~
    • 🐣 Add more constructors for Text class: βœ…
      • code: Text with code style by default.
      • italic: Text with italic style by default.
      • bold: Text with bold style by default.
      • underline: Text with underline style by default.
      • color: Text with different color of default.
    • 🐣 Add list(List<Text> texts, String separator, String lastSeparator): βœ…
    opened by jonathangomz 3
  • Follow proper package guidelines

    Follow proper package guidelines

    I just started using your package and see that I have to import every file separately for your notion package. There are 2 conventions you need to follow which is used by all packages.

    1. Could you please update your package to export all required files properly so that we don't have too many dependencies on file imports in our classes. Currently for this small bit of code.
      Future<void> createPage({required String pageId}) {
        Page page = Page(
          parent: Parent.page(id: 'YOUR_PAGE_ID'), // <- page
          title: Text('NotionClient (v1): Page test'),
        );
      }
    

    I have to import all of this

    import 'package:notion_api/notion.dart';
    import 'package:notion_api/notion/general/rich_text.dart';
    import 'package:notion_api/notion/objects/pages.dart';
    import 'package:notion_api/notion/objects/parent.dart';
    

    It should only be

    import 'package:notion_api/notion.dart';
    

    To achieve this all you have to do is declare an export in your notion.dart file.

    export 'notion/general/rich_text.dart';
    export 'notion/objects/pages.dart';
    export 'notion/objects/parent.dart';
    
    1. Move private code into a folder called src. At the moment it's all accessible and when you do improve your code it will break all projects that use this. It's better to do it early.
    opened by FilledStacks 6
Releases(v2.0.0-beta2)
  • v2.0.0-beta2(Aug 6, 2021)

  • v2.0.0-beta1(Jul 30, 2021)

    New feature: 🐣 Breaking change: πŸ—

    • 🐣 Add constructor for empty Database.
    • 🐣 Add parameter blocks for Children constructor.
    • πŸ— Remove deprecated code:
      • textSeparation
      • Parameter constructors for Children:
        • heading
        • paragraph
        • toDo
    • 🐣 Add suggestions on issue #11:
      • Update exports to improve usage
      • Add private folder (src/)
    • 🐣 Add constructors with only single text content with default style for:
      • Paragraph: Paragraph.text('some text here...')
      • ToDo: ToDo.text('some text here...', checked: true)
      • Heading: Heading.text('some text here...', type: 2)
      • BulletedListItem: BulletedListItem.text('some text here...')
      • NumberedListItem: NumberedListItem.text('some text here...')
      • Toggle: Toggle.text('some text here...', children: [])
    • 🐣 Add more constructors for Heading class:
      • one: Heading with type 1 by default.
      • two: Heading with type 2 by default.
      • three: Heading with type 3 by default.
    • 🐣 Add more constructors for Text class:
      • code: Text with code style by default.
      • italic: Text with italic style by default.
      • bold: Text with bold style by default.
      • underline: Text with underline style by default.
      • color: Text with different color of default.
    • 🐣 Add list(List<Text> texts, String separator, String lastSeparator):
      • A static method
      • Generate a textual list of texts separated by comma (by default).
    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Jul 27, 2021)

    • Implement new endpoints
      • Update page: https://developers.notion.com/reference/patch-page#archive-delete-a-page
      • Create database: https://developers.notion.com/reference/create-a-database
    • Add Page support for responses
    • Add more colors for Text
    • Add list of endpoints implemented on package
    • Improve coverage
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Jul 11, 2021)

    • Add more blocks support for (PATCH): block children endpoint
      • BulletedListItem block
      • NumberedListItem block
      • Toggle block
    • Add children field for blocks:
      • BulletedListItem
      • NumberedListItem
      • ToDo
      • Toggle
      • Paragraph
    • Add methods to manipulate content and children for blocks:
      • addText(String text, {TextAnnotations? annotations})
      • addChild(Block block)
      • addChildren(List<Block> blocks)
    • Add Children.withBlocks(List<Block> blocks) constructor
    • Add final for type fields to not allow overwrite:
      • Objects
      • Blocks
    • Add BaseClient class to avoid duplicated code for clients
    • Add deprecated annotations for future changes:
      • Remove textSeparation parameter/field
      • Remove add(Text text) function
      • Remove texts getter for Paragraph
      • Remove named parameters for Children class
    • Update documentation
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Jul 5, 2021)

  • v1.0.0(Jul 5, 2021)

  • v1.0.0-beta2(Jun 22, 2021)

  • v1.0.0-beta1(Jun 16, 2021)

    • Improve code implementation
      • Refactor package structure
      • Refactor some properties & function names
      • Add useful functions
      • Separate classes to avoid duplicated code
    • Add more tests
      • Tests for every piece of code
      • Separate tests by sections
    • Improve code documentation
    • Improve Pub Points
    • Add custom response
    • Remove dependency for flutter
    Source code(tar.gz)
    Source code(zip)
  • v0.0.1(Jun 1, 2021)

  • v0.0.1-beta1(May 26, 2021)

    • Update to null-safety
    • Improve environment variables implementation
    • Improve documentation
      • Add public docs for code
      • Add examples
    • Add CI with GitHub Actions
    • Add notion api endpoints: block children
      • Retrieve block children
      • Append block children
        • Note: Only Paragraph (with Text) & Heading types are working
    • Add block children API request tests
    Source code(tar.gz)
    Source code(zip)
  • v0.0.1.dev.1(May 20, 2021)

  • v0.0.1-prealpha1(May 20, 2021)

    • First version
    • Add page requests parameters models
    • Add notion api endpoints: pages
      • Retrieve a page
      • Create a page
        • Note: Accept only basic content: title & parent.
    • Add database tests
    Source code(tar.gz)
    Source code(zip)
  • v0.0.1-dev.2(May 20, 2021)

    • Add notion api endpoints: databases
      • Retrieve a database
      • Retrieve all databases
        • Note: page_size & start_cursor query parameters are available
    • Add database tests
    • Add title field to Page constructor
    • Add static API information (host, api version) on separated file
    Source code(tar.gz)
    Source code(zip)
Owner
Jonathan GΓ³mez
Code writer and sometimes a normal person
Jonathan GΓ³mez
ThingsBoard PE API client library for Dart developers.

ThingsBoard PE API client library for Dart developers. It's compatible with TB PE 3.3.0. Usage A simple usage example: import 'package:thingsboard_pe_

ThingsBoard - Open-source IoT Platform 45 Sep 28, 2022
Figma API client written in pure Dart

figma A library for interacting with Figma APIs. Created from templates made available by Stagehand under a BSD-style license. Usage A simple usage ex

Arne Molland 14 Oct 19, 2022
A fully cross-platform wrap of the Matomo tracking client for Flutter, using the Matomo API.

A fully cross-platform wrap of the Matomo tracking client for Flutter, using the Matomo Tracking API.

Floating Dartists 12 Jan 8, 2023
A simple and easy to use Redis client for Dart

redis_dart A simple and minimalist Redis client for Dart See it in pub: https://pub.dev/packages/redis_dart and GitHub: https://github.com/gabrielpach

Gabriel Pacheco 7 Dec 25, 2022
Wallet Connect client in Dart.

Wallet Connect Wallet Connect client in dart highly inspired from wallet-connect-kotlin by Trust Wallet. Usage import 'package:wallet_connect/wall

null 101 Dec 29, 2022
A dart client for Supabase Realtime server.

realtime-dart Listens to changes in a PostgreSQL Database and via websockets. A dart client for Supabase Realtime server. Usage Creating a Socket conn

Supabase Community 76 Dec 14, 2022
With ML Kit's face detection API, you can detect faces in an camera or image, Note that the API detects faces, it does not recognize people

Face Detection This project is a starting point for a Flutter application. Getting Started For help getting started with Flutter, view our online docu

Nashwan Abdullah 21 Dec 29, 2022
Weather-App-Api- - Simple Realtime Weather App With Api

music_app A new Flutter Weather App project. Getting Started // Ψ§ΩˆΩ„ Ψ­Ψ§Ψ¬Ω‡ ΨͺΨΉΩ…Ω„ en

Youssif El Sayed 5 Nov 11, 2022
Lime client built using flutter

** This project ist OUT OF DATE and I am currently not able to maintain it ** What we are building Lime is a social media app, which allows you to pos

Sebastian Sellmair 376 Dec 24, 2022
An architecture for dynamic UI without client deployment

Server Driven UI Demo Server Driven UI(SDUI)λŠ” μ„œλ²„μ—μ„œ ν΄λΌμ΄μ–ΈνŠΈμ˜ UI μ»΄ν¬λ„ŒνŠΈλ₯Ό κ΄€λ¦¬ν•˜λŠ” 방식. ν΄λΌμ΄μ–ΈνŠΈ 배포없이 API 응닡을 λ³€κ²½ν•˜λŠ” κ²ƒλ§ŒμœΌλ‘œ UI 변경이 κ°€λŠ₯ν•œ λ™μ‹œμ— ν•˜μœ„ ν˜Έν™˜μ„±μ„ 확보할 수 μžˆλ‹€. Rust, GraphQ

Simon Park 15 Oct 17, 2022
Invoice Ninja client built with Flutter

Invoice Ninja Client app for the Invoice Ninja web app. Google Play Store: v4 | v5 Apple App Store: v4 | v5 Setting up the app Initialize the config f

Invoice Ninja 1.3k Dec 25, 2022
A simple, modern AppImageHub Client, powered by flutter.

AppImagePool Simple AppImageHub Client Main Features FLOSS and non profit app Simple categories Download from github directly, no extra-server involve

Prateek SU 490 Jan 1, 2023
Dalal Street Client 2022

Flutter Client for Dalal Street Prerequisites Flutter >2.12 Download Link Protocol Buffer Compiler Download Link Check Prerequisites Run if you have i

Delta Force 15 Dec 22, 2022
An Android Client for ZeroNet Built With Flutter

ZeroNet Mobile ZeroNet Mobile is an Android Client for ZeroNet, a platform for decentralized websites using Bitcoin crypto and the BitTorrent network.

null 0 Nov 10, 2021
A Mastodon client built in Flutter

feathr A Mastodon client built in Flutter (in development). Contributing Pull requests are welcome. For major changes, please open an issue first to d

feathr.space 8 Nov 25, 2022
βš—οΈA privacy centric matrix client

a privacy centric matrix client - now in open alpha* Syphon is still in alpha and we do not recommend using it where proven and independently verified

Syphon 882 Dec 31, 2022
Chopper is an http client generator using source_gen and inspired from Retrofit.

Chopper Chopper is an http client generator for Dart and Flutter using source_gen and inspired by Retrofit. Documentation Installation Please refer to

Hadrien Lejard 632 Dec 31, 2022
NETCoreSync is a database synchronization framework where each client's local offline database

NETCoreSync NETCoreSync is a database synchronization framework where each client's local offline database (on each client's multiple devices) can be

Aldy J 65 Oct 31, 2022