๐Ÿ“ƒ
Content

Get content

Returns all content in a Confluence instance. By default, the following objects are expanded: space, history, version.
1
package main
2
โ€‹
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/confluence"
6
"log"
7
"os"
8
)
9
โ€‹
10
func main() {
11
โ€‹
12
var (
13
host = os.Getenv("HOST")
14
mail = os.Getenv("MAIL")
15
token = os.Getenv("TOKEN")
16
)
17
โ€‹
18
instance, err := confluence.New(nil, host)
19
if err != nil {
20
log.Fatal(err)
21
}
22
โ€‹
23
instance.Auth.SetBasicAuth(mail, token)
24
instance.Auth.SetUserAgent("curl/7.54.0")
25
โ€‹
26
โ€‹
27
var (
28
contentID = "64290828"
29
expand = []string{"any"}
30
version = 1
31
)
32
โ€‹
33
content, response, err := instance.Content.Get(context.Background(), contentID, expand, version)
34
if err != nil {
35
โ€‹
36
if response != nil {
37
log.Println(response.API)
38
}
39
โ€‹
40
log.Fatal(err)
41
}
42
โ€‹
43
log.Println("Endpoint:", response.Endpoint)
44
log.Println("Status Code:", response.Code)
45
log.Println(content)
46
}
Copied!

Create content

Creates a new piece of content or publishes an existing draft. To publish a draft, add the id and status properties to the body of the request. Set the id to the ID of the draft and set the status to 'current'. When the request is sent, a new piece of content will be created and the metadata from the draft will be transferred into it. By default, the following objects are expanded: space, history, version.
1
package main
2
โ€‹
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/confluence"
6
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
7
"log"
8
"os"
9
)
10
โ€‹
11
func main() {
12
โ€‹
13
var (
14
host = os.Getenv("HOST")
15
mail = os.Getenv("MAIL")
16
token = os.Getenv("TOKEN")
17
)
18
โ€‹
19
instance, err := confluence.New(nil, host)
20
if err != nil {
21
log.Fatal(err)
22
}
23
โ€‹
24
instance.Auth.SetBasicAuth(mail, token)
25
instance.Auth.SetUserAgent("curl/7.54.0")
26
โ€‹
27
var payload = &models.ContentScheme{
28
Type: "page", // Valid values: page, blogpost, comment
29
Title: "Confluence Page Title",
30
Space: &models.SpaceScheme{Key: "DUMMY"},
31
Body: &models.BodyScheme{
32
Storage: &models.BodyNodeScheme{
33
Value: "<p>This is <br/> a new page</p>",
34
Representation: "storage",
35
},
36
},
37
Ancestors: []*models.ContentScheme{
38
{
39
ID: "78643265",
40
},
41
},
42
}
43
โ€‹
44
newConfluence, response, err := instance.Content.Create(context.Background(), payload)
45
if err != nil {
46
โ€‹
47
if response != nil {
48
log.Fatal(response.API)
49
}
50
log.Fatal(err)
51
}
52
โ€‹
53
log.Println("Endpoint:", response.Endpoint)
54
log.Println("Status Code:", response.Code)
55
โ€‹
56
log.Println("The new content has been created")
57
log.Println(newConfluence.ID)
58
log.Println(newConfluence.Links.Self)
59
log.Println(newConfluence.Title)
60
log.Println(newConfluence.Space.Name)
61
}
Copied!

Get content by ID

Returns a single piece of content, like a page or a blog post. By default, the following objects are expanded: space, history, version.
1
package main
2
โ€‹
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/confluence"
6
"log"
7
"os"
8
)
9
โ€‹
10
func main() {
11
โ€‹
12
var (
13
host = os.Getenv("HOST")
14
mail = os.Getenv("MAIL")
15
token = os.Getenv("TOKEN")
16
)
17
โ€‹
18
instance, err := confluence.New(nil, host)
19
if err != nil {
20
log.Fatal(err)
21
}
22
โ€‹
23
instance.Auth.SetBasicAuth(mail, token)
24
instance.Auth.SetUserAgent("curl/7.54.0")
25
โ€‹
26
โ€‹
27
var (
28
contentID = "64290828"
29
expand = []string{"any"}
30
version = 1
31
)
32
โ€‹
33
content, response, err := instance.Content.Get(context.Background(), contentID, expand, version)
34
if err != nil {
35
โ€‹
36
if response != nil {
37
log.Println(response.API)
38
}
39
โ€‹
40
log.Fatal(err)
41
}
42
โ€‹
43
log.Println("Endpoint:", response.Endpoint)
44
log.Println("Status Code:", response.Code)
45
log.Println(content)
46
}
Copied!

