Expand description
§Notion Tools
notion-tools
is a library for interacting with the Notion API. It provides a convenient way to
perform various operations such as retrieving databases, querying databases, creating pages,
updating pages, archiving pages, and appending block children.
§Usage
To use this library, you need to set the NOTION_API_KEY
and NOTION_DATABASE_ID
environment
variables. The NOTION_API_KEY
is required for authentication, while the NOTION_DATABASE_ID
is optional and can be set later using the database
method.
§Implemented endpoints
§Build a query filter
The QueryFilter
struct is used to build a query filter for querying a database. The QueryFilter
struct provides methods for building a filter that can be used to query a database.
See the QueryFilter
struct for more information.
§Examples
§Create a page
let notion = Notion::new();
// Create a page
let mut properties: FxHashMap<String, PageProperty> = FxHashMap::default();
properties.insert(
String::from("Name"),
PageProperty::title(RichText::from_str(String::from("Sample Page"))),
);
properties.insert(
String::from("Title"),
PageProperty::rich_text(vec![RichText::from_str(String::from("Sample Page"))]),
);
properties.insert(String::from("Status"), PageProperty::status(String::from("ToDo")));
let mut page = Page::from_properties(properties);
page.parent.type_name = ParentType::Database;
page.parent.database_id = Some(notion.database_id.clone());
let response = notion.create_a_page(&page).await;
println!("{:?}", response);
§Query a database
let mut notion = Notion::new();
notion.database(String::from("your_database_id"));
// Build a query filter
let mut filter = QueryFilter::new();
filter.args(FilterItem::status(
String::from("Status"),
StatusFilterItem::equals(String::from("ToDo")),
));
// Query a database
let response = notion.query_database(filter).await?;
println!("{:?}", response);
Modules§
Structs§
- Notion
- Notion API client