πŸͺœ
Organization

Get organizations

This method returns a list of organizations in the Jira Service Management instance. Use this method when you want to present a list of organizations or want to locate an organization by name.
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
accountID = ""
28
start = 0
29
limit = 50
30
)
31
​
32
organizations, response, err := atlassian.Organization.Gets(context.Background(), accountID, 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 _, organization := range organizations.Values {
45
log.Println(organization)
46
}
47
​
48
}
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type OrganizationPageScheme 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 []*OrganizationScheme `json:"values,omitempty"`
7
Expands []string `json:"_expands,omitempty"`
8
Links *OrganizationPageLinkScheme `json:"_links,omitempty"`
9
}
10
​
11
type OrganizationPageLinkScheme 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 OrganizationScheme struct {
20
ID string `json:"id,omitempty"`
21
Name string `json:"name,omitempty"`
22
Links struct {
23
Self string `json:"self,omitempty"`
24
} `json:"_links,omitempty"`
25
}
Copied!

Create organization

This method creates an organization by passing the name of the organization.
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 organizationName = "Organization Name"
27
​
28
newOrganization, response, err := atlassian.Organization.Create(context.Background(), organizationName)
29
if err != nil {
30
if response != nil {
31
log.Println("Response HTTP Response", response.Bytes.String())
32
log.Println("HTTP Endpoint Used", response.Endpoint)
33
}
34
log.Fatal(err)
35
}
36
​
37
log.Println("Response HTTP Code", response.Code)
38
log.Println("HTTP Endpoint Used", response.Endpoint)
39
log.Printf("The organization has been created: %v", newOrganization.ID)
40
}
Copied!

Get organization

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
organization, response, err := atlassian.Organization.Get(context.Background(), 2)
27
if err != nil {
28
if response != nil {
29
log.Println("Response HTTP Response", response.Bytes.String())
30
log.Println("HTTP Endpoint Used", response.Endpoint)
31
}
32
log.Fatal(err)
33
}
34
​
35
log.Println("Response HTTP Code", response.Code)
36
log.Println("HTTP Endpoint Used", response.Endpoint)
37
log.Println(organization.ID, organization.Name, organization.Links.Self)
38
}
Copied!

Get organizations

This method returns a list of all organizations associated with a 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
accountID = ""
28
projectID = 1
29
start = 0
30
limit = 50
31
)
32
​
33
organizations, response, err := atlassian.Organization.Project(
34
context.Background(),
35
accountID,
36
projectID,
37
start,
38
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 _, organization := range organizations.Values {
53
log.Printf(organization.ID)
54
}
55
​
56
}
Copied!

Associate organization

This method adds an organization to a service desk. If the organization ID is already associated with the service desk, no change is made and the resource returns a 204 success code.
1
package main
2
import (
3
"context"
4
"github.com/ctreminiom/go-atlassian/jira/sm"
5
"log"
6
"os"
7
)
8
func main() {
9
var (
10
host = os.Getenv("HOST")
11
mail = os.Getenv("MAIL")
12
token = os.Getenv("TOKEN")
13
)
14
atlassian, err := sm.New(nil, host)
15
if err != nil {
16
return
17
}
18
atlassian.Auth.SetBasicAuth(mail, token)
19
atlassian.Auth.SetUserAgent("curl/7.54.0")
20
var (
21
projectID = 1
22
organizationID = 2
23
)
24
response, err := atlassian.Organization.Associate(context.Background(), projectID, organizationID)
25
if err != nil {
26
if response != nil {
27
log.Println("Response HTTP Response", response.Bytes.String())
28
log.Println("HTTP Endpoint Used", response.Endpoint)
29
}
30
log.Fatal(err)
31
}
32
log.Println("Response HTTP Code", response.Code)
33
log.Println("HTTP Endpoint Used", response.Endpoint)
34
}
Copied!

Detach organization

This method removes an organization from a service desk. If the organization ID does not match an organization associated with the service desk, no change is made and the resource returns a 204 success code.
1
package main
2
import (
3
"context"
4
"github.com/ctreminiom/go-atlassian/jira/sm"
5
"log"
6
"os"
7
)
8
func main() {
9
var (
10
host = os.Getenv("HOST")
11
mail = os.Getenv("MAIL")
12
token = os.Getenv("TOKEN")
13
)
14
atlassian, err := sm.New(nil, host)
15
if err != nil {
16
return
17
}
18
atlassian.Auth.SetBasicAuth(mail, token)
19
atlassian.Auth.SetUserAgent("curl/7.54.0")
20
var (
21
projectID = 1
22
organizationID = 2
23
)
24
response, err := atlassian.Organization.Detach(context.Background(), projectID, organizationID)
25
if err != nil {
26
if response != nil {
27
log.Println("Response HTTP Response", response.Bytes.String())
28
log.Println("HTTP Endpoint Used", response.Endpoint)
29
}
30
log.Fatal(err)
31
}
32
log.Println("Response HTTP Code", response.Code)
33
log.Println("HTTP Endpoint Used", response.Endpoint)
34
}
Copied!

Get users in organization

This method returns all the users associated with an organization. Use this method where you want to provide a list of users for an organization or determine if a user is associated with an organization.w
1
package main
2
package main
3
​
4
import (
5
"context"
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
organizationID = 2
29
start = 0
30
limit = 50
31
)
32
​
33
users, response, err := atlassian.Organization.Users(context.Background(), organizationID, start, limit)
34
if err != nil {
35
if response != nil {
36
log.Println("Response HTTP Response", response.Bytes.String())
37
log.Println("HTTP Endpoint Used", response.Endpoint)
38
}
39
log.Fatal(err)
40
}
41
​
42
log.Println("Response HTTP Code", response.Code)
43
log.Println("HTTP Endpoint Used", response.Endpoint)
44
​
45
for _, user := range users.Values {
46
log.Printf(user.DisplayName, user.EmailAddress)
47
}
48
​
49
}
Copied!

Add users to organization

This method adds users to an organization.
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
accountIDs = []string{"5b86be50b8e3cb5895860d6d"}
28
organizationID = 2
29
)
30
​
31
response, err := atlassian.Organization.Add(context.Background(), organizationID, accountIDs)
32
if err != nil {
33
if response != nil {
34
log.Println("Response HTTP Response", response.Bytes.String())
35
log.Println("HTTP Endpoint Used", response.Endpoint)
36
}
37
log.Fatal(err)
38
}
39
​
40
log.Println("Response HTTP Code", response.Code)
41
log.Println("HTTP Endpoint Used", response.Endpoint)
42
}
Copied!

Remove users from organization

This method removes users from an organization.
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
accountIDs = []string{"5b86be50b8e3cb5895860d6d"}
28
organizationID = 2
29
)
30
​
31
response, err := atlassian.Organization.Remove(context.Background(), organizationID, accountIDs)
32
if err != nil {
33
if response != nil {
34
log.Println("Response HTTP Response", response.Bytes.String())
35
log.Println("HTTP Endpoint Used", response.Endpoint)
36
}
37
log.Fatal(err)
38
}
39
​
40
log.Println("Response HTTP Code", response.Code)
41
log.Println("HTTP Endpoint Used", response.Endpoint)
42
​
43
}
Copied!