package notion import ( "context" "errors" "github.com/jomei/notionapi" ) var client *notionapi.Client func Init(token string) { client = notionapi.NewClient(notionapi.Token(token)) } func GetClient() *notionapi.Client { return client } func GetTableRows(tableId string, numberOfRows int, startFromId string) ([]notionapi.Block, error) { if client == nil { return nil, errors.New("notion client not initialized") } block, err := client.Block.GetChildren(context.Background(), notionapi.BlockID(tableId), ¬ionapi.Pagination{ StartCursor: notionapi.Cursor(startFromId), PageSize: numberOfRows, }) if err != nil { return nil, err } return block.Results, nil } func WriteTableRow(content []string, tableId string, after string) error { if client == nil { return errors.New("notion client not initialized") } rich := [][]notionapi.RichText{} for _, c := range content { rich = append(rich, []notionapi.RichText{ { Type: "text", Text: ¬ionapi.Text{ Content: c, }, }, }) } tableRow := notionapi.TableRowBlock{ BasicBlock: notionapi.BasicBlock{ Object: "block", Type: "table_row", }, TableRow: notionapi.TableRow{ Cells: rich, }, } _, err := client.Block.AppendChildren(context.Background(), notionapi.BlockID(tableId), ¬ionapi.AppendBlockChildrenRequest{ After: notionapi.BlockID(after), Children: []notionapi.Block{tableRow}, }) return err }