๐Ÿ“š
Knowledgebase

Search articles

Returns articles that match the given query string across all service desks.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/sm"
"log"
"os"
)
โ€‹
func main() {
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := sm.New(nil, host)
if err != nil {
return
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
query = "login"
start = 0
limit = 50
)
โ€‹
articles, response, err := atlassian.Knowledgebase.Search(
context.Background(),
query,
false,
start, limit,
)
โ€‹
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, article := range articles.Values {
log.Println(article)
}
โ€‹
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type ArticlePageScheme struct {
Size int `json:"size,omitempty"`
Start int `json:"start,omitempty"`
Limit int `json:"limit,omitempty"`
IsLastPage bool `json:"isLastPage,omitempty"`
Values []*ArticleScheme `json:"values,omitempty"`
Expands []string `json:"_expands,omitempty"`
Links *ArticlePageLinkScheme `json:"_links,omitempty"`
}
โ€‹
type ArticlePageLinkScheme struct {
Self string `json:"self,omitempty"`
Base string `json:"base,omitempty"`
Context string `json:"context,omitempty"`
Next string `json:"next,omitempty"`
Prev string `json:"prev,omitempty"`
}
โ€‹
type ArticleScheme struct {
Title string `json:"title,omitempty"`
Excerpt string `json:"excerpt,omitempty"`
Source *ArticleSourceScheme `json:"source,omitempty"`
Content *ArticleContentScheme `json:"content,omitempty"`
}
โ€‹
type ArticleSourceScheme struct {
Type string `json:"type,omitempty"`
}
โ€‹
type ArticleContentScheme struct {
IframeSrc string `json:"iframeSrc,omitempty"`
}

Get articles

Returns articles that match the given query and belong to the knowledge base linked to the service desk.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/sm"
"log"
"os"
)
โ€‹
func main() {
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := sm.New(nil, host)
if err != nil {
return
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
serviceDeskID = 1
query = "login"
start = 0
limit = 50
)
โ€‹
articles, response, err := atlassian.Knowledgebase.Gets(
context.Background(),
serviceDeskID,
query,
false,
start, limit,
)
โ€‹
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, article := range articles.Values {
log.Println(article)
}
โ€‹
}
Export as PDF
Copy link
On this page
Search articles
Get articles