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 :
async def add_team_as_owners(graph_client, group_name, group_id, user_id):
"""
Add Team as owner of the group
Args:
graph_client (GraphServiceClient): The Graph client
group_id (str): The ID of the group to update
user_id (str): The ID of the user to add as owner
Returns:
str: Return code (204 if successful)
"""
request_body = ReferenceCreate(odata_id = "https://graph.microsoft.com/v1.0/users/"+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}")
The call of this function is done by these lines:
for user_id in ["<user_id_1>", "<user_id_2>", "<user_id_3>"]:
runner.run(add_team_as_owners(client, source_group_name, source_group_id, user_id))