Skip to content

Latest commit

 

History

History
371 lines (263 loc) · 8.05 KB

api-reference.md

File metadata and controls

371 lines (263 loc) · 8.05 KB

Reference

Every operation below is shown in its throwing form. On an error status it throws ApiException<TError> — the status code, headers, content type and the operation's error type, RawError (the raw body) when the spec declares none — and where an operation offers an …AsResult sibling, that sibling returns ApiResult<TResponse, TError> instead. A request that produces no usable response surfaces as SdkConnectionException or SdkTimeoutException, a body that does not match the documented response type as ResponseDeserializationException, and a credential that cannot be applied as AuthSchemeException; all of them derive from SdkException and name the failed call. See README → Error Handling.

Source: NotionApiClient

Task<PaginatedList> AppendBlockChildren(AppendBlockChildrenRequest request, RequestOptions? requestOptions = null, CancellationToken cancellationToken = default);

Description

Creates and appends new children blocks to the parent block specified by block_id. Returns the updated parent block. Blocks can be appended to pages, or to other blocks that support children. The maximum number of blocks that can be appended in a single request is 100.

Usage

try
{
    var response = await client.AppendBlockChildren(new AppendBlockChildrenRequest
    {
        BlockId = Guid.Parse("00000000-0000-0000-0000-000000000000"),
        NotionVersion = "2022-06-28",
        Body = new BlocksChildrenRequest
        {
            Children = [
                new Block
                {
                    Object = Object1.Block,
                    Id = Guid.Parse("00000000-0000-0000-0000-000000000000"),
                    Type = Type1.Paragraph,
                    CreatedTime = DateTimeOffset.Parse("2024-01-15T09:30:00Z"),
                    LastEditedTime = DateTimeOffset.Parse("2024-01-15T09:30:00Z"),
                    HasChildren = true,
                },
            ],
        },
    });
    // TODO: Handle 'response' of type PaginatedList
}
catch (ApiException<AppendBlockChildrenError> ex)
{
    if (ex.Error.TryGetError(out var error))
    {
        // TODO: Handle 'error' of type Error
    }
}

Request

AppendBlockChildrenRequest

Response

OnSuccess: PaginatedList

OnError: ApiException<AppendBlockChildrenError>

Task<Block> DeleteBlock(DeleteBlockRequest request, RequestOptions? requestOptions = null, CancellationToken cancellationToken = default);

Description

Sets a Block object, including page blocks, to archived: true using the ID specified in the path. This is equivalent to trashing the block in the Notion UI. To restore an archived block, use the update block endpoint to set archived to false.

Usage

try
{
    var response = await client.DeleteBlock(new DeleteBlockRequest
    {
        BlockId = Guid.Parse("00000000-0000-0000-0000-000000000000"),
        NotionVersion = "2022-06-28",
    });
    // TODO: Handle 'response' of type Block
}
catch (ApiException<DeleteBlockError> ex)
{
    if (ex.Error.TryGetError(out var error))
    {
        // TODO: Handle 'error' of type Error
    }
}

Request

DeleteBlockRequest

Response

OnSuccess: Block

OnError: ApiException<DeleteBlockError>

Task<Block> RetrieveBlock(RetrieveBlockRequest request, RequestOptions? requestOptions = null, CancellationToken cancellationToken = default);

Description

Retrieves a Block object using the ID specified in the path. If the block is a page, the page properties will be returned. The block's children are not included; use the retrieve block children endpoint to get them.

Usage

try
{
    var response = await client.RetrieveBlock(new RetrieveBlockRequest
    {
        BlockId = Guid.Parse("00000000-0000-0000-0000-000000000000"),
        NotionVersion = "2022-06-28",
    });
    // TODO: Handle 'response' of type Block
}
catch (ApiException<RetrieveBlockError> ex)
{
    if (ex.Error.TryGetError(out var error))
    {
        // TODO: Handle 'error' of type Error
    }
}

Request

RetrieveBlockRequest

Response

OnSuccess: Block

OnError: ApiException<RetrieveBlockError>

Task<PaginatedList> RetrieveBlockChildren(RetrieveBlockChildrenRequest request, RequestOptions? requestOptions = null, CancellationToken cancellationToken = default);

Description

Returns a paginated array of child block objects contained in the block using the ID specified. This is used to read page content by passing a page ID as the block_id. Responses include a maximum of 100 blocks per request and are returned in the order they appear in the parent block.

Usage

try
{
    var response = await client.RetrieveBlockChildren(new RetrieveBlockChildrenRequest
    {
        BlockId = Guid.Parse("00000000-0000-0000-0000-000000000000"),
        NotionVersion = "2022-06-28",
    });
    // TODO: Handle 'response' of type PaginatedList
}
catch (ApiException<RetrieveBlockChildrenError> ex)
{
    if (ex.Error.TryGetError(out var error))
    {
        // TODO: Handle 'error' of type Error
    }
}

Request

RetrieveBlockChildrenRequest

Response

OnSuccess: PaginatedList

OnError: ApiException<RetrieveBlockChildrenError>

Task<Block> UpdateBlock(UpdateBlockRequest request, RequestOptions? requestOptions = null, CancellationToken cancellationToken = default);

Description

Updates the content of a block. The fields that can be updated depend on the block type. Blocks can also be archived by setting the archived field to true.

Usage

try
{
    var response = await client.UpdateBlock(new UpdateBlockRequest
    {
        BlockId = Guid.Parse("00000000-0000-0000-0000-000000000000"),
        NotionVersion = "2022-06-28",
        Body = new BlocksRequest(),
    });
    // TODO: Handle 'response' of type Block
}
catch (ApiException<UpdateBlockError> ex)
{
    if (ex.Error.TryGetError(out var error))
    {
        // TODO: Handle 'error' of type Error
    }
}

Request

UpdateBlockRequest

Response

OnSuccess: Block

OnError: ApiException<UpdateBlockError>