Error creating Planner Task Checklist with graph API

Jon Peters 0 Reputation points
2023-08-18T17:30:49.06+00:00

I'm unable to create checklist items using the graph API. I keep getting the error:

Exception of type 'Microsoft.Graph.Models.ODataErrors.ODataError' was thrown.

        public async static Task<PlannerTaskDetails> UpdateDetailsOfTaskAddChecklist(GraphServiceClient graphClient, PlannerTask plannerTask, string[] checklistItems)
        {
            PlannerTaskDetails requestBody = await graphClient.Planner.Tasks[plannerTask.Id].Details.GetAsync();
            string eTag = requestBody.AdditionalData["@odata.etag"].ToString();

            requestBody.PreviewType = PlannerPreviewType.Checklist;

            if (requestBody.Checklist == null)
            {
                requestBody.Checklist = new PlannerChecklistItems();
                requestBody.Checklist.AdditionalData = new Dictionary<string, object>();
            }

            foreach (var i in checklistItems)
            {
                requestBody.Checklist.AdditionalData.Add(Guid.NewGuid().ToString(),
                    new
                    {
                        OdataType = "microsoft.graph.plannerChecklistItem",
                        Title = i,
                        IsChecked = false
                    }
                 );
            }



            var result = await graphClient.Planner.Tasks[plannerTask.Id].Details.PatchAsync(requestBody, (requestConfiguration) =>
            {
                requestConfiguration.Headers.Add("Prefer", "return=representation");
                requestConfiguration.Headers.Add("If-Match", eTag);
            });

            return result;
        }
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,483 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.