planner task assigned to user using graph API

Manoj Pant 135 Reputation points
2023-03-24T13:01:27.3733333+00:00

We are using ClientSecretCredential to create planner task using Graph API. It is working fine without Assignments. But as soon as we are adding assignment it is throwing exception "

The request is invalid:
Value cannot be null.
Parameter name: qualifiedName

Code working without assignment:

string tenentId = "4c150d40-f8a6-4418-b062-26ad5b6608dd";
                string clientId = "4456de51-6b8c-4d96-9c70-f944f30d76d9";
                string clientScret = "Rvx8Q~P8H1vf6092F9-7CPXredzIEsBe4j.krdwj";

                ClientSecretCredential clientSecretCredential = new ClientSecretCredential(tenentId, clientId, clientScret);
                GraphServiceClient gsClient = new GraphServiceClient(clientSecretCredential);


                var plannerTask1 = new PlannerTask();
                plannerTask1.PlanId = "XXXXXXXX";
                plannerTask1.BucketId = "DDDDDDDDDDDDD";
                plannerTask1.Title = plannerTask.Title + "067";

 var plannerTaskRes = await gsClient.Planner.Tasks.PostAsync(plannerTask1 );

Code with Assignment having exception

"The request is invalid:Value cannot be null. Parameter name: qualifiedName"

string tenentId = "4c150d40-f8a6-4418-b062-26ad5b6608dd";
string clientId = "4456de51-6b8c-4d96-9c70-f944f30d76d9";
string clientScret = "Rvx8Q~P8H1vf6092F9-7CPXredzIEsBe4j.krdwj";


ClientSecretCredential clientSecretCredential = new ClientSecretCredential(tenentId, clientId, clientScret);

 GraphServiceClient gsClient = new GraphServiceClient(clientSecretCredential);


                var plannerTask1 = new PlannerTask();
                plannerTask1.PlanId = "XXXXXXXX";
                plannerTask1.BucketId = "DDDDDDDDDDDDD";
                plannerTask1.Title = plannerTask.Title + "067";

plannerTask1.Assignments = new PlannerAssignments();
plannerTask1.Assignments.AdditionalData = new Dictionary<string, object>();

plannerTask1.Assignments.AdditionalData.Add("84b38502-7293-4702-aaa0-c0898dc8e51f", new NewAssignment());

 var plannerTaskRes = await gsClient.Planner.Tasks.PostAsync(plannerTask1 );
   public class NewAssignment
    {

        [JsonPropertyName("@odata.type")]
        public string OData { get; set; } = "#microsoft.graph.plannerAssignment";

        [JsonPropertyName("orderhint")]
        public string OrderHint { get; set; } = " !";
    }
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,590 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,488 questions
0 comments No comments
{count} votes

Accepted answer
  1. Denniz Nilsson 80 Reputation points
    2023-03-28T13:48:29.37+00:00

    I managed to get it working. Upgrade the graphServiceClient to 5.3 and change the custom class NewAssignment to class in graphClient Assignment (notice it is singular)

    then you can do the following:

    string tenentId = "xxx";
    string clientId = "xxx";
    string clientScret = "xxx";
    
    
    ClientSecretCredential clientSecretCredential = new ClientSecretCredential(tenentId, clientId, clientScret);
    
     GraphServiceClient gsClient = new GraphServiceClient(clientSecretCredential);
    
    
                    var plannerTask1 = new PlannerTask();
                    plannerTask1.PlanId = "XXXXXXXX";
                    plannerTask1.BucketId = "DDDDDDDDDDDDD";
                    plannerTask1.Title = plannerTask.Title + "067";
    
    plannerTask1.Assignments = new PlannerAssignments();
    plannerTask1.Assignments.AdditionalData = new Dictionary<string, object>();
    
    plannerTask1.Assignments.AdditionalData.Add("xxx", new PlannerAssignment
                        {
                            OdataType = "#microsoft.graph.plannerAssignment",
                            OrderHint = " !",
                        });
    
     var plannerTaskRes = await gsClient.Planner.Tasks.PostAsync(plannerTask1 );
    
    
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. CharanyaB-MSFT 1,421 Reputation points Microsoft Vendor
    2023-03-28T07:38:19.23+00:00

    Hello @Manoj Pant,

    Thanks for reaching out!

    This issue occurs if Open Type properties are not of correct types, or the type isn't specified, or they do not contain any properties.

    Try using the below code to assign the @odata.type property with value microsoft.graph.plannerAssignment.

    public class NewAssignment
    {
        [JsonProperty("@odata.type")]
        public string ODataType { get; set; }
    
        [JsonProperty("orderHint")]
        public string OrderHint { get; set; }
    
        public NewAssignment()
        {
            ODataType = "#microsoft.graph.plannerAssignment";
            OrderHint = " !";
        }
    }
    

    Documnetation reference:

    https://learn.microsoft.com/en-us/graph/api/resources/planner-overview?view=graph-rest-1.0#400-bad-request

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.


  2. 계 일준 0 Reputation points
    2023-07-28T01:53:08.71+00:00

    Hi I also have an issue with Planner API.

    When I create a task without categories or assignments, everything is alright.

    But after adding categories or assignments, an lambda error occurs.

    My codes are like this

    var requestBody = new PlannerTask
            {
                PlanId = "[PlanId]",
                BucketId = "[BucketId]",
                Title = title,
                Assignments = new PlannerAssignments(),
    
                Details = new PlannerTaskDetails {
                    Description = Description,
                    Checklist = new PlannerChecklistItems {  },
                },
            };
    
    		// without below line, I can create task.
    		// I tried with both "PlannerAssignment" class and "NewAssignment" class
            requestBody.Assignments.AdditionalData.Add("[MyUserId]", new PlannerAssignment());
    
            var newtask = await _userClient.Planner.Tasks.PostAsync(requestBody);
    
    
    
    public class NewAssignment
    {
        [JsonProperty("@odata.type")]
        public string ODataType { get; set; }
    
        [JsonProperty("orderHint")]
        public string OrderHint { get; set; }
    
        public NewAssignment()
        {
            ODataType = "#microsoft.graph.plannerAssignment";
            OrderHint = " !";
        }
    }
    

    Anybody has any idea I should check?

    0 comments No comments