forked from Virtomize/confluence-go-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.go
99 lines (86 loc) · 1.9 KB
/
content.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
"log"
goconfluence "github.com/coggsflod/confluence-go-api"
)
func main() {
api, err := goconfluence.NewAPI("https://<your-domain>.atlassian.net/wiki/rest/api", "<username>", "<api-token>")
if err != nil {
log.Fatal(err)
}
// get content by content id
c, err := api.GetContentByID("12345678", goconfluence.ContentQuery{
SpaceKey: "IM",
Expand: []string{"body.storage", "version"},
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", c)
//get content by query
res, err := api.GetContent(goconfluence.ContentQuery{
SpaceKey: "IM",
})
if err != nil {
log.Fatal(err)
}
for _, v := range res.Results {
fmt.Printf("%+v\n", v)
}
// create content
data := &goconfluence.Content{
Type: "page", // can also be blogpost
Title: "Some-Test-Page", // page title (mandatory)
Ancestors: []goconfluence.Ancestor{
{
ID: "123456", // ancestor-id optional if you want to create sub-pages
},
},
Body: goconfluence.Body{
Storage: goconfluence.Storage{
Value: "#api-test\nnew sub\npage", // your page content here
Representation: "storage",
},
},
Version: &goconfluence.Version{ // mandatory
Number: 1,
},
Space: &goconfluence.Space{
Key: "SomeSpaceKey", // Space
},
}
c, err = api.CreateContent(data)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", c)
// update content
data = &goconfluence.Content{
ID: "1234567",
Type: "page",
Title: "updated-title",
Ancestors: []goconfluence.Ancestor{
{
ID: "2345678",
},
},
Body: goconfluence.Body{
Storage: goconfluence.Storage{
Value: "#api-page\nnew\ncontent",
Representation: "storage",
},
},
Version: &goconfluence.Version{
Number: 2,
},
Space: &goconfluence.Space{
Key: "SomeSpaceKey",
},
}
c, err = api.UpdateContent(data)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", c)
}