โ›นโ™‚
Groups

Get a group by ID

Get a group from a directory by group ID.
package main
โ€‹
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/admin"
"log"
"os"
)
โ€‹
func main() {
โ€‹
//ATLASSIAN_ADMIN_TOKEN
var scimApiKey = os.Getenv("ATLASSIAN_SCIM_API_KEY")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(scimApiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
directoryID = "bcdde508-ee40-4df2-89cc-d3f6292c5971"
groupID = "e18da5e4-ba2e-4039-9046-30000af6c0b7"
)
โ€‹
group, response, err := cloudAdmin.SCIM.Group.Get(context.Background(), directoryID, groupID)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", string(response.BodyAsBytes))
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.StatusCode)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(group)
โ€‹
fmt.Println(string(response.BodyAsBytes))
โ€‹
}
โ€‹
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type ScimGroupScheme struct {
Schemas []string `json:"schemas,omitempty"`
ID string `json:"id,omitempty"`
ExternalID string `json:"externalId,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Members []*ScimGroupMemberScheme `json:"members,omitempty"`
Meta *ScimMetadata `json:"meta,omitempty"`
}
โ€‹
type ScimGroupMemberScheme struct {
Type string `json:"type,omitempty"`
Value string `json:"value,omitempty"`
Display string `json:"display,omitempty"`
Ref string `json:"$ref,omitempty"`
}
โ€‹
type ScimMetadata struct {
ResourceType string `json:"resourceType,omitempty"`
Location string `json:"location,omitempty"`
LastModified string `json:"lastModified,omitempty"`
Created string `json:"created,omitempty"`
}

Update a group by ID

Update a group in a directory by group ID.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/admin"
"log"
"os"
)
โ€‹
func main() {
โ€‹
//ATLASSIAN_ADMIN_TOKEN
var scimApiKey = os.Getenv("ATLASSIAN_SCIM_API_KEY")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(scimApiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
directoryID = "bcdde508-ee40-4df2-89cc-d3f6292c5971"
groupID = "e18da5e4-ba2e-4039-9046-30000af6c0b7"
newGroupName = "scim-jira-users-updated"
)
โ€‹
group, response, err := cloudAdmin.SCIM.Group.Update(context.Background(), directoryID, groupID, newGroupName)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", string(response.BodyAsBytes))
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.StatusCode)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(group)
}

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.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/admin"
"log"
"os"
)
โ€‹
func main() {
โ€‹
//ATLASSIAN_ADMIN_TOKEN
var scimApiKey = os.Getenv("ATLASSIAN_SCIM_API_KEY")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(scimApiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
directoryID = "bcdde508-ee40-4df2-89cc-d3f6292c5971"
groupID = "e18da5e4-ba2e-4039-9046-30000af6c0b7"
)
โ€‹
โ€‹
response, err := cloudAdmin.SCIM.Group.Delete(context.Background(), directoryID, groupID)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", string(response.BodyAsBytes))
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.StatusCode)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
โ€‹

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.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/admin"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
โ€‹
func main() {
โ€‹
//ATLASSIAN_ADMIN_TOKEN
var scimApiKey = os.Getenv("ATLASSIAN_SCIM_API_KEY")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(scimApiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
directoryID = "bcdde508-ee40-4df2-89cc-d3f6292c5971"
groupID = "e18da5e4-ba2e-4039-9046-30000af6c0b7"
accountID = "635cdb2f-e72c-4122-bfd3-3aa6c7f02f96"
)
โ€‹
payload := &models.SCIMGroupPathScheme{
Schemas: []string{"urn:ietf:params:scim:api:messages:2.0:PatchOp"},
Operations: []*models.SCIMGroupOperationScheme{
{
Op: "add",
Path: "members",
Value: []*models.SCIMGroupOperationValueScheme{
{
Value: accountID,
Display: "Example Display Name",
},
},
},
},
}
โ€‹
group, response, err := cloudAdmin.SCIM.Group.Path(context.Background(), directoryID, groupID, payload)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
log.Println(group.ID, group.DisplayName)
โ€‹
for _, member := range group.Members {
log.Println(member)
}
โ€‹
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type ScimGroupScheme struct {
Schemas []string `json:"schemas,omitempty"`
ID string `json:"id,omitempty"`
ExternalID string `json:"externalId,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Members []*ScimGroupMemberScheme `json:"members,omitempty"`
Meta *ScimMetadata `json:"meta,omitempty"`
}
โ€‹
type ScimGroupMemberScheme struct {
Type string `json:"type,omitempty"`
Value string `json:"value,omitempty"`
Display string `json:"display,omitempty"`
Ref string `json:"$ref,omitempty"`
}
โ€‹
type ScimMetadata struct {
ResourceType string `json:"resourceType,omitempty"`
Location string `json:"location,omitempty"`
LastModified string `json:"lastModified,omitempty"`
Created string `json:"created,omitempty"`
}

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.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/admin"
"log"
"os"
)
โ€‹
func main() {
โ€‹
//ATLASSIAN_ADMIN_TOKEN
var scimApiKey = os.Getenv("ATLASSIAN_SCIM_API_KEY")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(scimApiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var directoryID = "bcdde508-ee40-4df2-89cc-d3f6292c5971"
โ€‹
groups, response, err := cloudAdmin.SCIM.Group.Gets(context.Background(), directoryID, "", 0, 50)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", string(response.BodyAsBytes))
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.StatusCode)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, group := range groups.Resources {
log.Println(group)
}
โ€‹
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type ScimGroupPageScheme struct {
Schemas []string `json:"schemas,omitempty"`
TotalResults int `json:"totalResults,omitempty"`
StartIndex int `json:"startIndex,omitempty"`
ItemsPerPage int `json:"itemsPerPage,omitempty"`
Resources []*ScimGroupScheme `json:"Resources,omitempty"`
}

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.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/admin"
"log"
"os"
)
โ€‹
func main() {
โ€‹
//ATLASSIAN_ADMIN_TOKEN
var scimApiKey = os.Getenv("ATLASSIAN_SCIM_API_KEY")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(scimApiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
directoryID = "bcdde508-ee40-4df2-89cc-d3f6292c5971"
newGroupName = "scim-jira-users"
)
โ€‹
group, response, err := cloudAdmin.SCIM.Group.Create(context.Background(), directoryID, newGroupName)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", string(response.BodyAsBytes))
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.StatusCode)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("The group %v has been created and it contains the ID %v", group.DisplayName, group.ID)
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type ScimGroupScheme struct {
Schemas []string `json:"schemas,omitempty"`
ID string `json:"id,omitempty"`
ExternalID string `json:"externalId,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Members []*ScimGroupMemberScheme `json:"members,omitempty"`
Meta *ScimMetadata `json:"meta,omitempty"`
}
โ€‹
type ScimGroupMemberScheme struct {
Type string `json:"type,omitempty"`
Value string `json:"value,omitempty"`
Display string `json:"display,omitempty"`
Ref string `json:"$ref,omitempty"`
}
โ€‹
type ScimMetadata struct {
ResourceType string `json:"resourceType,omitempty"`
Location string `json:"location,omitempty"`
LastModified string `json:"lastModified,omitempty"`
Created string `json:"created,omitempty"`
}
Last modified 10mo ago
Export as PDF
Copy link
On this page
Get a group by ID
Update a group by ID
Delete a group by ID
Update a group by ID (PATCH)
Get groups
Create a group