πŸ”Ž
Search

Search Content

Searches for content using the Confluence Query Language (CQL)​
The Confluence Cloud REST API
Official Documentation
1
package main
2
​
3
import (
4
"context"
5
"fmt"
6
"github.com/ctreminiom/go-atlassian/confluence"
7
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
8
"log"
9
"net/url"
10
"os"
11
"strconv"
12
)
13
​
14
func main() {
15
​
16
var (
17
host = os.Getenv("HOST")
18
mail = os.Getenv("MAIL")
19
token = os.Getenv("TOKEN")
20
)
21
​
22
instance, err := confluence.New(nil, host)
23
if err != nil {
24
log.Fatal(err)
25
}
26
​
27
instance.Auth.SetBasicAuth(mail, token)
28
instance.Auth.SetUserAgent("curl/7.54.0")
29
​
30
ctx := context.Background()
31
cql := "type = page"
32
​
33
options := &models.SearchContentOptions{Limit: 2}
34
​
35
for {
36
​
37
fmt.Println("cursor ==>", options.Cursor)
38
fmt.Println("startAt ==>", options.Start)
39
​
40
contents, response, err := instance.Search.Content(ctx, cql, options)
41
if err != nil {
42
if response != nil {
43
log.Println(response.Bytes.String())
44
log.Println("Endpoint:", response.Endpoint)
45
}
46
log.Fatal(err)
47
}
48
​
49
for _, content := range contents.Results {
50
​
51
fmt.Println(content.Content.ID, content.Content.Title)
52
/*
53
fmt.Println(content.Content.ID)
54
fmt.Println(content.Content.Title)
55
fmt.Println(content.Content.Type)
56
fmt.Println(content.LastModified)
57
fmt.Println(content.FriendlyLastModified)
58
*/
59
}
60
​
61
if contents.Links.Next == "" {
62
break
63
}
64
​
65
values, err := url.ParseQuery(contents.Links.Next)
66
if err != nil {
67
log.Fatal(err)
68
}
69
​
70
start, err := strconv.Atoi(values["start"][0])
71
if err != nil {
72
log.Fatal(err)
73
}
74
​
75
options.Cursor = values["cursor"][0]
76
options.Start = start
77
}
78
​
79
}
Copied!

Search Users

Searches for users using user-specific queries from the Confluence Query Language (CQL).
Note that some user fields may be set to null depending on the user's privacy settings. These are: email, profilePicture, displayName, and timeZone.
The Confluence Cloud REST API
Official Documentation
1
package main
2
​
3
import (
4
"context"
5
"fmt"
6
"github.com/ctreminiom/go-atlassian/confluence"
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
ctx := context.Background()
28
cql := "type = user"
29
​
30
​
31
users, response, err := instance.Search.Users(ctx, cql, 0, 50, nil)
32
if err != nil {
33
if response != nil {
34
log.Println(response.Bytes.String())
35
log.Println("Endpoint:", response.Endpoint)
36
}
37
log.Fatal(err)
38
}
39
​
40
for _, user := range users.Results {
41
fmt.Println(user.User)
42
}
43
}
Copied!
Export as PDF
Copy link