β›Ήβ™‚
Groups

Get a group by ID

Get a group from a directory by group ID.
1
package main
2
​
3
import (
4
"context"
5
"fmt"
6
"github.com/ctreminiom/go-atlassian/admin"
7
"log"
8
"os"
9
)
10
​
11
func main() {
12
​
13
//ATLASSIAN_ADMIN_TOKEN
14
var scimApiKey = os.Getenv("ATLASSIAN_SCIM_API_KEY")
15
​
16
cloudAdmin, err := admin.New(nil)
17
if err != nil {
18
log.Fatal(err)
19
}
20
​
21
cloudAdmin.Auth.SetBearerToken(scimApiKey)
22
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
23
​
24
var (
25
directoryID = "bcdde508-ee40-4df2-89cc-d3f6292c5971"
26
groupID = "e18da5e4-ba2e-4039-9046-30000af6c0b7"
27
)
28
​
29
group, response, err := cloudAdmin.SCIM.Group.Get(context.Background(), directoryID, groupID)
30
if err != nil {
31
if response != nil {
32
log.Println("Response HTTP Response", string(response.BodyAsBytes))
33
}
34
log.Fatal(err)
35
}
36
​
37
log.Println("Response HTTP Code", response.StatusCode)
38
log.Println("HTTP Endpoint Used", response.Endpoint)
39
log.Println(group)
40
​
41
fmt.Println(string(response.BodyAsBytes))
42
​
43
}
44
​
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type ScimGroupScheme struct {
2
Schemas []string `json:"schemas,omitempty"`
3
ID string `json:"id,omitempty"`
4
ExternalID string `json:"externalId,omitempty"`
5
DisplayName string `json:"displayName,omitempty"`
6
Members []*ScimGroupMemberScheme `json:"members,omitempty"`
7
Meta *ScimMetadata `json:"meta,omitempty"`
8
}
9
​
10
type ScimGroupMemberScheme struct {
11
Type string `json:"type,omitempty"`
12
Value string `json:"value,omitempty"`
13
Display string `json:"display,omitempty"`
14
Ref string `json:"$ref,omitempty"`
15
}
16
​
17
type ScimMetadata struct {
18
ResourceType string `json:"resourceType,omitempty"`
19
Location string `json:"location,omitempty"`
20
LastModified string `json:"lastModified,omitempty"`
21
Created string `json:"created,omitempty"`
22
}
Copied!

Update a group by ID

Update a group in a directory by group ID.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
//ATLASSIAN_ADMIN_TOKEN
13
var scimApiKey = os.Getenv("ATLASSIAN_SCIM_API_KEY")
14
​
15
cloudAdmin, err := admin.New(nil)
16
if err != nil {
17
log.Fatal(err)
18
}
19
​
20
cloudAdmin.Auth.SetBearerToken(scimApiKey)
21
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
22
​
23
var (
24
directoryID = "bcdde508-ee40-4df2-89cc-d3f6292c5971"
25
groupID = "e18da5e4-ba2e-4039-9046-30000af6c0b7"
26
newGroupName = "scim-jira-users-updated"
27
)
28
​
29
group, response, err := cloudAdmin.SCIM.Group.Update(context.Background(), directoryID, groupID, newGroupName)
30
if err != nil {
31
if response != nil {
32
log.Println("Response HTTP Response", string(response.BodyAsBytes))
33
}
34
log.Fatal(err)
35
}
36
​
37
log.Println("Response HTTP Code", response.StatusCode)
38
log.Println("HTTP Endpoint Used", response.Endpoint)
39
log.Println(group)
40
}
Copied!

Delete a group by ID

Delete a group from a directory. An attempt to delete a non-existent group fails with a 404 (Resource Not found) error.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
//ATLASSIAN_ADMIN_TOKEN
13
var scimApiKey = os.Getenv("ATLASSIAN_SCIM_API_KEY")
14
​
15
cloudAdmin, err := admin.New(nil)
16
if err != nil {
17
log.Fatal(err)
18
}
19
​
20
cloudAdmin.Auth.SetBearerToken(scimApiKey)
21
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
22
​
23
var (
24
directoryID = "bcdde508-ee40-4df2-89cc-d3f6292c5971"
25
groupID = "e18da5e4-ba2e-4039-9046-30000af6c0b7"
26
)
27
​
28
​
29
response, err := cloudAdmin.SCIM.Group.Delete(context.Background(), directoryID, groupID)
30
if err != nil {
31
if response != nil {
32
log.Println("Response HTTP Response", string(response.BodyAsBytes))
33
}
34
log.Fatal(err)
35
}
36
​
37
log.Println("Response HTTP Code", response.StatusCode)
38
log.Println("HTTP Endpoint Used", response.Endpoint)
39
}
40
​
Copied!

Update a group by ID (PATCH)

