diff --git a/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 b/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 index 4db39833..139c4cc9 100644 --- a/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 +++ b/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 @@ -10,13 +10,41 @@ function ConvertTo-JiraCreateMetaField { foreach ($i in $InputObject) { Write-Debug "[$($MyInvocation.MyCommand.Name)] Converting `$InputObject to custom object" - $fields = $i.projects.issuetypes.fields - $fieldNames = (Get-Member -InputObject $fields -MemberType '*Property').Name - foreach ($f in $fieldNames) { - $item = $fields.$f + + $fieldList = $null + + If ($null -ne $i.values) { + Write-Debug "[$($MyInvocation.MyCommand.Name)] Input appears to be from Jira 9+ CreateMeta" + + $fieldList = $i.values | ForEach-Object { + @{ + Name = $_.fieldId + Value = $_ + } + } + } + Elseif ($null -ne $i.projects.issuetypes.fields) { + Write-Debug "[$($MyInvocation.MyCommand.Name)] Input appears to be from Jira 8 (or below) CreateMeta" + + $fields = $i.projects.issuetypes.fields + $fieldNames = (Get-Member -InputObject $fields -MemberType '*Property').Name + + $fieldList = $fieldNames | ForEach-Object { + @{ + Name = $_ + Value = $fields.$_ + } + } + } + Else { + Write-Error -Exception ([System.ArgumentException]::new("Input data does not match a known CreateMeta payload.", "InputObject")) + } + + $FieldList | ForEach-Object { + $item = $_.Value $props = @{ - 'Id' = $f + 'Id' = $_.Name 'Name' = $item.name 'HasDefaultValue' = [System.Convert]::ToBoolean($item.hasDefaultValue) 'Required' = [System.Convert]::ToBoolean($item.required) diff --git a/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 b/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 index 54e9c82e..84e7b01d 100644 --- a/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 +++ b/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 @@ -22,7 +22,16 @@ function Get-JiraIssueCreateMetadata { $server = Get-JiraConfigServer -ErrorAction Stop - $resourceURi = "$server/rest/api/2/issue/createmeta?projectIds={0}&issuetypeIds={1}&expand=projects.issuetypes.fields" + $JiraVersion = Get-JiraServerInfo -ErrorAction Stop + + # Beginning with Jira 9, the old instance-level CreateMeta endpoint is no longer available. + # Instead, CreateMeta is inherently scoped to project and issue type. + If ($JiraVersion.Version -gt [System.version](9.0.0)) { + $resourceURi = "$server/rest/api/2/issue/createmeta/{0}/issuetypes/{1}" + } Else { + $resourceURi = "$server/rest/api/2/issue/createmeta?projectIds={0}&issuetypeIds={1}&expand=projects.issuetypes.fields" + } + } process {