H. Pauwelyn
H. Pauwelyn

Reputation: 14320

Getting labels from Planner with Microsoft Graph API

Is it possible to get the labels and priority from a Microsoft Planner task with the Microsoft Graph API?

See screenshot below to have an idea:

Using next endpoint: https://graph.microsoft.com/v1.0/planner/plans/<plan-id>/tasks I get next data:

{
    "@odata.etag": "W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBBWCc=\"",
    "planId": "r4g58er4grregrg7848",
    "bucketId": "64g8df54hhktohk487",
    "title": "Title of a task",
    "orderHint": "545457845775LM",
    "assigneePriority": "",
    "percentComplete": 0,
    "startDateTime": null,
    "createdDateTime": "2022-01-07T13:58:14.5355148Z",
    "dueDateTime": null,
    "hasDescription": true,
    "previewType": "description",
    "completedDateTime": null,
    "completedBy": null,
    "referenceCount": 0,
    "checklistItemCount": 1,
    "activeChecklistItemCount": 3,
    "conversationThreadId": null,
    "id": "grejgopreg645647",
    "createdBy": {
        "user": {
            "displayName": null,
            "id": "74463467-d67d-4512-9086-c9e279dde6ae"
        }
    },
    "appliedCategories": {
        "category5": true
    },
    "assignments": {}
}

I've next comments on this JSON:

  1. What is assigneePriority? When a priority is filled in, will always be an empty string.
  2. What is appliedCategories? Can these categories being used for the labels? But what is category5?

Upvotes: 1

Views: 3972

Answers (3)

CMO
CMO

Reputation: 1

Using the free to use Microsoft Graph RestAPI Query for reference...

via: https://developer.microsoft.com/en-us/graph/graph-explorer?request=planner/plans/%7Bid%7D/tasks&version=v1.0

Run a GET (v1.0 or beta) query for the planner details api: https://graph.microsoft.com/v1.0/planner/plans/{plannerPlan-id}/details

Insert your planId in the {plannerPlan-id} for the api query

link to image example of ms graph planner api qry

Edited categoryDescription sample returned code...to return the colors with names, I had to type over the color labels in planner. Otherwise, the categories would return equal to "null"

"categoryDescriptions": {
    "category1": "Pink",
    "category2": "Red",
    "category3": "Yellow",
    "category4": "Green",
    "category5": "Blue",
    "category6": "Purple",
    "category7": "Bronze",
    "category8": "Lime",
    "category9": "Aqua",
    "category10": "Gray",
    "category11": "Silver",
    "category12": "Brown",
    "category13": "Cranberry",
    "category14": "Orange",
    "category15": "Peach",
    "category16": "Marigold",
    "category17": "Light green",
    "category18": "Dark green",
    "category19": "Teal",
    "category20": "Light blue",
    "category21": "Dark blue",
    "category22": "Lavender",
    "category23": "Plum",
    "category24": "Light gray",
    "category25": "Dark gray"
}

Upvotes: 0

Reigningfear
Reigningfear

Reputation: 1

Just want to add my research onto what Michael said in case it helps anyone looking at this in the future. I was a bit confused with the categories when using MS Graph versus looking at the API response through the browser while within MS Planner. The category I was looking for was #4 through the Browser but it was #5 through MS Graph.

Browser view

Browser View

Power BI View using Graph URL as source

Power BI View using Graph URL as source

URL used for source within Power BI - https://graph.microsoft.com/beta/planner/plans/{plan-id}/tasks?$expand=details

Looks like Graph counts array elements starting at 1 which threw me as I was wondering why #4 was missing in the Graph response.

Upvotes: 0

Michael
Michael

Reputation: 123

While it's not the most straightforward answer, you can figure out what labels are assigned to a task. You'll need both the planid and taskid to get it.

The appliedCategories are actually the labels applied to a particular task. Their identifieres are just category##. To find the corresponding label name, you'll need to make a call to get the plan details.

Graph API URL: https://graph.microsoft.com/beta/planner/plans/{planid}/details

This will return a JSON object containing each of the categories and their descriptions. You can find more info here about the plannerPlanDetails type. Note: the v1.0 graph endpoint only returns the first 6 categories, while the beta version will return 25.

    "categoryDescriptions": {
        "category1": "Some name",
        "category2": "Some other name",
        "category3": "Another",
        "category4": null,
        ...
        "category25": null
    }

Within the task details, appliedCategories object will contain any labels assigned to that task.

For the priority, you will find a priority property on the task object when using the beta version of the endpoint. It's an integer, but from my testing, the following are the corresponding priority titles

  • 9 - Low
  • 5 - Important
  • 3 - Medium
  • 1 - Urgent

You'll have to do some correlation on your own to match them up, but this is how you can get the information you're looking for.

Upvotes: 2

Related Questions