Create AD group with owners and members with python graph SDK

Sanjay Prakash 0 Reputation points
2024-03-04T07:58:21.21+00:00

Im following this example to create Azure AD security group with owners and members, But the group is created without the members and additional owners provided. Im following the below doc:

https://learn.microsoft.com/en-us/graph/api/group-post-groups?view=graph-rest-1.0&tabs=python#exampl...

 

The Group object has members and owners parameter, should that be used instead? If so is there any example for that? 


from msgraph import GraphServiceClient
from msgraph.generated.models.group import Group

graph_client = GraphServiceClient(credentials, scopes)

request_body = Group(
	description = "Group with designated owner and members",
	display_name = "Operations group",
	group_types = [
	],
	mail_enabled = False,
	mail_nickname = "operations2019",
	security_enabled = True,
	additional_data = {
			"owners@odata_bind" : [
				"https://graph.microsoft.com/v1.0/users/26be1845-4119-4801-a799-aea79d09f1a2",
			],
			"members@odata_bind" : [
				"https://graph.microsoft.com/v1.0/users/ff7cb387-6688-423c-8188-3da9532a73cc",
				"https://graph.microsoft.com/v1.0/users/69456242-0067-49d3-ba96-9de6f2728e14",
			],
	}
)

result = await graph_client.groups.post(request_body)
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,783 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 41,126 Reputation points
    2024-03-04T09:08:11.1133333+00:00

    Hi @Sanjay Prakash

    I just tested this API locally and it works perfectly to create security groups with members and owners. Go to Azure AD > Groups > Find the group you created, then find the Members & Owners blade and check again.

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.