Adding a Full Task [PlannerTask] to 365 planner

Today i created an angular app to interact with MS 365 Planner. I tried to add a task. The example @MS - create task works fine
{
  "planId": "xqQg5FS2LkCp935s-FIFm2QAFkHM",
  "bucketId": "hsOf2dhOJkqyYYZEtdzDe2QAIUCR",
  "title": "Update client list",
  "assignments": {
    "fbab97d0-4932-4511-b675-204639209557": {
      "@odata.type": "#microsoft.graph.plannerAssignment",
      "orderHint": " !"
    }
  },
}

Adding a details object was great until i was trying to add some checklist items.
My app gave this error [400]:

message:"Schema validation has failed. Validation for field 'Title', on entity 'Task' has failed: A non-null value must be specified for this field."

Well, this is the end of the story, since after everything went well in the Graph Explorer my app still gave the same error, until i notices that the Content-Type was application/x-www-form-urlencoded.

The Fix is
.api(api)
.header('Content-Type', 'application/json')
.post(data)

While the Graph Explorer gave this error [400]:

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

Traveling through the MS DOCS from Task Type to Task Details to PlannerCheckListItems i saw they add to some types the @odata.type
"@odata.type": "microsoft.graph.checklistItem", // required in PATCH requests to edit the checklist on a task
So i added that to the checklistItem field ... and got this error [400]

message:"The Request is invalid. A type named 'microsoft.graph.checklistItem' could not be resolved by the model. When a model is available, each type name must resolve to a valid type ."

Googling that resulted with some Sharepoint Errors of the name like this one, and knowing Sharepoint and Microsoft i was sure its the same idea, the error basically means that the type you sent is not the right type, and with MS it's just some extra words or chars.

with the help of the Graph Explorer querying a Task Details like this [planner/tasks/<task_id>/details] i saw that the @odata.type for CheckListItems is actually "#microsoft.graph.plannerChecklistItem", planner before..

AND... Almost...
the CheckList wasn't actually created.. you must, after creating the task, GET the task's details, get the @odata.etag, and PATCH it again to set these values as explained in Update Task Details.

PATCH  planner/tasks/<task_id>/details
and the etag must be with the\" as
W/\"JzEtVGFza0RldGFpbHMgQEBAQEBAAAAAQAAAQEBARCc=\"

{
  "previewType": "checklist",
  "description": "my task desc",
  "checklist": {
    "95e27074-6c4a-1234-1234-9d718a0b86fa":{
      "@odata.type": "microsoft.graph.plannerChecklistItem",
      "title": "thing 1 todo",
      "isChecked": false
    },
    "d280ed1a-9f6b-1234-1234-fb4d00dc50ff":{
      "@odata.type": "microsoft.graph.plannerChecklistItem",
      "title": "thing 2 todo",
      "isChecked": false,
    },
    "a93c93c5-10a6-1234-1234-8bafa09967a7": null
  }
}
P.S. - don't forget to set your app's permissions

Comments

Popular posts from this blog

Asp.Net Ending Response options, Response.End() vs CompleteRequest()

c# Service Play Sound with NAudio example by Moshe

MatDatePicker Errors