Update content

Updates a piece of content. Use this method to update the title or body of a piece of content, change the status, change the parent page, and more.
Note, updating draft content is currently not supported.
1
package main
2
โ€‹
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/confluence"
6
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
7
"log"
8
"os"
9
)
10
โ€‹
11
func main() {
12
โ€‹
13
var (
14
host = os.Getenv("HOST")
15
mail = os.Getenv("MAIL")
16
token = os.Getenv("TOKEN")
17
)
18
โ€‹
19
instance, err := confluence.New(nil, host)
20
if err != nil {
21
log.Fatal(err)
22
}
23
โ€‹
24
instance.Auth.SetBasicAuth(mail, token)
25
instance.Auth.SetUserAgent("curl/7.54.0")
26
โ€‹
27
var payload = &models.ContentScheme{
28
Type: "page", // Valid values: page, blogpost, comment
29
Title: "Confluence Page Title - Updated",
30
Body: &models.BodyScheme{
31
Storage: &models.BodyNodeScheme{
32
Value: "<p>This is <br/> a new page - updated</p>",
33
Representation: "storage",
34
},
35
},
36
Version: &models.ContentVersionScheme{Number: 2},
37
}
38
โ€‹
39
content, response, err := instance.Content.Update(context.Background(), "64290828", payload)
40
if err != nil {
41
โ€‹
42
if response != nil {
43
log.Println(response.API)
44
}
45
โ€‹
46
log.Fatal(err)
47
}
48
โ€‹
49
log.Println("Endpoint:", response.Endpoint)
50
log.Println("Status Code:", response.Code)
51
log.Println(content)
52
}
Copied!

Delete content

Moves a piece of content to the space's trash or purges it from the trash, depending on the content's type and status:
  • If the content's type is page or blogpost and its status is current, it will be trashed.
  • If the content's type is page or blogpost and its status is trashed, the content will be purged from the trash and deleted permanently. Note, you must also set the status query parameter to trashed in your request.
  • If the content's type is comment or attachment, it will be deleted permanently without being trashed.
1
package main
2
โ€‹
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/confluence"
6
"log"
7
"os"
8
)
9
โ€‹
10
func main() {
11
โ€‹
12
var (
13
host = os.Getenv("HOST")
14
mail = os.Getenv("MAIL")
15
token = os.Getenv("TOKEN")
16
)
17
โ€‹
18
instance, err := confluence.New(nil, host)
19
if err != nil {
20
log.Fatal(err)
21
}
22
โ€‹
23
instance.Auth.SetBasicAuth(mail, token)
24
instance.Auth.SetUserAgent("curl/7.54.0")
25
โ€‹
26
var contentID = "74219528"
27
โ€‹
28
response, err := instance.Content.Delete(context.Background(), contentID, "")
29
if err != nil {
30
โ€‹
31
if response != nil {
32
log.Println(response.API)
33
log.Println(response)
34
}
35
โ€‹
36
log.Fatal(err)
37
}
38
โ€‹
39
log.Println(response)
40
โ€‹
41
}
Copied!

Get content history

