MSGraphClient
is still in preview and will not work in production tenants as of writing this. Have tested the below the code and it works in Developer tenant.
Add the below import statement:
import { MSGraphClient } from "@microsoft/sp-client-preview";
import { Group } from "@microsoft/microsoft-graph-types";
To create a group, make a POST request to the graph groups endpoint as below:
const graphClient : MSGraphClient = this.context.serviceScope.consume(MSGraphClient.serviceKey)
const group : Group = {
displayName: "Sample test group",
description: "Group description",
groupTypes: [
"Unified"
],
mailEnabled: true,
mailNickname: "TestGroup",
securityEnabled: true
};
graphClient
.api("https://graph.microsoft.com/v1.0/groups/")
.post(group)
.then((groupResponse) => {
console.log(groupResponse);
});
Have added the below npm package:
npm install @microsoft/microsoft-graph-types --save-dev
Reference - Use MS Graph
Github sample - API Scopes