Notion.Net 4.0.0-preview-3.9.1.2022

This is a prerelease version of Notion.Net.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Notion.Net --version 4.0.0-preview-3.9.1.2022                
NuGet\Install-Package Notion.Net -Version 4.0.0-preview-3.9.1.2022                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Notion.Net" Version="4.0.0-preview-3.9.1.2022" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Notion.Net --version 4.0.0-preview-3.9.1.2022                
#r "nuget: Notion.Net, 4.0.0-preview-3.9.1.2022"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Notion.Net as a Cake Addin
#addin nuget:?package=Notion.Net&version=4.0.0-preview-3.9.1.2022&prerelease

// Install Notion.Net as a Cake Tool
#tool nuget:?package=Notion.Net&version=4.0.0-preview-3.9.1.2022&prerelease                

Notion SDK for .Net

A simple and easy to use client for the Notion API

Installation

.Net CLI

dotnet add package Notion.Net

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 = NotionClientFactory.Create(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();

Register using Microsoft.Extensions.DependencyInjection

Library also provides extension method to register NotionClient with Microsoft dependency injection.

services.AddNotionClient(options => {
  AuthToken = "<Token>"
});

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
  • Pages
    • Retrieve a page
    • Create a page
    • Update page
    • Retrieve page property item
  • Blocks
    • Retrieve a block
    • Update a block
    • Retrieve block children
    • Append block children
    • Delete a block
  • Comments
    • Retrieve comments
    • Create comment
  • Users
    • Retrieve a User
    • List all users
    • Retrieve your token's bot user
  • Search

Enable internal logs

The library make use of ILoggerFactory interface exposed by Microsoft.Extensions.Logging. Which allow you to have ability to enable the internal logs when developing application to get additional information.

To enable logging you need to add the below code at startup of the application.

// pass the ILoggerFactory instance
NotionClientLogging.ConfigureLogger(logger);

You can set the LogLevel in config file.

{
  "Logging": {
    "LogLevel": {
      "Notion.Client": "Trace"
    }
  }
}

You can also refer examples/list-users example.

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.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Notion.Net:

Repository Stars
vrchat-community/osc
Files and Info on using OSC to communicate with VRChat
notion-dotnet/notion-sdk-net
A Notion SDK for .Net
Version Downloads Last updated
4.2.0 51,979 9/17/2023
4.1.0 50,589 1/24/2023
4.0.0 58,029 10/4/2022
4.0.0-preview-6.9.19.2022 249 9/18/2022
4.0.0-preview-5.9.15.2022 184 9/14/2022
4.0.0-preview-4.9.11.2022 140 9/10/2022
4.0.0-preview-3.9.1.2022 99 9/1/2022
4.0.0-preview-2.8.29.2022 108 8/28/2022
4.0.0-preview-1.8.21.2022 140 8/20/2022
3.1.2 11,008 8/20/2022
3.1.0 446 8/20/2022 3.1.0 is deprecated because it has critical bugs.
3.0.0 4,555 7/17/2022
2.2.5 2,361 7/16/2022
2.2.4 579 7/3/2022
2.2.3 20,191 1/9/2022
2.2.2 601 1/1/2022
2.2.1 7,539 12/11/2021
2.2.1-preview-1.11.1.2021 256 11/1/2021
2.2.1-preview.1.10.24.2021 200 10/24/2021
2.2.0 2,395 10/7/2021
2.0.1 317 10/3/2021
2.0.0 401 10/2/2021
1.4.3 386 10/2/2021
1.4.2 436 9/28/2021
1.4.1 518 9/17/2021
1.4.0 384 9/12/2021
1.3.1 375 9/12/2021
1.2.0 438 8/18/2021
1.1.0 388 8/14/2021
1.0.4 465 8/2/2021
1.0.3 378 7/30/2021
1.0.2 410 7/17/2021
1.0.1 391 7/17/2021
1.0.0 440 7/5/2021
0.6.0-beta 213 6/22/2021
0.5.0-beta 239 6/3/2021
0.2.0-beta 250 5/23/2021
0.1.0-beta 311 5/22/2021