Returns the most recent update for a piece of content.
1
package main
2
โ€‹
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/confluence"
6
"log"
7
"os"
8
)
9
โ€‹
10
func main() {
11
โ€‹
12
var (
13
host = os.Getenv("HOST")
14
mail = os.Getenv("MAIL")
15
token = os.Getenv("TOKEN")
16
)
17
โ€‹
18
instance, err := confluence.New(nil, host)
19
if err != nil {
20
log.Fatal(err)
21
}
22
โ€‹
23
instance.Auth.SetBasicAuth(mail, token)
24
instance.Auth.SetUserAgent("curl/7.54.0")
25
โ€‹
26
var (
27
contentID = "76513281"
28
expand = []string{"lastUpdated", "previousVersion"}
29
)
30
โ€‹
31
contentHistory, response, err := instance.Content.History(context.Background(), contentID, expand)
32
if err != nil {
33
โ€‹
34
if response != nil {
35
log.Println(response.API)
36
}
37
โ€‹
38
log.Fatal(err)
39
}
40
โ€‹
41
log.Println("Endpoint:", response.Endpoint)
42
log.Println("Status Code:", response.Code)
43
log.Println(contentHistory)
44
}
Copied!

Search Contents by CQL

Returns the list of content that matches a Confluence Query Language (CQL) query. For information on CQL, see: Advanced searching using CQL.
1
package main
2
โ€‹
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/confluence"
6
"log"
7
"net/http"
8
"os"
9
)
10
โ€‹
11
func main() {
12
โ€‹
13
var (
14
host = os.Getenv("HOST")
15
mail = os.Getenv("MAIL")
16
token = os.Getenv("TOKEN")
17
)
18
โ€‹
19
instance, err := confluence.New(nil, host)
20
if err != nil {
21
log.Fatal(err)
22
}
23
โ€‹
24
instance.Auth.SetBasicAuth(mail, token)
25
instance.Auth.SetUserAgent("curl/7.54.0")
26
โ€‹
27
var (
28
cql = "type=page"
29
cqlContext = ""
30
expand = []string{"childTypes.all", "metadata.labels"}
31
maxResults = 50
32
)
33
โ€‹
34
contentPage, response, err := instance.Content.Search(context.Background(), cql, cqlContext, expand, "", maxResults)
35
if err != nil {
36
โ€‹
37
if response.Code == http.StatusBadRequest {
38
log.Println(response.API)
39
}
40
log.Fatal(err)
41
}
42
โ€‹
43
log.Println("Endpoint:", response.Endpoint)
44
log.Println("Status Code:", response.Code)
45
log.Println(contentPage.Links.Next)
46
โ€‹
47
โ€‹
48
for _, content := range contentPage.Results {
49
log.Println(content.Title, content.ID)
50
}
51
}
52
โ€‹
Copied!

Archive Pages

Archives a list of pages. The pages to be archived are specified as a list of content IDs. This API accepts the archival request and returns a task ID.
The archival process happens asynchronously. Use the /longtask/ REST API to get the copy task status.
The Confluence Cloud REST API
Official Documentation
1
package main
2
โ€‹
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/confluence"
6
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
7
"log"
8
"os"
9
)
10
โ€‹
11
func main() {
12
โ€‹
13
var (
14
host = os.Getenv("HOST")
15
mail = os.Getenv("MAIL")
16
token = os.Getenv("TOKEN")
17
)
18
โ€‹
19
instance, err := confluence.New(nil, host)
20
if err != nil {
21
log.Fatal(err)
22
}
23
โ€‹
24
instance.Auth.SetBasicAuth(mail, token)
25
instance.Auth.SetUserAgent("curl/7.54.0")
26
โ€‹
27
payload := &models.ContentArchivePayloadScheme{
28
Pages: []*models.ContentArchiveIDPayloadScheme{
29
{
30
ID: 78675984,
31
},
32
},
33
}
34
โ€‹
35
task, response, err := instance.Content.Archive(context.Background(), payload)
36
if err != nil {
37
if response != nil {
38
log.Println("Response HTTP Response", response.Bytes.String())
39
}
40
log.Fatal(err)
41
}
42
โ€‹
43
log.Println("Endpoint:", response.Endpoint)
44
log.Println("Status Code:", response.Code)
45
log.Println(task.ID, task.Links.Status)
46
}
47
โ€‹
Copied!
Last modified 3mo ago