[Python] How to add multiple owners to an Entra ID group with the Microsoft Graph API

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I'm searching a way to add multiple owners to a group inside Microsoft Entra ID. I'm using the MS Graph 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}")


    How can I achieve that?

    Continue reading...

Compartilhe esta Página