๐Ÿ“™
Request

Get customer requests

This method returns all customer requests for the user executing the query.
1
package main
2
โ€‹
3
import (
4
"context"
5
"encoding/json"
6
"github.com/ctreminiom/go-atlassian/jira/sm"
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
atlassian, err := sm.New(nil, host)
20
if err != nil {
21
return
22
}
23
โ€‹
24
atlassian.Auth.SetBasicAuth(mail, token)
25
atlassian.Auth.SetUserAgent("curl/7.54.0")
26
โ€‹
27
options := &sm.RequestGetOptionsScheme{
28
SearchTerm: "",
29
RequestOwnerships: []string{"OWNED_REQUESTS"},
30
RequestStatus: "ALL_REQUESTS",
31
ApprovalStatus: "",
32
OrganizationId: 0,
33
ServiceDeskID: 0,
34
RequestTypeID: 0,
35
Expand: []string{"serviceDesk", "requestType", "status", "action"},
36
}
37
โ€‹
38
customerRequests, response, err := atlassian.Request.Gets(context.Background(), options, 0, 50)
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 _, customRequest := range customerRequests.Values {
51
โ€‹
52
dataAsJson, err := json.MarshalIndent(customRequest, "", "\t")
53
if err != nil {
54
log.Fatal(err)
55
}
56
โ€‹
57
log.Println(string(dataAsJson))
58
}
59
โ€‹
60
}
Copied!

Get customer request by id or key

This method returns a customer request.
1
package main
2
โ€‹
3
import (
4
"context"
5
"encoding/json"
6
"github.com/ctreminiom/go-atlassian/jira/sm"
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
atlassian, err := sm.New(nil, host)
20
if err != nil {
21
return
22
}
23
โ€‹
24
atlassian.Auth.SetBasicAuth(mail, token)
25
atlassian.Auth.SetUserAgent("curl/7.54.0")
26
โ€‹
27
var (
28
issueKey = "DESK-11"
29
expand = []string{"serviceDesk", "requestType"}
30
)
31
โ€‹
32
request, response, err := atlassian.Request.Get(context.Background(), issueKey, expand)
33
if err != nil {
34
if response != nil {
35
log.Println("Response HTTP Response", response.Bytes.String())
36
log.Println("HTTP Endpoint Used", response.Endpoint)
37
}
38
log.Fatal(err)
39
}
40
โ€‹
41
log.Println("Response HTTP Code", response.Code)
42
log.Println("HTTP Endpoint Used", response.Endpoint)
43
โ€‹
44
dataAsJson, err := json.MarshalIndent(request, "", "\t")
45
if err != nil {
46
log.Fatal(err)
47
}
48
โ€‹
49
log.Println(string(dataAsJson))
50
โ€‹
51
}
Copied!

Subscribe

This method subscribes the user to receiving notifications from a customer request.
1
package main
2
โ€‹
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/sm"
6
"log"
7
"os"
8
)
9
func main() {
10
var (
11
host = os.Getenv("HOST")
12
mail = os.Getenv("MAIL")
13
token = os.Getenv("TOKEN")
14
)
15
atlassian, err := sm.New(nil, host)
16
if err != nil {
17
return
18
}
19
atlassian.Auth.SetBasicAuth(mail, token)
20
atlassian.Auth.SetUserAgent("curl/7.54.0")
21
22
response, err := atlassian.Request.Subscribe(context.Background(), "DUMMY-4")
23
if err != nil {
24
if response != nil {
25
log.Println("Response HTTP Response", response.Bytes.String())
26
log.Println("HTTP Endpoint Used", response.Endpoint)
27
}
28
log.Fatal(err)
29
}
30
log.Println("Response HTTP Code", response.Code)
31
log.Println("HTTP Endpoint Used", response.Endpoint)
32
}
Copied!

Unsubscribe

This method unsubscribes the user from notifications from a customer request.
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
var (
12
host = os.Getenv("HOST")
13
mail = os.Getenv("MAIL")
14
token = os.Getenv("TOKEN")
15
)
16
atlassian, err := sm.New(nil, host)
17
if err != nil {
18
return
19
}
20
atlassian.Auth.SetBasicAuth(mail, token)
21
atlassian.Auth.SetUserAgent("curl/7.54.0")
22
response, err := atlassian.Request.Unsubscribe(context.Background(), "DUMMY-4")
23
if err != nil {
24
if response != nil {
25
log.Println("Response HTTP Response", string(response.Bytes.String()))
26
log.Println("HTTP Endpoint Used", response.Endpoint)
27
}
28
log.Fatal(err)
29
}
30
log.Println("Response HTTP Code", response.Code)
31
log.Println("HTTP Endpoint Used", response.Endpoint)
32
}
33
โ€‹
Copied!

