Search code examples
c#.netazuremicrosoft-graph-apimicrosoft-planner

Planner create API with Group Id is not working in Microsoft Graph


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);

Solution

  • 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.

    • Planner is integrated into Microsoft 365 Groups, and each group automatically gets a Planner plan that can be used for task management.
    • A Microsoft 365 Group is a collaborative workspace where you can manage resources like Outlook, Teams, OneDrive, SharePoint, and Planner.

    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
    }
    

    enter image description here

    enter image description here

    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"
    }
    

    enter image description here

    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:

    Create plannerPlan - Microsoft Graph v1.0 | Microsoft