Create a Planner board to team using Graph API

Continuing on Graph API series: this time I show how to create a Planner board, add a bucket and task into it and attach it to a team as template.

The setup

  • I am showing these snippets as example, they are not a full solutions
  • I use PowerShell and Graph Explorer to post commands in
  • Experiment, learn and use the knowledge to create your own solutions

Create a Planner and a bucket

Using Docs.Microsoft.Com examples it is actually quite easy to create a Planner and buckets into it. They key API is /planner/plans. I use variables $teamID and $teamName to create a planner to specific team. Plan title can of course be anything you wish.

# Create a Planner to team
$createPlanUri ="https://graph.microsoft.com/beta/planner/plans"
$createPlanJSON ='{ 
	"owner": "' +$teamID +'", 
	"title": "' +$teamName +' Planner" 
}
' 
$graphResponse = Invoke-RestMethod -Method Post -Uri $createPlanUri -Headers @{"Authorization"="Bearer $delegatedaccessToken"} -Body $createPlanJSON -ContentType "application/json"
$planID = $graphResponse.id
Write-Host "Planner Plan ID: " $planID

After creation of a planner, we can add objects into it. Like a bucket.

## add some planner buckets & tasks
##
$bucketJSON ='
{
  "name": "Backlog bucket",
  "planId": "' +$planID + '",
  "orderHint": " !"
}
'
$bucketURI = "https://graph.microsoft.com/beta/planner/buckets"
$graphResponse = Invoke-RestMethod -Method Post -Uri $BucketUri -Headers @{"Authorization"="Bearer $delegatedaccessToken"} -Body $BucketJSON -ContentType "application/json"

$backlockBucketID = $graphResponse.id

Adding tasks

When you know the plan and bucket IDs, it is easy to write tasks to them. Looking at the Docs reference you can go though orderHint (well, ordering). However – note that there is a priority property – you can set the task automatically important or urgent when you create a task! You can also assigns categories.

## Add a Task
$taskJSON ='
{
  "title": "Sample task",
  "planId": "' +$planID + '",
  "bucketId" : "' + $backlockBucketID + '",
  "orderHint": " !",
  "priority" : 2,
  "appliedCategories": {
    "category1": true
  }
}'

$taskURI = "https://graph.microsoft.com/beta/planner/tasks"
$graphResponse = Invoke-RestMethod -Method Post -Uri $TaskUri -Headers @{"Authorization"="Bearer $delegatedaccessToken"} -Body $TaskJSON -ContentType "application/json"
$taskID = $graphResponse.id

Adding a planner as a tab

Using Graph API it is easy to provision a template Planner (perhaps reading buckets and tasks from another template Team / Planner! – just note the ordering so you won’t create them in reverse).

Provisioning a template planner to a fresh team (or just adding a Planner to existing team) helps with specific team templates: project setup, sales process, marketing campaing, setting up an event and the list goes on.

How to setup the tab to a team? Read Docs.Microsoft.Com, check the example below or check my GitHub repository https://github.com/veskunopanen/Teams-Graph-API .

When adding a Planner tab you need to first configure the URL that is set to contentURL, removeURL and to websiteURL in a call. When you know a PlanID it is rather straight-forward.

You also need to ID of the team and the channel to which you are adding the tab.

## Add Planner Tab to a team

$generalTabsURI = "https://graph.microsoft.com/beta/teams/" + $teamID + "/channels/" + $ChannelID + "/tabs"

$planURL = 'https://tasks.office.com/'+ $tenantname +'.onmicrosoft.com/Home/PlannerFrame?page=7&planId='+ $planID

$plannerJSON =' {
	"name": "'+ $teamname +' Backlog",
	"displayName": "'+  $teamname  +' Backlog",
     "teamsAppId" : "com.microsoft.teamspace.tab.planner",
     "configuration": {
        "entityId": "'+ $planID +'",
		"contentUrl": "' + $planURL+ '",
		"removeUrl": "' + $planURL+ '",
		"websiteUrl": "' + $planURL+ '"
           }
        }'
        
#Write-Host $plannerJSON
$graphResponse = Invoke-RestMethod -Method Post -Uri $generalTabsURI -Headers @{"Authorization"="Bearer $delegatedaccessToken"} -Body $plannerJSON -ContentType "application/json"

Vastaa

Täytä tietosi alle tai klikkaa kuvaketta kirjautuaksesi sisään:

WordPress.com-logo

Olet kommentoimassa WordPress.com -tilin nimissä. Log Out /  Muuta )

Google photo

Olet kommentoimassa Google -tilin nimissä. Log Out /  Muuta )

Twitter-kuva

Olet kommentoimassa Twitter -tilin nimissä. Log Out /  Muuta )

Facebook-kuva

Olet kommentoimassa Facebook -tilin nimissä. Log Out /  Muuta )

Muodostetaan yhteyttä palveluun %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.