-
Notifications
You must be signed in to change notification settings - Fork 3
/
append-block-children-example.go
69 lines (61 loc) · 1.42 KB
/
append-block-children-example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"os"
notion "github.com/oyekanmiayo/go-notion/notion/version1"
)
func main() {
flags := flag.NewFlagSet("notion-databases-example", flag.ExitOnError)
accessToken := flags.String("access-token", "", "Notion API Key / Notion Access Token")
blockID := flags.String("block-id", "", "Page ID")
err := flags.Parse(os.Args[1:])
if err != nil {
log.Fatalf("error: %v", err)
}
client := notion.NewClient(http.DefaultClient, *accessToken)
// Append block children to a block
// Sample command: go run append-block-children-example.go --access-token=<token> --block-id=<block-id>
params := ¬ion.AppendBlockChildrenBodyParams{
Children: []notion.Block{
{
Object: "block",
Type: "heading_2",
HeadingTwo: ¬ion.HeadingTwoBlock{
Text: []notion.RichText{
{
Type: "text",
Text: ¬ion.Text{
Content: "Header Two Test",
},
},
},
},
},
{
Object: "block",
Type: "paragraph",
Paragraph: ¬ion.ParagraphBlock{
Text: []notion.RichText{
{
Type: "text",
Text: ¬ion.Text{
Content: "Paragraph Test",
},
},
},
},
},
},
}
res, _, err := client.Blocks.AppendBlockChildren(*blockID, params)
if err != nil {
fmt.Printf("Err %v\n", err)
}
jsonBody, _ := json.Marshal(res)
fmt.Println()
fmt.Println(string(jsonBody))
}