Update a group's information in a directory by groupId via PATCH. You can use this API to manage group membership.
Note: Renaming groups after they've synced to your Atlassian organization isn't supported in this release of the User Provisioning API. To rename a group, create a new group with the desired name, update membership, and then delete the old group.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
7
"log"
8
"os"
9
)
10
​
11
func main() {
12
​
13
//ATLASSIAN_ADMIN_TOKEN
14
var scimApiKey = os.Getenv("ATLASSIAN_SCIM_API_KEY")
15
​
16
cloudAdmin, err := admin.New(nil)
17
if err != nil {
18
log.Fatal(err)
19
}
20
​
21
cloudAdmin.Auth.SetBearerToken(scimApiKey)
22
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
23
​
24
var (
25
directoryID = "bcdde508-ee40-4df2-89cc-d3f6292c5971"
26
groupID = "e18da5e4-ba2e-4039-9046-30000af6c0b7"
27
accountID = "635cdb2f-e72c-4122-bfd3-3aa6c7f02f96"
28
)
29
​
30
payload := &models.SCIMGroupPathScheme{
31
Schemas: []string{"urn:ietf:params:scim:api:messages:2.0:PatchOp"},
32
Operations: []*models.SCIMGroupOperationScheme{
33
{
34
Op: "add",
35
Path: "members",
36
Value: []*models.SCIMGroupOperationValueScheme{
37
{
38
Value: accountID,
39
Display: "Example Display Name",
40
},
41
},
42
},
43
},
44
}
45
​
46
group, response, err := cloudAdmin.SCIM.Group.Path(context.Background(), directoryID, groupID, payload)
47
if err != nil {
48
if response != nil {
49
log.Println("Response HTTP Response", response.Bytes.String())
50
}
51
log.Fatal(err)
52
}
53
​
54
log.Println("Response HTTP Code", response.Code)
55
log.Println("HTTP Endpoint Used", response.Endpoint)
56
​
57
log.Println(group.ID, group.DisplayName)
58
​
59
for _, member := range group.Members {
60
log.Println(member)
61
}
62
​
63
}
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type ScimGroupScheme struct {
2
Schemas []string `json:"schemas,omitempty"`
3
ID string `json:"id,omitempty"`
4
ExternalID string `json:"externalId,omitempty"`
5
DisplayName string `json:"displayName,omitempty"`
6
Members []*ScimGroupMemberScheme `json:"members,omitempty"`
7
Meta *ScimMetadata `json:"meta,omitempty"`
8
}
9
​
10
type ScimGroupMemberScheme struct {
11
Type string `json:"type,omitempty"`
12
Value string `json:"value,omitempty"`
13
Display string `json:"display,omitempty"`
14
Ref string `json:"$ref,omitempty"`
15
}
16
​
17
type ScimMetadata struct {
18
ResourceType string `json:"resourceType,omitempty"`
19
Location string `json:"location,omitempty"`
20
LastModified string `json:"lastModified,omitempty"`
21
Created string `json:"created,omitempty"`
22
}
Copied!

Get groups

Get groups from a directory. Filtering is supported with a single exact match (eq) against the displayName attribute. Pagination is supported. Sorting is not supported.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
//ATLASSIAN_ADMIN_TOKEN
13
var scimApiKey = os.Getenv("ATLASSIAN_SCIM_API_KEY")
14
​
15
cloudAdmin, err := admin.New(nil)
16
if err != nil {
17
log.Fatal(err)
18
}
19
​
20
cloudAdmin.Auth.SetBearerToken(scimApiKey)
21
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
22
​
23
var directoryID = "bcdde508-ee40-4df2-89cc-d3f6292c5971"
24
​
25
groups, response, err := cloudAdmin.SCIM.Group.Gets(context.Background(), directoryID, "", 0, 50)
26
if err != nil {
27
if response != nil {
28
log.Println("Response HTTP Response", string(response.BodyAsBytes))
29
}
30
log.Fatal(err)
31
}
32
​
33
log.Println("Response HTTP Code", response.StatusCode)
34
log.Println("HTTP Endpoint Used", response.Endpoint)
35
​
36
for _, group := range groups.Resources {
37
log.Println(group)
38
}
39
​
40
}
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type ScimGroupPageScheme struct {
2
Schemas []string `json:"schemas,omitempty"`
3
TotalResults int `json:"totalResults,omitempty"`
4
StartIndex int `json:"startIndex,omitempty"`
5
ItemsPerPage int `json:"itemsPerPage,omitempty"`
6
Resources []*ScimGroupScheme `json:"Resources,omitempty"`
7
}
Copied!

Create a group

Create a group in a directory. An attempt to create a group with an existing name fails with a 409 (Conflict) error.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
//ATLASSIAN_ADMIN_TOKEN
13
var scimApiKey = os.Getenv("ATLASSIAN_SCIM_API_KEY")
14
​
15
cloudAdmin, err := admin.New(nil)
16
if err != nil {
17
log.Fatal(err)
18
}
19
​
20
cloudAdmin.Auth.SetBearerToken(scimApiKey)
21
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
22
​
23
var (
24
directoryID = "bcdde508-ee40-4df2-89cc-d3f6292c5971"
25
newGroupName = "scim-jira-users"
26
)
27
​
28
group, response, err := cloudAdmin.SCIM.Group.Create(context.Background(), directoryID, newGroupName)
29
if err != nil {
30
if response != nil {
31
log.Println("Response HTTP Response", string(response.BodyAsBytes))
32
}
33
log.Fatal(err)
34
}
35
​
36
log.Println("Response HTTP Code", response.StatusCode)
37
log.Println("HTTP Endpoint Used", response.Endpoint)
38
log.Printf("The group %v has been created and it contains the ID %v", group.DisplayName, group.ID)
39
}
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type ScimGroupScheme struct {
2
Schemas []string `json:"schemas,omitempty"`
3
ID string `json:"id,omitempty"`
4
ExternalID string `json:"externalId,omitempty"`
5
DisplayName string `json:"displayName,omitempty"`
6
Members []*ScimGroupMemberScheme `json:"members,omitempty"`
7
Meta *ScimMetadata `json:"meta,omitempty"`
8
}
9
​
10
type ScimGroupMemberScheme struct {
11
Type string `json:"type,omitempty"`
12
Value string `json:"value,omitempty"`
13
Display string `json:"display,omitempty"`
14
Ref string `json:"$ref,omitempty"`
15
}
16
​
17
type ScimMetadata struct {
18
ResourceType string `json:"resourceType,omitempty"`
19
Location string `json:"location,omitempty"`
20
LastModified string `json:"lastModified,omitempty"`
21
Created string `json:"created,omitempty"`
22
}
Copied!
Last modified 7mo ago