πŸ“š
Knowledgebase

Search articles

Returns articles that match the given query string across all service desks.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/sm"
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
atlassian, err := sm.New(nil, host)
19
if err != nil {
20
return
21
}
22
​
23
atlassian.Auth.SetBasicAuth(mail, token)
24
atlassian.Auth.SetUserAgent("curl/7.54.0")
25
​
26
var (
27
query = "login"
28
start = 0
29
limit = 50
30
)
31
​
32
articles, response, err := atlassian.Knowledgebase.Search(
33
context.Background(),
34
query,
35
false,
36
start, limit,
37
)
38
​
39
if err != nil {
40
if response != nil {
41
log.Println("Response HTTP Response", response.Bytes.String())
42
log.Println("HTTP Endpoint Used", response.Endpoint)
43
}
44
log.Fatal(err)
45
}
46
​
47
log.Println("Response HTTP Code", response.Code)
48
log.Println("HTTP Endpoint Used", response.Endpoint)
49
​
50
for _, article := range articles.Values {
51
log.Println(article)
52
}
53
​
54
}
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type ArticlePageScheme struct {
2
Size int `json:"size,omitempty"`
3
Start int `json:"start,omitempty"`
4
Limit int `json:"limit,omitempty"`
5
IsLastPage bool `json:"isLastPage,omitempty"`
6
Values []*ArticleScheme `json:"values,omitempty"`
7
Expands []string `json:"_expands,omitempty"`
8
Links *ArticlePageLinkScheme `json:"_links,omitempty"`
9
}
10
​
11
type ArticlePageLinkScheme struct {
12
Self string `json:"self,omitempty"`
13
Base string `json:"base,omitempty"`
14
Context string `json:"context,omitempty"`
15
Next string `json:"next,omitempty"`
16
Prev string `json:"prev,omitempty"`
17
}
18
​
19
type ArticleScheme struct {
20
Title string `json:"title,omitempty"`
21
Excerpt string `json:"excerpt,omitempty"`
22
Source *ArticleSourceScheme `json:"source,omitempty"`
23
Content *ArticleContentScheme `json:"content,omitempty"`
24
}
25
​
26
type ArticleSourceScheme struct {
27
Type string `json:"type,omitempty"`
28
}
29
​
30
type ArticleContentScheme struct {
31
IframeSrc string `json:"iframeSrc,omitempty"`
32
}
Copied!

Get articles

Returns articles that match the given query and belong to the knowledge base linked to the service desk.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/sm"
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
atlassian, err := sm.New(nil, host)
19
if err != nil {
20
return
21
}
22
​
23
atlassian.Auth.SetBasicAuth(mail, token)
24
atlassian.Auth.SetUserAgent("curl/7.54.0")
25
​
26
var (
27
serviceDeskID = 1
28
query = "login"
29
start = 0
30
limit = 50
31
)
32
​
33
articles, response, err := atlassian.Knowledgebase.Gets(
34
context.Background(),
35
serviceDeskID,
36
query,
37
false,
38
start, limit,
39
)
40
​
41
if err != nil {
42
if response != nil {
43
log.Println("Response HTTP Response", response.Bytes.String())
44
log.Println("HTTP Endpoint Used", response.Endpoint)
45
}
46
log.Fatal(err)
47
}
48
​
49
log.Println("Response HTTP Code", response.Code)
50
log.Println("HTTP Endpoint Used", response.Endpoint)
51
​
52
for _, article := range articles.Values {
53
log.Println(article)
54
}
55
​
56
}
Copied!
Export as PDF
Copy link