如何通过 REST API 创建任务或用户故事
我正在尝试使用此 RESTapi 有多个积压订单。
POST https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/${type}?api-version=6.0
我的代码
function Set-pbiStuff {
param
(
[Parameter(Mandatory = $true)] [string] $Organization,
[Parameter(Mandatory = $true)] [string] $Project,
[Parameter(Mandatory = $true)] [hashtable] $Token
)
$Base = "https://dev.azure.com/$($organization)/$($project)/_apis/wit/workitems"
$workItemType = 'task'
$URL = "$($Base)/$($workItemType)?api-version=6.0"
$Json = @(
@{
op = 'add'
path = '/fields/System.Title'
value = $workItemType
}
)
$Body = (ConvertTo-Json $Json)
$response = Invoke-RestMethod `
-Method Post `
-Uri $URL `
-ContentType 'application/json' `
-Body $Body `
-Headers $Token
Write-Host $URL
Write-Host $response
}
$Token= @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($env:SYSTEM_ACCESSTOKEN)")) }
$tt = Set-pbiStuff -Organization 'myOrganization' -Project 'myProject' -Token $Token
return $tt
但我得到的响应是找不到该页面。 我错过了什么?
I am trying to create a user story and task in Azure DevOps with this RESTapi
There are multiple backlogs.
POST https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/${type}?api-version=6.0
My code
function Set-pbiStuff {
param
(
[Parameter(Mandatory = $true)] [string] $Organization,
[Parameter(Mandatory = $true)] [string] $Project,
[Parameter(Mandatory = $true)] [hashtable] $Token
)
$Base = "https://dev.azure.com/$($organization)/$($project)/_apis/wit/workitems"
$workItemType = 'task'
$URL = "$($Base)/$($workItemType)?api-version=6.0"
$Json = @(
@{
op = 'add'
path = '/fields/System.Title'
value = $workItemType
}
)
$Body = (ConvertTo-Json $Json)
$response = Invoke-RestMethod `
-Method Post `
-Uri $URL `
-ContentType 'application/json' `
-Body $Body `
-Headers $Token
Write-Host $URL
Write-Host $response
}
$Token= @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($env:SYSTEM_ACCESSTOKEN)")) }
$tt = Set-pbiStuff -Organization 'myOrganization' -Project 'myProject' -Token $Token
return $tt
But the response I get is that the page was not found.
What have I missed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是脚本中的类型
${type}
不正确,缺少字符$
。请尝试这个:
内容类型应该是“
application/json-patch+json
”下面的脚本对我有用:(用于测试的PAT,您可以将其更改回
SYSTEM_ACCESSTOKEN< /code> 如果你在管道中运行它)
The problem is that the type
${type}
is incorrect in your script, the character$
is missing.Please try this:
And the content type should be "
application/json-patch+json
"Below script works for me : (PAT used for the test, you can change it back to
SYSTEM_ACCESSTOKEN
if you run it in pipeline)您尝试使用 PATCH 动词调用 API,请参阅第二行:
API 端点是,如文档所示和您在问题中所述的 POST 端点。
You're trying to call the API with a PATCH verb, see line two:
The API endpoint is, like the documentation shows and you stated in your question, a POST endpoint.
尝试此 URL:
检查此示例:https://arindamhazra.com/create -azure-devops-task-using-powershell/
Try this URL:
Check this sample: https://arindamhazra.com/create-azure-devops-task-using-powershell/