Create Office 365 groups using client library programatically

196 Views Asked by At

I am trying to create Office 365 groups programatically. I found that there is one possible way to create Office 365 groups via REST API through Graph. I read that there will be Client Library for creating Office 365 groups, but I couldn't find much information. Does anyone created Office 365 groups using Client library. Please suggest.

Thanking in advance.

2

There are 2 best solutions below

0
On BEST ANSWER

Install the Microsoft.Graph Nuget Package.

Then, you can use the GraphServiceClient to create the service.
Next, you simply use the client to pull whatever you need down.

GraphServiceClient client = new GraphServiceClient(Iauthcontext provider or proxy);
var me = client.me.request().getasync();   

The hard work is in setting up the Authenticator, but if you search the we for samples with the GraphServiceClient, you will find many.

0
On

Creating a new group using the Client Side API (CSOM) should be something like this.

 GroupCreationInformation info = new GroupCreationInformation();
 info.Title = "My new group";
 Group grp = clientContext.Web.SiteGroups.Add(info);
 clientContext.ExecuteQuery();

If you use OfficeDev PnP you will have an easier life since they it adds a bunch of extension methods like the following

clientContext.Web.AddGroup("My new group", "", true, true);