Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 755d02a

Browse files
Merge pull request #495 from notion-dotnet/release/4.4.0
Release 4.4.0
2 parents 37bdcdc + 921e7c6 commit 755d02a

File tree

2 files changed

+145
-17
lines changed

2 files changed

+145
-17
lines changed

‎README.md‎

Lines changed: 144 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ Provides the following packages:
3838
dotnet add package Notion.Net
3939
```
4040

41-
**Note:** default Notion-Version used by NuGet package versions
41+
**Note:** Default Notion-Version used by NuGet package versions
4242
| Package version | Notion-Version |
4343
| --- | --- |
44-
| 4.0.0-preview-1.8.21.2022 | 2022年06月28日 |
44+
| 4.4.0+ | 2022年06月28日 |
45+
| 4.3.0+ | 2022年06月28日 |
46+
| 4.0.0+ | 2022年06月28日 |
4547
| 3.0.0+ | 2022年02月22日 |
4648
| 2.0.0+ | 2021年08月16日 |
4749
| 1.0.0+ | 2021年05月13日 |
@@ -67,14 +69,33 @@ var usersList = await client.Users.ListAsync();
6769

6870
## Dependency Injection
6971

70-
Library also provides extension method to register NotionClient with Microsoft dependency injection.
72+
The library provides an extension method to register NotionClient with Microsoft dependency injection.
7173

72-
```
74+
```csharp
7375
services.AddNotionClient(options => {
7476
options.AuthToken = "<Token>";
7577
});
7678
```
7779

80+
Then inject `INotionClient` into your services:
81+
82+
```csharp
83+
public class MyService
84+
{
85+
private readonly INotionClient _notionClient;
86+
87+
public MyService(INotionClient notionClient)
88+
{
89+
_notionClient = notionClient;
90+
}
91+
92+
public async Task<Database> GetDatabaseAsync(string databaseId)
93+
{
94+
return await _notionClient.Databases.RetrieveAsync(databaseId);
95+
}
96+
}
97+
```
98+
7899
### Querying a database
79100

80101
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:
@@ -109,30 +130,42 @@ var complexFiler = new CompoundFilter(
109130

110131
## Supported Endpoints
111132

112-
- [x] Databases
133+
- [x] **Authentication**
134+
- [x] Create access token
135+
- [x] Revoke access token
136+
- [x] Introspect token (get token status and details)
137+
- [x] Refresh access token
138+
- [x] **Databases**
139+
- [x] Retrieve a database
113140
- [x] Query a database
114141
- [x] Create a database
115-
- [x] Update database
116-
- [x] Retrieve a database
117-
- [x] Pages
142+
- [x] Update a database
143+
- [x] **Pages**
118144
- [x] Retrieve a page
119145
- [x] Create a page
120-
- [x] Update page
146+
- [x] Update page properties
121147
- [x] Retrieve page property item
122-
- [x] Blocks
148+
- [x] **Blocks**
123149
- [x] Retrieve a block
124150
- [x] Update a block
125151
- [x] Retrieve block children
126152
- [x] Append block children
127153
- [x] Delete a block
128-
- [x] Comments
154+
- [x] **Comments**
129155
- [x] Retrieve comments
130156
- [x] Create comment
131-
- [x] Users
132-
- [x] Retrieve a User
157+
- [x] **Users**
158+
- [x] Retrieve a user
133159
- [x] List all users
134-
- [x] Retrieve your token's bot user
135-
- [x] Search
160+
- [x] Retrieve your token's bot user (me)
161+
- [x] **Search**
162+
- [x] Search across pages and databases
163+
- [x] **File Uploads**
164+
- [x] Create file upload
165+
- [x] Send file upload
166+
- [x] Complete file upload (for multi-part uploads)
167+
- [x] List file uploads
168+
- [x] Retrieve file upload
136169

137170
## Enable internal logs
138171
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.
@@ -156,7 +189,102 @@ You can set the LogLevel in config file.
156189
}
157190
```
158191

159-
You can also refer `examples/list-users` example.
192+
You can also refer to the `examples/list-users` example.
193+
194+
## Error Handling
195+
196+
The SDK provides specific exception types for common API errors:
197+
198+
```csharp
199+
try
200+
{
201+
var page = await client.Pages.RetrieveAsync(pageId);
202+
}
203+
catch (NotionApiRateLimitException rateLimitEx)
204+
{
205+
// Handle rate limit - check rateLimitEx.RetryAfter for when to retry
206+
Console.WriteLine($"Rate limited. Retry after: {rateLimitEx.RetryAfter}");
207+
}
208+
catch (NotionApiException apiEx)
209+
{
210+
// Handle other API errors
211+
Console.WriteLine($"API Error: {apiEx.NotionAPIErrorCode} - {apiEx.Message}");
212+
}
213+
```
214+
215+
## Examples
216+
217+
The repository includes several example projects to help you get started:
218+
219+
- **[`examples/list-users`](examples/list-users/)** - Basic example showing how to list users and configure logging
220+
- **[`examples/aspnet-core-app`](examples/aspnet-core-app/)** - ASP.NET Core integration example with dependency injection
221+
- **[`examples/print-database-property-name-and-values`](examples/print-database-property-name-and-values/)** - Working with database properties
222+
223+
## More Code Examples
224+
225+
### Creating a Page
226+
```csharp
227+
var newPage = await client.Pages.CreateAsync(new PagesCreateParameters
228+
{
229+
Parent = new DatabaseParentInput { DatabaseId = databaseId },
230+
Properties = new Dictionary<string, PropertyValue>
231+
{
232+
{
233+
"Title", new TitlePropertyValue
234+
{
235+
Title = new List<RichTextBase>
236+
{
237+
new RichTextText { Text = new Text { Content = "My New Page" } }
238+
}
239+
}
240+
}
241+
}
242+
});
243+
```
244+
245+
### Working with Blocks
246+
```csharp
247+
// Append a paragraph block to a page
248+
var appendResponse = await client.Blocks.AppendChildrenAsync(new BlockAppendChildrenRequest
249+
{
250+
BlockId = pageId,
251+
Children = new List<ICreateBlock>
252+
{
253+
new ParagraphBlock
254+
{
255+
Paragraph = new ParagraphBlock.ParagraphData
256+
{
257+
RichText = new List<RichTextBase>
258+
{
259+
new RichTextText
260+
{
261+
Text = new Text { Content = "This is a new paragraph!" }
262+
}
263+
}
264+
}
265+
}
266+
}
267+
});
268+
```
269+
270+
### File Upload
271+
```csharp
272+
// Create file upload
273+
var fileUpload = await client.FileUploads.CreateAsync(new CreateFileUploadRequest
274+
{
275+
Name = "example.pdf",
276+
FileType = FileType.Pdf,
277+
FileSize = fileSize,
278+
ExpiresTime = DateTime.UtcNow.AddHours(1)
279+
});
280+
281+
// Send the file
282+
var sendResponse = await client.FileUploads.SendAsync(new SendFileUploadRequest
283+
{
284+
FileUploadId = fileUpload.Id,
285+
FileContent = fileBytes
286+
});
287+
```
160288

161289
## Contributors
162290
This project exists thanks to all the people who contribute.

‎Src/Notion.Client/Notion.Client.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>4.3.0-preview</VersionPrefix>
4+
<VersionPrefix>4.4.0-preview</VersionPrefix>
55
<TargetFramework>netstandard2.0</TargetFramework>
66
<LangVersion>9.0</LangVersion>
77

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /