I am creating a Planner with Planner create API. For business reason I also have to create a new group and create the planner under the new group. It was working fine until the new Planner update. Now even though I am supplying the groupId, the planner does not create under it and the group members can not access it. Is there any work around for this?
Here is how I am creating a planner,
PlannerPlan requestBody = new()
{
Container = new PlannerPlanContainer
{
Url = $"https://graph.microsoft.com/v1.0/groups/{groupId}",
},
Title = title,
};
var result = await _graphServiceClient.Planner.Plans.PostAsync(requestBody);
And here is how I am creating the group,
Group requestBody = new Group
{
Description = name,
DisplayName = name,
GroupTypes = new List<string>
{
},
MailEnabled = false,
MailNickname = {nickName},
SecurityEnabled = true,
AdditionalData = new Dictionary<string, object>
{
{
"[email protected]" , new List<string>
{
$"https://graph.microsoft.com/v1.0/users/{ownerId}",
}
},
{
"[email protected]" , new List<string>
{
$"https://graph.microsoft.com/v1.0/users/{ownerId}",
}
},
},
};
var response =await _graphServiceClient.Groups.PostAsync(requestBody);
Note that: You cannot create a Planner plan directly with a security group. Planner is designed to work with Microsoft 365 Groups, not security groups.
Hence to resolve the issue, make sure to create group as Microsoft 365
:
POST https://graph.microsoft.com/v1.0/groups
Content-type: application/json
{
"description": "Test",
"displayName": "Test",
"groupTypes": [
"Unified"
],
"mailEnabled": true,
"mailNickname": "Test",
"securityEnabled": false
}
To create Microsoft 365 group via code check the below:
var requestBody = new Group
{
Description = "Test",
DisplayName = "Test",
GroupTypes = new List<string>
{
"Unified",
},
MailEnabled = true,
MailNickname = "Test",
SecurityEnabled = false,
};
var result = await graphClient.Groups.PostAsync(requestBody);
Now create the planner by using below query:
POST https://graph.microsoft.com/v1.0/planner/plans
{
"container": {
"url": "https://graph.microsoft.com/v1.0/groups/M365GroupID"
},
"title": "ruk"
}
Code:
var requestBody = new PlannerPlan
{
Container = new PlannerPlanContainer
{
Url = "https://graph.microsoft.com/v1.0/groups/M365GroupID",
},
Title = "title-value",
};
var result = await graphClient.Planner.Plans.PostAsync(requestBody);
Reference: