[Solved] How can I create group mail alias using office 365 API in C#


In this case, you can consider using the Microsoft Graph – Create Group

First, ensure you have assigned the “Microsoft Graph” > “Read and write all groups” permission to app in Azure AD.

enter image description here

Code for your reference:

        string authority = "https://login.windows.net/yourdomain.onmicrosoft.com";

        string clientId = "{client_id}";

        Uri redirectUri = new Uri("http://localhost");

        string resourceUrl = "https://graph.microsoft.com";

        HttpClient client = new HttpClient();

        AuthenticationContext authenticationContext = new AuthenticationContext(authority, false);

        AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resourceUrl,
            clientId, redirectUri, PromptBehavior.Always);

        client.DefaultRequestHeaders.Add("Authorization", "Bearer " + authenticationResult.AccessToken);

        string content = @"{
          'displayName': 'mailgrouptest',
          'groupTypes': ['Unified'],
          'mailEnabled': true,
          'mailNickname': 'mailalias1',
          'securityEnabled': false
        }";

        var httpContent = new StringContent(content, Encoding.GetEncoding("utf-8"), "application/json");

        var response = client.PostAsync("https://graph.microsoft.com/v1.0/groups", httpContent).Result;

        Console.WriteLine(response.Content.ReadAsStringAsync().Result);

12

solved How can I create group mail alias using office 365 API in C#