How to create Planner Task with checklist item through Graph API

為{幸葍}努か 提交于 2019-12-24 18:29:52

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/49003261/how-to-create-planner-task-with-checklist-item-through-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!