Notion Offical API client library for rust

Overview

notion

Build Crates.io

Notion API client library for rust.

This project is under active development and this README will be updated as this library gets closer to a reliable state. However, if you're really eager see the example todo cli application provided in examples/todo.

Building

cargo build
Comments
  • Implement page creation

    Implement page creation

    I am currently working on a create page feature to use in a program I'm writing to do more pleasant data entry.

    This PR is a work in progress, I still need to write some tests (after I get my program working past the risk-of-abandonment stage).

    opened by lf- 1
  • Add support for code blocks

    Add support for code blocks

    Fairly straightforward copy of what the other code is doing, and works when used on pages with code examples.

    text is a list of rich text objects, and language is an effectively unbounded list of potential languages, so string seemed preferable to an enum.

    opened by nxsy 1
  • Example wasn't compling + lib fixes

    Example wasn't compling + lib fixes

    Rust newb here, Example app wasn't working because of the changes in clap. Library wasn't working too, at least part that was querying database. I also added get_page method which is minimal changes, everything for it was already read :) I also not found a way how to transfor string into DatabaseId or any other Identifier, so i modified macros a bit by adding FromStr method. Without these changes library is not currently usable.

    opened by flamedmg 1
  • Deserialization error with number property

    Deserialization error with number property

    I'm getting an error when using search():

    JsonParseError {
        source: Error("missing field `format`", line: 1, column: 1425),
    }
    

    My code:

    use notion::models::search::NotionSearch;
    use notion::NotionApi;
    use std::env;
    
    #[tokio::main]
    async fn main() {
        let notion_api = NotionApi::new(env::var("NOTION_API_TOKEN").unwrap()).unwrap();
        let query: NotionSearch = {
            NotionSearch::Query(String::from("Movie Collection"))
        };
        let result = notion_api.search(query).await;
        match result {
            Ok(resp) => println!("{:#?}", resp),
            Err(err) => println!("{:#?}", err),
        }
    }
    

    Saved JSON from curl:

    {
      "object": "list",
      "results": [
        {
          "object": "database",
          "id": "58be2827-5ca0-4cc4-85a8-ff656911df67",
          "created_time": "2021-03-07T19:20:00.000Z",
          "last_edited_time": "2021-07-11T22:04:00.000Z",
          "title": [
            {
              "type": "text",
              "text": { "content": "Movie Collection", "link": null },
              "annotations": {
                "bold": false,
                "italic": false,
                "strikethrough": false,
                "underline": false,
                "code": false,
                "color": "default"
              },
              "plain_text": "Movie Collection",
              "href": null
            }
          ],
          "properties": {
            "Watched": { "id": "<dji", "type": "checkbox", "checkbox": {} },
            "Cover": { "id": "VWBk", "type": "files", "files": {} },
            "Type": {
              "id": "]iu{",
              "type": "select",
              "select": {
                "options": [
                  {
                    "id": "522ab335-108c-4a92-a2d6-0aeee7b946c8",
                    "name": "Blu-Ray",
                    "color": "blue"
                  },
                  {
                    "id": "12f11180-47bd-4c36-abb8-c84c35ade60c",
                    "name": "Digital",
                    "color": "green"
                  }
                ]
              }
            },
            "Year": {
              "id": "jwIv",
              "type": "number",
              "number": { "format": "number" }
            },
            "Director": {
              "id": "~psh",
              "type": "select",
              "select": {
                "options": [
                  {
                    "id": "d1023a7a-52af-4c2f-aabf-cac75b59e9bd",
                    "name": "Hirozaku Kore-eda",
                    "color": "yellow"
                  },
                  {
                    "id": "45bd4057-eddc-4bf2-be59-a693f4f81f05",
                    "name": "Hayao Miyazaki",
                    "color": "pink"
                  },
                  {
                    "id": "a1a2896b-26f0-410b-8205-fda67c9edb99",
                    "name": "Doug Liman",
                    "color": "orange"
                  },
                  {
                    "id": "f9854b2d-b913-454f-b18c-ce312fa1d9e4",
                    "name": "Steven Soderbergh",
                    "color": "green"
                  }
                ]
              }
            },
            "Title": { "id": "title", "type": "title", "title": {} }
          },
          "parent": {
            "type": "page_id",
            "page_id": "2ffcd525-17b1-4606-93ff-e367eade9e66"
          }
        }
      ],
      "next_cursor": null,
      "has_more": false
    }
    

    I'm fairly new to Rust, but it seems like there's a mismatch in the property schema versus what's returned. If I delete this line the code runs successfully (albeit without the number's format): https://github.com/jakeswenson/notion/blob/9d5b84b88ddc2b7de1bc0f03d9026eb52e8976ac/src/models/properties.rs#L133

    Or if I add:

    #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
    pub struct NumberFmt {
        format: String
    }
    

    and change the line to number: NumberFmt that also works, this time with the number's format as a string. I couldn't get it to work with the existing NumberFormat enum.

    opened by austinbutler 1
  • ci: Add forks build support to Build

    ci: Add forks build support to Build

    Uses: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target

    This may be a bad idea... https://securitylab.github.com/research/github-actions-preventing-pwn-requests/

    Probably best to get pull_request working which means no secrets are available...

    opened by jakeswenson 1
  • Get Block Children

    Get Block Children

    Description

    Generic implementation of retrieving block information. I have yet to enumerate different fields for specific Block types.

    Fixed some visibility issues for people using this client externally. Fixed an casing issue when deserializing Url types

    opened by bspradling 1
  • Rollups are not parsed properly

    Rollups are not parsed properly

    Hello, usually it try to fix things myself, but this issue i don't have straight way how to fix. Please take a look at json returned by notion:

            "properties": {
        "Is Subscription": {
          "id": "%3E%7Dfd",
          "type": "checkbox",
          "checkbox": false
        },
        "Base Price": {
          "id": "AuNU",
          "type": "number",
          "number": 29.95
        },
        "Product Type Code": {
          "id": "R%7Cm%3F",
          "type": "rollup",
          "rollup": {
            "type": "array",
            "array": [
              {
                "type": "rich_text",
                "rich_text": [
                  {
                    "type": "text",
                    "text": {
                      "content": "personal",
                      "link": null
                    },
                    "annotations": {
                      "bold": false,
                      "italic": false,
                      "strikethrough": false,
                      "underline": false,
                      "code": false,
                      "color": "default"
                    },
                    "plain_text": "personal",
                    "href": null
                  }
                ]
              }
            ],
            "function": "show_original"
          }
        },
    ......
    }
    

    Rollup contains an array, which contains PropertyValue. There are two issues: RollupValue exists that probably was meant to solve this issue, but it's not used anywhere. If i create property array and make it a Option<Vec>, i will have an issue. Rich text node does not have an ID. Making this field optional is not a good idea imho.

    Please suggest how to better solve this issue, and i will be happy to implement and issue PR

    bug 
    opened by flamedmg 0
  • Url property can be null

    Url property can be null

    Hello again :) This is small change that i found is required for my code to work properly. Url property can be returned as null, here is an example json returned by notion: image

    opened by flamedmg 0
  • build(audits): Split security audit out of build workflow

    build(audits): Split security audit out of build workflow

    There are currently unfixable issues with chrono 0.4.19 in security audits... Until these are fixable they are just showing up as build failures Splitting this into its own workflow is probably the correct thing long term anyways

    opened by jakeswenson 0
  • Get Children Blocks

    Get Children Blocks

    Description

    Generic implementation of retrieving block information. I have yet to enumerate different fields for specific Block types.

    Fixed some visibility issues for people using this client externally. Fixed an casing issue when deserializing Url types

    Recreating PR to be a branch instead of fork.

    opened by bspradling 0
  • Search Assumes Database Response

    Search Assumes Database Response

    Description

    The search endpoint is the generic way to look for a particular resource within a Notion organization. Currently, the client is returning a Result<ListResponse<Database>, NotionApiClientError>. This makes an assumption that it is a Database when it could be a Page.

    Documentation

    In the API Reference, there are two results in the payload. The first contains the assumed object: database but the second has object: page.

    Current Response

    The client gives an Error when the result contains a Page:

    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("missing field `title`", line: 1, column: 545)'

    Expected Behavior

    That you can successfully retrieve Database and Page objects via the search endpoint.

    opened by bspradling 0
  • Querying database requires full user info access

    Querying database requires full user info access

    Hello! I have the following code, in a project where I don't need full user info, just the base (without the email). If I don't have the e-mail permission granted, the code crashes with the error below, but with the permission granted it successfully queries.

    // The query
    let results = notion_api
        .query_database(db, DatabaseQuery::default())
        .await?;
    
    // The error without any user info beyond ID
    Error: Error parsing json response: missing field `type`
    
    Caused by:
        missing field `type`
    
    // The error with user info without email
    Error: Error parsing json response: missing field `email`
    
    Caused by:
        missing field `email`
    

    IMHO, those should either be optional, or on an enum/nested struct, and not require full permissions (otherwise, could it be mentioned in the README?)

    opened by Arteneko 0
  • How can I search for `Pages` only?

    How can I search for `Pages` only?

    It seems that there is only one implementation of filter_by_databases. Is there any need to add an implementation for filter_by_pages?

    BTW, the API list_databases is departed, I got a 400 error when I use it.

    opened by ruiqurm 0
  • RUSTSEC-2021-0139: ansi_term is Unmaintained

    RUSTSEC-2021-0139: ansi_term is Unmaintained

    ansi_term is Unmaintained

    | Details | | | ------------------- | ---------------------------------------------- | | Status | unmaintained | | Package | ansi_term | | Version | 0.12.1 | | URL | https://github.com/ogham/rust-ansi-term/issues/72 | | Date | 2021-08-18 |

    The maintainer has adviced this crate is deprecated and will not receive any maintenance.

    The crate does not seem to have much dependencies and may or may not be ok to use as-is.

    Last release seems to have been three years ago.

    Possible Alternative(s)

    The below list has not been vetted in any way and may or may not contain alternatives;

    See advisory page for additional details.

    opened by github-actions[bot] 0
  • RUSTSEC-2018-0015: term is looking for a new maintainer

    RUSTSEC-2018-0015: term is looking for a new maintainer

    term is looking for a new maintainer

    | Details | | | ------------------- | ---------------------------------------------- | | Status | unmaintained | | Package | term | | Version | 0.6.1 | | URL | https://github.com/Stebalien/term/issues/93 | | Date | 2018-11-19 |

    The author of the term crate does not have time to maintain it and is looking for a new maintainer.

    Some maintained alternatives you can potentially switch to instead, depending on your needs:

    See advisory page for additional details.

    opened by github-actions[bot] 0
  • RUSTSEC-2020-0056: stdweb is unmaintained

    RUSTSEC-2020-0056: stdweb is unmaintained

    opened by github-actions[bot] 0
Releases(v0.4.1)
🦀 Zulip API Library Rust Client

Zulip API Client Library Rust Crate This repo contains the code for an unofficial, third-party Zulip API client library crate written in the Rust prog

Manuel Nila 3 Oct 23, 2022
Modrinth API is a simple library for using, you guessed it, the Modrinth API in Rust projects

Modrinth API is a simple library for using, you guessed it, the Modrinth API in Rust projects. It uses reqwest as its HTTP(S) client and deserialises responses to typed structs using serde.

null 21 Jan 1, 2023
Luno API Client written in Rust Language for Rustaceans :)

The Luno API provides developers with a wealth of financial information provided through the Luno platform

borngraced 4 Dec 22, 2022
Meteor Client Installer - Installer to automate the install of Fabric and Meteor Client

This is an installer that automates the install of Meteor and Fabric

Jake Priddle 3 Jun 23, 2021
An asynchronous API client for a light installation at the University of Kiel

An asynchronous API client for a light installation at the University of Kiel

FW 2 Nov 22, 2022
API wrapper for the tankerkönig api

tankerkoenig-rs API wrapper for the tankerkoenig-api written in rust. Gives you ready deserialized structs and a easy to use and strictly typed api. I

Jonathan 2 Feb 27, 2022
A repository full of manually generated hand curated JSON files, which contain the API Types that the Discord API returns.

Discord API Types A repository full of manually generated hand curated JSON files, which contain the API Types that the Discord API returns. Also did

Unofficial Discord Documentation 1 Sep 16, 2022
Yet another ROS2 client library written in Rust

RclRust Target CI Status Document Foxy (Ubuntu 20.04) Introduction This is yet another ROS2 client library written in Rust. I have implemented it inde

rclrust 42 Dec 1, 2022
Ocular seeks to be the preferred cosmos client library UX for Rust projects

Ocular seeks to be the preferred cosmos client library UX for Rust projects. It is strongly based on lens, a go client library for blockchains built with the Cosmos SDK.

Peggy JV, Inc 34 Dec 26, 2022
Wrapper library for utilizing DigitalOcean API v2 in Rust

doapi-rs Wrapper library for utilizing DigitalOcean API v2 in Rust Disclaimer This library is in alpha - it may do anything up to, and including, eati

Kevin K. 30 Nov 5, 2022
Serenity is a Rust library for the Discord API

serenity Serenity is a Rust library for the Discord API. View the examples on how to make and structure a bot. Serenity supports bot login via the use

serenity 3.3k Jan 2, 2023
librdkafka - the Apache Kafka C/C++ client library

librdkafka - the Apache Kafka C/C++ client library Copyright (c) 2012-2020, Magnus Edenhill. https://github.com/edenhill/librdkafka librdkafka is a C

Magnus Edenhill 6.4k Dec 31, 2022
A library to access BGPKIT Broker API and enable searching for BGP data archive files over time from public available data sources.

BGPKIT Broker BGPKIT Broker is a online data API service that allows users to search for publicly available BGP archive files by time, collector, proj

BGPKIT 10 Nov 30, 2022
A library for working with alpaca.markets APIs, including the Broker API.

alpaca-rs, an unofficial Rust SDK for the Alpaca API (WIP) Features Easy to use - Minimal setup and no boilerplate. Cross-platform - can run on most p

null 4 Dec 2, 2023
Rust client for Pushover

Pushover RS Description It's a Rust client library you can use to interact with the Pushover messaging API. This client is unofficial and I'm in no wa

Emmanuel C. 4 Dec 9, 2022
A variation of the solana helloworld program example with a client written in Rust instead of Typescript

Simple Solana Smart Contract Example This repository demonstrates how to create and invoke a program on the Solana blockchain. In Solana the word prog

zeke 56 Dec 26, 2022
Feign-RS (Rest client of Rust)

Feign-RS (Rest client of Rust)

null 9 Aug 12, 2022
A Rust client for the NOAA Weather Wire Service Open Interface.

nwws-oi A Rust client for the NOAA Weather Wire Service Open Interface. NWWS-OI is one of several platforms through which the National Weather Service

Will Glynn 3 Sep 15, 2022
A simple external client made with rust

A simple external client made with rust

null 2 Mar 19, 2022