๐Ÿ”Ž
Search

Search Content

Searches for content using the Confluence Query Language (CQL)โ€‹
The Confluence Cloud REST API
Official Documentation
package main
โ€‹
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/confluence"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"net/url"
"os"
"strconv"
)
โ€‹
func main() {
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
instance, err := confluence.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
โ€‹
ctx := context.Background()
cql := "type = page"
โ€‹
options := &models.SearchContentOptions{Limit: 2}
โ€‹
for {
โ€‹
fmt.Println("cursor ==>", options.Cursor)
fmt.Println("startAt ==>", options.Start)
โ€‹
contents, response, err := instance.Search.Content(ctx, cql, options)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println("Endpoint:", response.Endpoint)
}
log.Fatal(err)
}
โ€‹
for _, content := range contents.Results {
โ€‹
fmt.Println(content.Content.ID, content.Content.Title)
/*
fmt.Println(content.Content.ID)
fmt.Println(content.Content.Title)
fmt.Println(content.Content.Type)
fmt.Println(content.LastModified)
fmt.Println(content.FriendlyLastModified)
*/
}
โ€‹
if contents.Links.Next == "" {
break
}
โ€‹
values, err := url.ParseQuery(contents.Links.Next)
if err != nil {
log.Fatal(err)
}
โ€‹
start, err := strconv.Atoi(values["start"][0])
if err != nil {
log.Fatal(err)
}
โ€‹
options.Cursor = values["cursor"][0]
options.Start = start
}
โ€‹
}

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
package main
โ€‹
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/confluence"
"log"
"os"
)
โ€‹
func main() {
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
instance, err := confluence.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
โ€‹
ctx := context.Background()
cql := "type = user"
โ€‹
โ€‹
users, response, err := instance.Search.Users(ctx, cql, 0, 50, nil)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println("Endpoint:", response.Endpoint)
}
log.Fatal(err)
}
โ€‹
for _, user := range users.Results {
fmt.Println(user.User)
}
}
Export as PDF
Copy link
On this page
Search Content
Search Users