Get customer transitions

This method returns a list of transitions, the workflow processes that moves a customer request from one status to another, that the user can perform on a request. Use this method to provide a user with a list if the actions they can take on a customer request.
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
issueKeyOrID = "DESK-3"
28
start = 0
29
limit = 50
30
)
31
โ€‹
32
transitions, response, err := atlassian.Request.Transitions(context.Background(), issueKeyOrID, start, limit)
33
if err != nil {
34
if response != nil {
35
log.Println("Response HTTP Response", response.Bytes.String())
36
log.Println("HTTP Endpoint Used", response.Endpoint)
37
}
38
log.Fatal(err)
39
}
40
โ€‹
41
log.Println("Response HTTP Code", response.Code)
42
log.Println("HTTP Endpoint Used", response.Endpoint)
43
โ€‹
44
for _, transition := range transitions.Values {
45
log.Println(transition.ID, transition.Name)
46
}
47
}
48
โ€‹
Copied!

Perform customer transition

This method performs a customer transition for a given request and transition. An optional comment can be included to provide a reason for the transition.
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
issueKeyOrID = "DESK-3"
28
transitionID = "921"
29
comment = "lorem"
30
)
31
โ€‹
32
response, err := atlassian.Request.Transition(context.Background(), issueKeyOrID, transitionID, comment)
33
if err != nil {
34
if response != nil {
35
log.Println("Response HTTP Response", response.Bytes.String())
36
log.Println("HTTP Endpoint Used", response.Endpoint)
37
}
38
log.Fatal(err)
39
}
40
โ€‹
41
log.Println("Response HTTP Code", response.Code)
42
log.Println("HTTP Endpoint Used", response.Endpoint)
43
}
44
โ€‹
Copied!

Create Customer Request

This method creates a customer request at a service desk. The payload must include the service desk and customer request type, as well as any fields that are required for the request type. A list of the fields required by a customer request type can be obtained using the sm.RequestType.Fields method.
The Jira Service Management Cloud REST API
1
package main
2
โ€‹
3
import (
4
"context"
5
"fmt"
6
"github.com/ctreminiom/go-atlassian/jira/sm"
7
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
8
"log"
9
"os"
10
"time"
11
)
12
โ€‹
13
func main() {
14
โ€‹
15
var (
16
host = os.Getenv("HOST")
17
mail = os.Getenv("MAIL")
18
token = os.Getenv("TOKEN")
19
)
20
โ€‹
21
atlassian, err := sm.New(nil, host)
22
if err != nil {
23
return
24
}
25
โ€‹
26
atlassian.Auth.SetBasicAuth(mail, token)
27
atlassian.Auth.SetUserAgent("curl/7.54.0")
28
โ€‹
29
form := &models.CustomerRequestFields{}
30
โ€‹
31
if err := form.Text("summary", "Summary Sample"); err != nil {
32
log.Fatal(err)
33
}
34
โ€‹
35
if err := form.Date("duedate", time.Now()); err != nil {
36
log.Fatal(err)
37
}
38
โ€‹
39
if err := form.Components([]string{"Intranet"}); err != nil {
40
log.Fatal(err)
41
}
42
โ€‹
43
if err := form.Labels([]string{"label-00", "label-01"}); err != nil {
44
log.Fatal(err)
45
}
46
โ€‹
47
payload := &models.CreateCustomerRequestPayloadScheme{
48
RequestParticipants: nil,
49
ServiceDeskID: "1",
50
RequestTypeID: "10",
51
}
52
โ€‹
53
ticket, response, err := atlassian.Request.Create(context.Background(), payload, form)
54
if err != nil {
55
log.Fatal(err)
56
}
57
โ€‹
58
log.Println("Response HTTP Code", response.Code)
59
log.Println("HTTP Endpoint Used", response.Endpoint)
60
โ€‹
61
fmt.Println("IssueID", ticket.IssueID)
62
fmt.Println("IssueKey", ticket.IssueKey)
63
fmt.Println("Reporter.EmailAddress", ticket.Reporter.EmailAddress)
64
fmt.Println("CreatedDate.Friendly", ticket.CreatedDate.Friendly)
65
โ€‹
66
for _, field := range ticket.RequestFieldValues {
67
fmt.Println(field)
68
}
69
}
Copied!