I’m searching a way to add multiple owners to a group inside Azure Entra ID. I’m using the msgraph API with Python.
The documentation available here show how to add one owner, but I want to add multiple owners in one call, and I can’t find anything on that.
For now, my function work but only for one user :
async def add_team_as_owners(graph_client, group_name, group_id):
"""
Add multiple users as owners of a group
Args:
graph_client (GraphServiceClient): The Graph client
group_id (str): The ID of the group to update
Returns:
str: Return code (204 if successful)
"""
request_body = ReferenceCreate(
odata_id = "https://graph.microsoft.com/v1.0/users/<azure_user_id>"
)
try:
result = await graph_client.groups.by_group_id(group_id).owners.ref.post(request_body)
logging.info(f"Group updated successfully: {group_name} - {group_id}")
return result
except Exception as e:
logging.error(f"Error updating the group: {group_name} - {group_id}")
logging.error(f"Error detail: {e}")
Is someone has an idea or an example to achieve that ?
Thanks for your time,
Regards,
2
Answers
Based on the answer of Sridevi, which I thank for this, I've updated my code to create a loop on all users I wanted to add as owners. It works perfectly, but I find sad that we can't do a one call to add multiple owners.
Anyway, thanks again for your time, and here's my code after the correction :
The call of this function is done by these lines:
You can update the group and a maximum of 20 owners and members can be added as part of group update