The BlockService interface provides methods to interact with Notion blocks. You can use a BlockClient to implement this service for retrieving, updating, appending, or deleting blocks.
Key operations include:
Get(ctx, id): Retrieves a single block by its BlockID.GetChildren(ctx, id, pagination): Returns a paginated list of child blocks for a specific block.AppendChildren(ctx, id, request): Appends new blocks as children to a parent block. Note that blocks appended via this method cannot be moved elsewhere via the API.Update(ctx, id, request): Updates the content of an existing block. The update replaces the entire value for a given field; omitting a field leaves its current value unchanged.Delete(ctx, id): Archives a block (moves it to the Trash).
// Example usage of BlockService methods
// Assuming 'client' is an initialized *BlockClient
// 1. Get a block
block, err := client.Get(ctx, notion.BlockID("block_id"))
// 2. Append children
appendReq := ¬ion.AppendBlockChildrenRequest{
Children: notion.Blocks{
¬ion.ParagraphBlock{
BasicBlock: notion.BasicBlock{Type: notion.BlockTypeParagraph},
Paragraph: notion.Paragraph{RichText: []notion.RichText{{PlainText: "Hello World"}}},
},
},
}
client.AppendChildren(ctx, notion.BlockID("parent_id"), appendReq)
// 3. Update a block
updateReq := ¬ion.BlockUpdateRequest{
ToDo: ¬ion.ToDo{
RichText: []notion.RichText{{PlainText: "Updated Task"}},
Checked: true,
},
}
client.Update(ctx, notion.BlockID("todo_id"), updateReq)