Public/Create-Task.ps1
function Create-Task { param( [string]$ChannelId, [string]$EntityId, [string]$GroupId, [string]$TeamId, [string]$Domain = "teams-stag.appvity.com", $TaskObject, [string]$Title, [string]$AssignedTo, [string]$Attachments, [string]$Body, [string]$Complete, [string]$CompletedDate, [string]$DueDate, [string]$Effort, [string]$Name, [string]$Owner, [string]$Priority, [string]$RelatedItems, [string]$StartDate, [string]$Status, [string]$Source, [string]$ProjectId, $PhaseId, $BucketId, [string]$Cookie ) $validate = '' if(!$Domain){ $validate = $validate + ', Domain' } if(!$ChannelId){ $validate = $validate + ', ChannelId' } <# if(!$EntityId){ $validate = $validate + ', EntityId' } if(!$GroupId){ $validate = $validate + ', GroupId' } #> if(!$TeamId){ $validate = $validate + ', TeamId' } if(!$ProjectId){ $validate = $validate + ', ProjectId' } if($TaskObject) { #$object = $TaskObject | ConvertFrom-Json if($object.Title) {$Title = $object.Title} if($object.AssignedTo) {$AssignedTo = $object.AssignedTo} if($object.Attachments) {$Attachments = $object.Attachments} if($object.Body) {$Body = $object.Body} if($object.Complete) {$Complete = $object.Complete} if($object.CompletedDate) {$CompletedDate = $object.CompletedDate} if($object.DueDate) {$DueDate = $object.DueDate} if($object.Effort) {$Effort = $object.Effort} if($object.Name) {$Name = $object.Name} if($object.Owner) {$Owner = $object.Owner} if($object.Priority) {$Priority = $object.Priority} if($object.RelatedItems) {$RelatedItems = $object.RelatedItems} if($object.StartDate) {$StartDate = $object.StartDate} if($object.Status) {$Status = $object.Status} if($object.Source) {$Source = $object.Source} if($object.BucketId) {$BucketId = $object.BucketId} if($object.PhaseId) {$PhaseId = $object.PhaseId} } #validation if(!$Title) { $validate = $validate + ', Title' } <# if(!$Source) { $validate = $validate + ', Source' } #> if(!$Priority) { $validate = $validate + ', Priority' } if(!$Status) { $validate = $validate + ', Status' } if($validate) { $validate = $validate.TrimStart(',').TrimStart() + ' is require' Write-Host $validate -F Red return } #cookie $cookie = $Cookie if(!$cookie){ $cookie = Get-GraphOauthCookie -BaseURL $Domain #Write-Host '-------------cookie------------------' #Write-Host $cookie } #header $hd = New-Object 'System.Collections.Generic.Dictionary[String,String]' $hd.Add("x-appvity-channelId",$ChannelId) $hd.Add("x-appvity-entityId",$EntityId) $hd.Add("x-appvity-groupId",$GroupId) $hd.Add("x-appvity-teamid",$TeamId) $hd.Add("Content-Type","application/json") #session $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession $ck = New-Object System.Net.Cookie $ck.Name = "graphNodeCookie" $ck.Value = $cookie $ck.Path = "/" $ck.Domain = $Domain $session.Cookies.Add($ck); $phaseName = '' $bucketName = '' if($PhaseId) { $phases = Get-Phases -Domain $Domain -ChannelId $ChannelId -TeamId $TeamId -ProjectId $ProjectId -Cookie $cookie $phase = $phases | Where {$_.id -eq $PhaseId} | Select displayName $phaseName = $phase.displayName if($BucketId) { $buckets = Get-Buckets -Domain $Domain -ChannelId $ChannelId -TeamId $TeamId -ProjectId $ProjectId -PhaseId $PhaseId -Cookie $cookie $bucket = $buckets | Where {$_.id -eq $BucketId} | Select displayName $bucketName = $bucket.displayName } } $ret = Get-Projects -Domain $Domain -Cookie $cookie -ChannelId $ChannelId -TeamId $TeamId $project = $ret | Where {$_._id -eq $ProjectId} | Select source $Source = $project.source $Arr = @{ name = $Title status = $Status body = $Body source = $Source priority = $Priority startDate = $StartDate dueDate = $DueDate attachments = @() bucket = $BucketId bucketName = $bucketName complete = '0' completedDate = '' effort = '' owner = '' phase = $PhaseId phaseName = $phaseName projectId = $ProjectId relatedItems = @() assignedTo = @() } | ConvertTo-Json $Url = 'https://' + $Domain.TrimEnd('/') + '/odata/tasks' $Params = @{ Uri = $Url Method = 'POST' Headers = $hd Body = $Arr } try { Invoke-WebRequest @Params -WebSession $session } catch{ Write-Error $_.Exception.Message } } |