diff --git a/CHANGELOG.md b/CHANGELOG.md index af11e6c..1d09d24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ Format as below (Requires the '### Added' as a header or task fails) ...- Update ReadMe.MD ## [Unreleased] +### Added +- Set-InsightObject and Get-InsightObject updated to suport more depth for JSON. +- Set-InsightObject and New-InsightObject updated array var name ## [1.16] - 2021-06-01 ### Added diff --git a/JSM.Insight/Public/Find-InsightObject.ps1 b/JSM.Insight/Public/Find-InsightObject.ps1 new file mode 100644 index 0000000..07e1e99 --- /dev/null +++ b/JSM.Insight/Public/Find-InsightObject.ps1 @@ -0,0 +1,72 @@ +function Find-InsightObject { + [CmdletBinding()] + param ( + [string]$IQL, + [string]$objectTypeId, + [int]$page = 1, + [int]$resultsPerPage = 500, + [int]$orderByTypeAttrId, + [ValidateSet(0,1)] + [int]$asc = 1, + [string]$objectId, + [string]$objectSchemaId, + [bool]$includeAttributes, + [array]$attributesToDisplay, + [String]$Version = "1", + [string]$InsightCreds = $InsightCreds, + [string]$InsightWorkspaceID = $InsightWorkspaceID + ) + + begin { + Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" + $Headers = New-InsightHeaders + } + + process { + + $RequestBody = @{ + 'iql' = $iql + 'objectTypeId' = $objectTypeId + 'resultsPerPage' = $resultsPerPage + } + if ($page) { + $RequestBody.Add('page', $page) + } + if ($orderByTypeAttrId) { + $RequestBody.Add('orderByTypeAttrId', $orderByTypeAttrId) + } + if ($asc) { + $RequestBody.Add('asc', $asc) + } + if ($objectId) { + $RequestBody.Add('objectId', $objectId) + } + if ($objectSchemaId) { + $RequestBody.Add('objectSchemaId', $objectSchemaId) + } + if ($includeAttributes) { + $RequestBody.Add('includeAttributes', $includeAttributes) + } + if ($attributesToDisplay ) { + $RequestBody.Add('attributesToDisplay', $attributesToDisplay) + } + + $RequestBody = $RequestBody | ConvertTo-Json -Depth 5 + + $Request = [System.UriBuilder]"https://api.atlassian.com/jsm/insight/workspace/$InsightWorkspaceID/v$Version/object/navlist/iql" + } + + end { + try { + $response = Invoke-RestMethod -Uri $Request.Uri -Body $RequestBody -Headers $headers -Method POST + } + catch { + Write-Verbose "[$($MyInvocation.MyCommand.Name)] Failed" + Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation + } + + $response + + Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete" + } +} \ No newline at end of file diff --git a/JSM.Insight/Public/New-InsightObject.ps1 b/JSM.Insight/Public/New-InsightObject.ps1 index a716b21..282eeaf 100644 --- a/JSM.Insight/Public/New-InsightObject.ps1 +++ b/JSM.Insight/Public/New-InsightObject.ps1 @@ -1,4 +1,3 @@ - function New-InsightObject { [CmdletBinding()] param ( @@ -20,9 +19,11 @@ function New-InsightObject { $RequestBody = @{ 'objectTypeId' = $objectTypeId - 'attributes' = @($attributes) + 'attributes' = @($attributesArray) } + $RequestBody = $RequestBody | ConvertTo-Json -Depth 5 + $Request = [System.UriBuilder]"https://api.atlassian.com/jsm/insight/workspace/$InsightWorkspaceID/v$Version/object/create" } diff --git a/JSM.Insight/Public/Set-InsightObject.ps1 b/JSM.Insight/Public/Set-InsightObject.ps1 index 240a1a0..181f1e3 100644 --- a/JSM.Insight/Public/Set-InsightObject.ps1 +++ b/JSM.Insight/Public/Set-InsightObject.ps1 @@ -21,9 +21,11 @@ function Set-InsightObject { $RequestBody = @{ 'objectTypeId' = $objectTypeId - 'attributes' = @($attributes) + 'attributes' = @($attributesArray) } + $RequestBody = $RequestBody | ConvertTo-Json -Depth 5 + $Request = [System.UriBuilder]"https://api.atlassian.com/jsm/insight/workspace/$InsightWorkspaceID/v$Version/object/$id" }