0

I am trying to create O365 Group using Graph API, though I am able to get users and user profile details, I am unable to create group. My Azure tenant does have permission to create users/groups in the default directory and I did gave Profile and GroupReadWriteAll permissions.

static async Task CreateO365Group(string o365Group) { try { //Get the Graph client var graphClient = AuthenticationHelper.GetAuthenticatedClient();

            var token = await AuthenticationHelper.GetTokenForUserAsync();

            var request = new HttpRequestMessage(HttpMethod.Post, graphClient.BaseUrl + "/groups");
            request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);

            var group = new Group
            {
                Description = "Group for Partners",
                DisplayName = "O365Partners",
                GroupTypes = new List<String>()
                {
                    "Unified"
                },
                MailEnabled = true,
                MailNickname = "library",
                SecurityEnabled = false
            };

            await graphClient.Groups.Request().AddAsync(group);

            var response = await graphClient.HttpProvider.SendAsync(request);
            var bodyContents = await response.Content.ReadAsStringAsync();

            Debug.WriteLine(bodyContents);
            return bodyContents;
        }
        catch (Exception e)
        {
           Debug.WriteLine("Could not create Group {0} {1}", e.Message,o365Group);
           return null;
        }
    }
krisrajz
  • 11
  • 1
  • 4

0 Answers0