10000 GitHub - hognevevle/notion-sdk-net: A Notion SDK for .Net
[go: up one dir, main page]

Skip to content

hognevevle/notion-sdk-net

 
 

Repository files navigation

Notion SDK for .Net

A simple and easy to use client for the Notion API


GitHub release (latest SemVer) GitHub

Build Status Build artifacts Publish Code CodeQL

LGTM Alerts LGTM Grade

GitHub last commit GitHub commit activity GitHub commit activity GitHub commit activity

GitHub repo size Lines of code

Provides the following packages:

Package Downloads Nuget
Notion.Net Nuget Nuget Nuget (with prereleases)

Installation

.Net CLI

dotnet add package Notion.Net

Note: From Nuget 2.0.0 notion client sdk default sets the Notion-Version header to 2021-08-16.

Usage

Before getting started, you need to create an integration and find the token. You can learn more about authorization here.

Import and initialize the client using the integration token created above.

var client = new NotionClient(new ClientOptions
{
    AuthToken = "<Token>"
});

Make A request to any Endpoint. For example you can call below to fetch the paginated list of users.

var usersList = await client.Users.ListAsync();

Querying a database

After you initialized your client and got an id of a database, you can query it for any contained pages. You can add filters and sorts to your request. Here is a simple example:

// Date filter for page property called "When"
var dateFilter = new DateFilter("When", onOrAfter: DateTime.Now);

var queryParams = new DatabasesQueryParameters { Filter = dateFilter };
var pages = await client.Databases.QueryAsync(databaseId, queryParams);

Filters constructors contain all possible filter conditions, but you need to choose only condition per filter, all other should be null. So, for example this code would not filter by 2 conditions as one might expect:

var filter = new TextFilter("Name", startsWith: "Mr", contains: "John"); // WRONG FILTER USAGE

To use complex filters, use class CompoundFilter. It allows adding many filters and even nesting compound filters into each other (it works as filter group in Notion interface). Here is an example of filter that would return pages that were due in past month AND either had a certain assignee OR had high urgency:

var selectFilter = new SelectFilter("Urgency", equal: "High");
var assigneeFilter = new PeopleFilter("Assignee", contains: "some-uuid");
var dateFilter = new DateFilter("Due", pastMonth: new Dictionary<string, object>());

var orGroup = new List<Filter> { assigneeFilter, selectFilter };
var complexFiler = new CompoundFilter(
    and: new List<Filter> { dateFilter, new CompoundFilter(or: orGroup) }
);

Supported Endpoints

  • Databases
    • Query a database
    • Create a database
    • Update database
    • Retrieve a database
    • List databases (Deprecated: use Search API instead)
  • Pages
    • Retrieve a page
    • Create a page
    • Update page
  • Blocks
    • Retrieve a block
    • Update a block
    • Retrieve block children
    • Append block children
    • Delete a block
  • Users
    • Retrieve a User
    • List all users
    • Retrieve your token's bot user
  • Search

Contributors

This project exists thanks to all the people who contribute.

contributor image

Contribution Guideline

Hello! Thank you for choosing to help contribute to this open source library. There are many ways you can contribute and help is always welcome. You can read the detailed Contribution Guideline defined here - we will continue to improve it.

About

A Notion SDK for .Net

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%
0