简体   繁体   中英

How to create Planner Task with checklist item through Graph API

I'm trying to create a Planner Task including a couple of checklist items. The checklist items are part of the task details, but unlike the description field, the checklist items are a list of item with a unique element name like the element samples 14680 and 49286 below.

How can I create such a list for a task through the API?

"checklist": {
        "14680": {
            "@odata.type": "#microsoft.graph.plannerChecklistItem",
            "isChecked": true,
            "title": "Element 2",
            "orderHint": "8586819525[x",
            "lastModifiedBy": {
                "user": {
                    "displayName": null,
                    "id": "a275ad83-babe-437e-a62b-e4f4e738fd7b"
                }
            },
            "lastModifiedDateTime": "2018-02-26T14:11:40.2829359Z"
        },
        "49286": {
            "@odata.type": "#microsoft.graph.plannerChecklistItem",
            "isChecked": false,
            "title": "Element 1",
            "orderHint": "8586819526571539898P;",
            "lastModifiedBy": {
                "user": {
                    "displayName": null,
                    "id": "a275ad83-babe-437e-a62b-e4f4e738fd7b"
                }
            },
            "lastModifiedDateTime": "2018-02-26T14:11:28.3392169Z"
        }
    },

It looks like you can do that at least by doing it in 2 steps:

  • Create the task 1st, using POST /planner/tasks (doc available here )

  • Then edit the created task details using PATCH /planner/tasks/<id>/details ( doc )

This latest method has a checklist in its body like in this example:

PATCH https://graph.microsoft.com/v1.0/planner/tasks/gcrYAaAkgU2EQUvpkNNXLGQAGTtu/details
Content-type: application/json
Content-length: 857
If-Match: W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc="

{
  "previewType": "noPreview",
  "references": {
    "http%3A//developer%2Emicrosoft%2Ecom":{
      "@odata.type": "microsoft.graph.plannerExternalReference",
      "alias": "Documentation",
      "previewPriority": " !",
      "type": "Other"
    },
    "https%3A//developer%2Emicrosoft%2Ecom/en-us/graph/graph-explorer":{
      "@odata.type": "microsoft.graph.plannerExternalReference",
      "previewPriority": "  !!",
    },
    "http%3A//www%2Ebing%2Ecom": null
  },
  "checklist": {
    "95e27074-6c4a-447a-aa24-9d718a0b86fa":{
      "@odata.type": "microsoft.graph.plannerChecklistItem",
      "title": "Update task details",
      "ischecked": true
    },
    "d280ed1a-9f6b-4f9c-a962-fb4d00dc50ff":{
      "@odata.type": "microsoft.graph.plannerChecklistItem",
      "isChecked": true,
    },
    "a93c93c5-10a6-4167-9551-8bafa09967a7": null
  }
}

If you have a look to the plannerChecklistItems documentation, you will see that the checklist item's ID is a client generated ID:

Properties of an Open Type can be defined by the client. In this case, the client should provide GUIDs as properties and their values must be checklistItem objects. Example is shown below. To remove an item in the checklist, set the value of the property to null.

So you have to generate your own IDs and you are done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM