![](/img/trans.png)
[英]azure devops python get all links (child / parent) for work item
[英]How to delete a work item relation (parent) from a child task work item via HTTP request to azure devops?
在 Azure Devops 中,我有一個任務工作項,它有一個與其鏈接的父工作項。 我知道如何通過 Azure Devops 做到這一點。 但是,我想知道如何通過 HTTP 向 azure devops 請求從子任務工作項中刪除父任務關系?
您可以使用工作項 - 更新rest api 從子任務中刪除父任務關系。
首先,您需要在子任務的關系 arraylist 中檢查父任務的索引。 使用工作項 - 獲取工作項rest api 並指定$expand=Relations
參數以在結果中包含關系。 請參見 powershell 腳本中的以下示例:
$token="PAT"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$token)))
$uri = "https://dev.azure.com/ORG/PROJ/_apis/wit/workitems/9?`$expand=Relations&api-version=6.1-preview.3"
$invRestMethParams = @{
Uri = $uri
Method = 'get'
Headers= @{Authorization=("Basic {0}" -f $base64AuthInfo)}
}
$res= Invoke-RestMethod @invRestMethParams
$res.relations
結果:
在上面的示例中,父任務被列為子任務的關系 arraylist 中的第一個元素。 所以父任務索引為0。
然后使用 Work Items - Update rest api 刪除父任務關系。
請求正文:
$body='[
{
"op": "remove",
"path": "/relations/0" #parent task index is 0
}
]'
請參見 powershell 腳本中的以下示例:
$token="PAT"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$token)))
$uri = "https://dev.azure.com/ORG/PROJ/_apis/wit/workitems/9?`$expand=Relations&api-version=6.1-preview.3"
$body='[
{
"op": "remove",
"path": "/relations/0" #parent task index is 0
}
]'
$invRestMethParams = @{
Uri = $uri
Method = 'PATCH'
ContentType = 'application/json-patch+json'
Headers= @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Body=$body
}
Invoke-RestMethod @invRestMethParams
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.