microsoft-graph-apiazure-ad-b2cmicrosoft-graph-groups

Microsoft Graph API Create Group Fails


Using Microsoft Graph API 1.0 on an Azure AD B2C directory, I'm running into the following problem when creating groups.

I'm able to create a group with the following code

payload = {
    "description": group_name,
    "displayName": group_name,
    "groupTypes": [
        "Unified"
    ],
    "mailEnabled": False,
    "mailNickname": azure_user_id,
    "securityEnabled": True,
    "owners@odata.bind": [Config.GRAPH_API_BASE + "users/" + azure_user_id],
    "members@odata.bind": [Config.GRAPH_API_BASE + "users/" + azure_user_id]
}

graph_api_post(Config.GRAPH_API_BASE + "groups", payload)

This creates a group with the specified name with a single owner who is also a member of the group.

However, having created one group this way, if I try to create a second group, with the same user, in the same manner, but with a different name, the API fails. In other words I can create:

Name: Group 1

Owner: "Me"

Members: "Me"

But when I try to create a second group as below, the API throws a 500 error.

Name: Group 2

Owner: "Me"

Members: "Me"

Using the Azure Portal, I'm able to create the second group, so this doesn't appear to be a limitation of groups in general, just a limitation / bug of the Graph API.

Is this limitation documented somewhere? Is there a workaround?


Solution

  • Based on Properties of Group, mailNickname is unique in the organization.

    So you should specify a different value for mailNickname. Otherwise you will get 500 error.