使用此 api,我尝试使用此 api 创建一个带有自定义字段的页面:https://learn.microsoft.com/en-us/rest/api/azure/devops/processes/pages/add?view=azure -devops-rest-7.1&tabs=HTTP 它创建了页面,但是尽管在工作项中声明了一个字段,但它并没有放置它,而是创建了一个空白。
function addWorkItemFieldPage {
[CmdletBinding()] param (
[Parameter(Mandatory)] [string] $organization,
[Parameter(Mandatory)] [string] $processId,
[Parameter(Mandatory)] [string] $witRefName,
[Parameter(Mandatory)] [Object] $info,
[Parameter(Mandatory)] [hashtable] $header
)
[string] $uri = "https://dev.azure.com/{0}/_apis/work/processes/{1}/workItemTypes/{2}/layout/pages?{3}" -f $organization, $processId, $witRefName, $apiVersion
[string] $body = @{
sections = @{
id = "Section1"
groups = @{
id = $info.label
controls = @{
id = $info.refName
label = $info.label
order = $null
height = $null
visible = $true
readOnly = $false
metadata = $null
watermark = $null
inherited = $null
overridden = $null
controlType = $null
contribution = $null
isContribution = $false
}
overridden = $false
visible = $true
}
overridden = $false
visible = $true
}
label = $info.page
order = $null
overridden = $null
inherited = $null
visible = $true
locked = $false
pageType = 1
contribution = $null
} | ConvertTo-Json -Depth 3
Write-Host $uri
try {
Invoke-RestMethod -Uri $uri -Method Post -Headers $header -Body $body -ContentType application/json
} catch {
Get-Error
throw
}
}
我做错了什么?
您可能遇到不止一个问题。
不清楚您从
$header
中获得 Invoke-WebRequest
。确保您已获得有效的身份验证令牌并相应地设置标头:
Authorization: Bearer XXXXXXXXXXXXX..
我相信您的嵌套对象深度是 4,而不是 3。只需从
-depth 3
中删除 ConvertTo-Json
参数和值即可。
您已使用 cmdletBinding 创建了 addWorkItemFieldPage 函数。目前还不清楚它是如何被调用的。该函数需要 5 个参数,以便将正确的值插入到 JSON 正文中。您应该在调用休息方法之前调用此函数。
如果以上所有内容均正常,则检查
$info.label
、$info.refName
和 $info.page
的值。它们都不应该为空或为空。