MoritzP
MoritzP

Reputation: 43

Unable to create Microsoft Team from a Group with Graph-Api: Cannot migrate this group

I am trying to create a Team with the Microsoft Graph-Api. I already have an existing Group and i want to add a Team. My Code Looks like this:

            var api = graphClients.GetClientForTenantId(tId);
            groupToAdd.MailEnabled = false;
            groupToAdd.SecurityEnabled = true;
            groupToAdd.MailNickname = RemoveWhitespace(groupToAdd.DisplayName);

            var directoryObject = new DirectoryObject
            {
                Id = userId
            };

            var team = new Team
            {
                MemberSettings = new TeamMemberSettings
                {
                    AllowCreateUpdateChannels = true,
                    ODataType = null
                },
                MessagingSettings = new TeamMessagingSettings
                {
                    AllowUserEditMessages = true,
                    AllowUserDeleteMessages = true,
                    ODataType = null
                },
                FunSettings = new TeamFunSettings
                {
                    AllowGiphy = true,
                    GiphyContentRating = GiphyRatingType.Strict,
                    ODataType = null
                },
                ODataType = null
            };

            var addedGroup = await api.Groups
                .Request()
                .AddAsync(groupToAdd);

            await api.Groups[addedGroup.Id].Owners.References
                .Request()
                .AddAsync(directoryObject);

            await api.Groups[addedGroup.Id].Team
                .Request()
                .PutAsync(team)

Adding the Group and owner works perfectly fine, but when i try to create the Team i get this error message:

Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: BadRequest
Message: Cannot migrate this group, id: (id), access type: 
Inner error:
    AdditionalData:
    request-id: (request-id)
    date: (date)
ClientRequestId: (ClientRequestId)

I tried changing some settings, but Nothing really works, also i am unable to find any help from Microsoft besides this :

If the group was created less than 15 minutes ago, it's possible for the Create team call to fail with a 404 error code due to replication delays. The recommended pattern is to retry the Create team call three times, with a 10 second delay between calls.

lol

If you have any ideas, let me know, thanks in advance!

MoritzP

Upvotes: 1

Views: 451

Answers (1)

MoritzP
MoritzP

Reputation: 43

Short answer, i had to add this:

            groupToAdd.GroupTypes = new List<String>()
            {
                "Unified"
            };

After that it worked.

Upvotes: 1

Related Questions