πŸ‘«
Groups
A Jira group is a convenient way to manage a collection of users. You can use groups throughout Jira to:
  • Allow application access.
  • Grant global permissions or project-specific access.
  • Receive email notifications.
  • Access issue filters and dashboards.
  • Reference workflow conditions.
  • Integrate with project roles.
This resource represents groups of users. Use it to get, create, find, and delete groups as well as add and remove users from groups.

Create Group

Creates a group
  • πŸ”’ Permissions required: Site administration
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
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 := v2.New(nil, host)
19
if err != nil {
20
return
21
}
22
​
23
atlassian.Auth.SetBasicAuth(mail, token)
24
​
25
group, response, err := atlassian.Group.Create(context.Background(), "jira-users-22")
26
if err != nil {
27
log.Fatal(err)
28
}
29
​
30
log.Println("HTTP Endpoint Used", response.Endpoint)
31
log.Println("Group created", group.Name)
32
}
33
​
Copied!

Remove group

Deletes a group
  • πŸ”’ Permissions required: Site administration
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
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 := v2.New(nil, host)
19
if err != nil {
20
return
21
}
22
​
23
atlassian.Auth.SetBasicAuth(mail, token)
24
​
25
response, err := atlassian.Group.Delete(context.Background(), "jira-users-2")
26
if err != nil {
27
log.Fatal(err)
28
return
29
}
30
​
31
log.Println("HTTP Endpoint Used", response.Endpoint)
32
}
33
​
Copied!

Bulk Groups

Returns a paginated list of groups, the method returns the following information:
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
6
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
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 := v2.New(nil, host)
20
if err != nil {
21
return
22
}
23
​
24
atlassian.Auth.SetBasicAuth(mail, token)
25
​
26
options := models.GroupBulkOptionsScheme{
27
GroupIDs: nil,
28
GroupNames: nil,
29
}
30
​
31
groups, response, err := atlassian.Group.Bulk(context.Background(), &options, 0, 50)
32
if err != nil {
33
return
34
}
35
​
36
log.Println("HTTP Endpoint Used", response.Endpoint)
37
log.Println(groups.IsLast)
38
​
39
for index, group := range groups.Values {
40
log.Printf("#%v, Group: %v", index, group.Name)
41
}
42
}
43
​
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type BulkGroupScheme struct {
2
MaxResults int `json:"maxResults,omitempty"`
3
StartAt int `json:"startAt,omitempty"`
4
Total int `json:"total,omitempty"`
5
IsLast bool `json:"isLast,omitempty"`
6
Values []struct {
7
Name string `json:"name,omitempty"`
8
GroupID string `json:"groupId,omitempty"`
9
} `json:"values,omitempty"`
10
}
Copied!

Get users from groups

Returns a paginated list of all users in a group, the method returns the following information:
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
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 := v2.New(nil, host)
19
if err != nil {
20
return
21
}
22
​
23
atlassian.Auth.SetBasicAuth(mail, token)
24
​
25
members, response, err := atlassian.Group.Members(context.Background(), "jira-users", false, 0, 100)
26
if err != nil {
27
log.Fatal(err)
28
return
29
}
30
​
31
log.Println("HTTP Endpoint Used", response.Endpoint)
32
log.Println(members.IsLast)
33
​
34
for index, member := range members.Values {
35
log.Printf("#%v - Group %v - Member Mail %v - Member AccountID %v", index, "jira-users", member.EmailAddress, member.AccountID)
36
}
37
}
38
​
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type GroupMemberPageScheme struct {
2
Self string `json:"self,omitempty"`
3
NextPage string `json:"nextPage,omitempty"`
4
MaxResults int `json:"maxResults,omitempty"`
5
StartAt int `json:"startAt,omitempty"`
6
Total int `json:"total,omitempty"`
7
IsLast bool `json:"isLast,omitempty"`
8
Values []*GroupUserDetailScheme `json:"values,omitempty"`
9
}
10
​
11
type GroupUserDetailScheme struct {
12
Self string `json:"self"`
13
Name string `json:"name"`
14
Key string `json:"key"`
15
AccountID string `json:"accountId"`
16
EmailAddress string `json:"emailAddress"`
17
DisplayName string `json:"displayName"`
18
Active bool `json:"active"`
19
TimeZone string `json:"timeZone"`
20
AccountType string `json:"accountType"`
21
}
Copied!

Add user to group

Adds a user to a group
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
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 := v2.New(nil, host)
19
if err != nil {
20
return
21
}
22
​
23
atlassian.Auth.SetBasicAuth(mail, token)
24
​
25
_, response, err := atlassian.Group.Add(context.Background(), "groupName", "accountID")
26
if err != nil {
27
return
28
}
29
​
30
log.Println("HTTP Endpoint Used", response.Endpoint)
31
}
32
​
Copied!

Remove user from group

Removes a user from a group
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
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 := v2.New(nil, host)
19
if err != nil {
20
return
21
}
22
​
23
atlassian.Auth.SetBasicAuth(mail, token)
24
​
25
response, err := atlassian.Group.Remove(context.Background(), "groupName", "accountID")
26
if err != nil {
27
return
28
}
29
​
30
log.Println("HTTP Endpoint Used", response.Endpoint)
31
}
Copied!