πŸ’Ύ
Space

Get content for space

Returns all content in a space. The returned content is grouped by type (pages then blogposts), then ordered by content ID in ascending order.
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
spaceKey = "DUMMY"
29
depth = "all"
30
expand = []string{"operations"}
31
startAt = 0
32
maxResults = 50
33
)
34
​
35
contents, response, err := instance.Space.Content(context.Background(), spaceKey, depth, expand, startAt, maxResults)
36
if err != nil {
37
​
38
if response != nil {
39
if response.Code == http.StatusBadRequest {
40
log.Println(response.API)
41
}
42
}
43
log.Println("Endpoint:", response.Endpoint)
44
log.Fatal(err)
45
}
46
​
47
log.Println("Endpoint:", response.Endpoint)
48
log.Println("Status Code:", response.Code)
49
​
50
​
51
log.Println(contents.Links)
52
log.Println(contents.Page)
53
}
Copied!

Get content by type for space

Returns all content of a given type, in a space. The returned content is ordered by content ID in ascending order.
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
spaceKey = "DUMMY"
29
contentType = "page"
30
depth = "all"
31
expand = []string{"operations"}
32
startAt = 0
33
maxResults = 50
34
)
35
​
36
contents, response, err := instance.Space.ContentByType(context.Background(), spaceKey, contentType, depth, expand, startAt, maxResults)
37
if err != nil {
38
​
39
if response != nil {
40
if response.Code == http.StatusBadRequest {
41
log.Println(response.API)
42
}
43
}
44
log.Println("Endpoint:", response.Endpoint)
45
log.Fatal(err)
46
}
47
​
48
log.Println("Endpoint:", response.Endpoint)
49
log.Println("Status Code:", response.Code)
50
​
51
​
52
for _, content := range contents.Results {
53
log.Println(content.ID, content.Title)
54
}
55
​
56
}
Copied!

Create space

Creates a new space. Note, currently you cannot set space labels when creating a space.
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
"net/http"
9
"os"
10
)
11
​
12
func main() {
13
​
14
var (
15
host = os.Getenv("HOST")
16
mail = os.Getenv("MAIL")
17
token = os.Getenv("TOKEN")
18
)
19
​
20
instance, err := confluence.New(nil, host)
21
if err != nil {
22
log.Fatal(err)
23
}
24
​
25
instance.Auth.SetBasicAuth(mail, token)
26
instance.Auth.SetUserAgent("curl/7.54.0")
27
​
28
var payload = &models.CreateSpaceScheme{
29
Key: "DUM",
30
Name: "Dum Confluence Space",
31
Description: &models.CreateSpaceDescriptionScheme{
32
Plain: &models.CreateSpaceDescriptionPlainScheme{
33
Value: "Confluence Space Description Sample",
34
Representation: "plain",
35
},
36
},
37
AnonymousAccess: true,
38
UnlicensedAccess: false,
39
}
40
​
41
space, response, err := instance.Space.Create(context.Background(), payload, false)
42
if err != nil {
43
​
44
if response != nil {
45
if response.Code == http.StatusBadRequest {
46
log.Println(response.API)
47
}
48
}
49
log.Println("Endpoint:", response.Endpoint)
50
log.Fatal(err)
51
}
52
​
53
log.Println("Endpoint:", response.Endpoint)
54
log.Println("Status Code:", response.Code)
55
log.Println(space)
56
}
Copied!

Delete space

Deletes a space. Note, the space will be deleted in a long running task. Therefore, the space may not be deleted yet when this method has returned. Clients should poll the status link that is returned in the response until the task completes.
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
task, response, err := instance.Space.Delete(context.Background(), "DS")
28
if err != nil {
29
​
30
if response != nil {
31
if response.Code == http.StatusBadRequest {
32
log.Println(response.API)
33
}
34
}
35
log.Println("Endpoint:", response.Endpoint)
36
log.Fatal(err)
37
}
38
​
39
log.Println("Endpoint:", response.Endpoint)
40
log.Println("Status Code:", response.Code)
41
​
42
log.Println(task.ID)
43
log.Println(task.Links.Status)
44
}
Copied!

