如何通过对 azure devops 的 HTTP 请求从子任务工作项中删除工作项关系(父项)?
How to delete a work item relation (parent) from a child task work item via HTTP request to azure devops?
在 Azure Devops 中,我有一个任务工作项,它有一个链接到它的父工作项。我知道如何通过 Azure Devops 做到这一点。但是,我想知道如何通过对 azure devops 的 HTTP 请求从子任务工作项中删除父任务关系?
您可以使用 Work Items - Update rest api 从子任务中删除父任务关系。
首先您需要检查子任务的关系数组列表中父任务的索引。使用 Work Items - Get Work Item 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
结果:
在上面的例子中,父任务被列为子任务关系数组列表中的第一个元素。所以父任务索引为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
在 Azure Devops 中,我有一个任务工作项,它有一个链接到它的父工作项。我知道如何通过 Azure Devops 做到这一点。但是,我想知道如何通过对 azure devops 的 HTTP 请求从子任务工作项中删除父任务关系?
您可以使用 Work Items - Update rest api 从子任务中删除父任务关系。
首先您需要检查子任务的关系数组列表中父任务的索引。使用 Work Items - Get Work Item 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
结果:
在上面的例子中,父任务被列为子任务关系数组列表中的第一个元素。所以父任务索引为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