user1432193
user1432193

Reputation: 307

How to create a new group in Azure AD using Go SDK?

I need to create a group in Azure Active Directory programmatically using Go SDK, I somehow struggle to find the learning resources to do that. Can I get an example or explanation how to go about it?

Upvotes: 1

Views: 717

Answers (1)

Sridevi
Sridevi

Reputation: 22542

To achieve your requirement, you can make use of Microsoft Graph SDK for Go by integrating the Microsoft Graph API into your Go application.

Make sure to install and import required libraries and create authProvider instance.

You can refer this Microsoft Doc to create group in Azure AD via Graph API that includes code snippets for Go too.

Make sure to consent required permissions before running the query. Based on the request body you specify; group type will be decided accordingly.

To create Security group, I gave request body like below:

enter image description here

You can get GO code by selecting code snippets:

//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)

requestBody := msgraphsdk.NewGroup()
description := "Example of Security Group"
requestBody.SetDescription(&description)
displayName := "Sri Security"
requestBody.SetDisplayName(&displayName)
requestBody.SetGroupTypes( []string {
}
mailEnabled := false
requestBody.SetMailEnabled(&mailEnabled)
mailNickname := "test"
requestBody.SetMailNickname(&mailNickname)
securityEnabled := true
requestBody.SetSecurityEnabled(&securityEnabled)
result, err := graphClient.Groups().Post(requestBody)

After running the above query, Security Group created successfully like below:

enter image description here

Upvotes: 1

Related Questions