Get space

Returns a space. This includes information like the name, description, and permissions, but not the content in the space.
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
space, response, err := instance.Space.Get(context.Background(), "DUMMY", []string{"operations"})
28
if err != nil {
29
​
30
if response != nil {
31
if response.Code == http.StatusBadRequest {
32
log.Println(response.API)
33
}
34
}
35
log.Println("Endpoint:", response.Endpoint)
36
log.Fatal(err)
37
}
38
​
39
log.Println("Endpoint:", response.Endpoint)
40
log.Println("Status Code:", response.Code)
41
log.Println(space)
42
}
Copied!

Get Spaces

Returns all spaces. The returned spaces are ordered alphabetically in ascending order by space key.
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
"net/http"
9
"os"
10
)
11
​
12
func main() {
13
​
14
var (
15
host = os.Getenv("HOST")
16
mail = os.Getenv("MAIL")
17
token = os.Getenv("TOKEN")
18
)
19
​
20
instance, err := confluence.New(nil, host)
21
if err != nil {
22
log.Fatal(err)
23
}
24
​
25
instance.Auth.SetBasicAuth(mail, token)
26
instance.Auth.SetUserAgent("curl/7.54.0")
27
​
28
var (
29
options = &models.GetSpacesOptionScheme{
30
SpaceKeys: nil,
31
SpaceIDs: []int{80838666, 196613},
32
SpaceType: "",
33
Status: "",
34
Labels: nil,
35
Favorite: false,
36
FavoriteUserKey: "",
37
Expand: nil,
38
}
39
startAt = 0
40
maxResults = 25
41
)
42
​
43
spaces, response, err := instance.Space.Gets(context.Background(), options, startAt, maxResults)
44
if err != nil {
45
​
46
if response != nil {
47
if response.Code == http.StatusBadRequest {
48
log.Println(response.API)
49
}
50
}
51
log.Println("Endpoint:", response.Endpoint)
52
log.Fatal(err)
53
}
54
​
55
log.Println("Endpoint:", response.Endpoint)
56
log.Println("Status Code:", response.Code)
57
​
58
for _, space := range spaces.Results {
59
log.Println(space.Name, space.Key, space.ID)
60
}
61
}
Copied!

Update space

Updates the name, description, or homepage of a space.
  • For security reasons, permissions cannot be updated via the API and must be changed via the user interface instead.
  • Currently, you cannot set space labels when updating a space.
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
"net/http"
9
"os"
10
)
11
​
12
func main() {
13
​
14
var (
15
host = os.Getenv("HOST")
16
mail = os.Getenv("MAIL")
17
token = os.Getenv("TOKEN")
18
)
19
​
20
instance, err := confluence.New(nil, host)
21
if err != nil {
22
log.Fatal(err)
23
}
24
​
25
instance.Auth.SetBasicAuth(mail, token)
26
instance.Auth.SetUserAgent("curl/7.54.0")
27
​
28
var (
29
spaceKey = "DUMMY"
30
payload = &models.UpdateSpaceScheme{
31
Name: "DUMMY Space - Updated",
32
Description: &models.CreateSpaceDescriptionScheme{
33
Plain: &models.CreateSpaceDescriptionPlainScheme{
34
Value: "Dummy Space - Description - Updated",
35
Representation: "plain",
36
},
37
},
38
Homepage: &models.UpdateSpaceHomepageScheme{ID: "65798145"},
39
}
40
)
41
​
42
spaceUpdated, response, err := instance.Space.Update(context.Background(), spaceKey, payload)
43
if err != nil {
44
​
45
if response != nil {
46
if response.Code == http.StatusBadRequest {
47
log.Println(response.API)
48
}
49
}
50
log.Println("Endpoint:", response.Endpoint)
51
log.Fatal(err)
52
}
53
​
54
log.Println("Endpoint:", response.Endpoint)
55
log.Println("Status Code:", response.Code)
56
log.Println(spaceUpdated)
57
}
58
​
Copied!
Last modified 7mo ago